98915587a147784022a9e95b5c88647831ba740b
[sdk] / samples / games / cards / poker / bet.ec
1 /****************************************************************************
2    POKER Game Interface
3
4    Copyright (c) 2001 Jerome Jacovella-St-Louis
5    All Rights Reserved.
6    
7    bet.ec - Poker Bet Window
8 ****************************************************************************/
9 import "poker.ec"
10
11 class Bet : Window
12 {
13    background = activeBorder;
14    borderStyle = fixed;
15    clientSize = Size { 140, 80 };
16
17    int * thisBet;
18    Button bet
19    {
20       this,
21       text = "Bet",
22       size = Size { 40, 20 },
23       anchor = Anchor { horz = -20 };
24       hotKey = b,
25       isDefault = true;
26
27       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
28       {
29          int theBet = (int) strtod(edit.contents, null) * 2;
30          if(theBet > 0 && *thisBet + theBet >= currentBet)
31          {
32             *thisBet += theBet;
33             Destroy(1);
34          }
35          return true;
36       }
37    };
38    Button pass
39    {
40       this,
41       text = currentBet ? "Fold" : "Pass",
42       size = Size { 40, 20 },
43       anchor = Anchor { horz = 20 },
44       hotKey = currentBet ? f : p;
45
46       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
47       {
48          Destroy(0);
49          return true;
50       }
51    };
52
53    bool OnKeyHit(Key key, unichar ch)
54    {
55       if(key == escape) Destroy(0);
56       return true;
57    }
58    EditBox edit { this, anchor = Anchor { top = 10 }, size = Size { 80, 20 } };
59
60    property int * thisBet { set { this.thisBet = value; } };
61
62    void OnRedraw(Surface surface)
63    {
64       surface.SetForeground(red);
65       surface.WriteTextf(0, 65, "$%.2f to you.", (currentBet - *thisBet) / 2.0);
66    }
67 }