3b89fef12aa802aec4dc1c433c15adb0d094b0ae
[sdk] / samples / games / cards / poker / player.ec
1 /****************************************************************************
2    POKER Game Interface
3
4    Copyright (c) 2001 Jerome Jacovella-St-Louis
5    All Rights Reserved.
6
7    player.ec - Poker Player Window
8 ****************************************************************************/
9 import "poker.ec"
10 import "pokerUtils.ec"
11
12 static char handTypes[10][20] =
13 {
14    "NOTHING",
15    "ONE PAIR",
16    "TWO PAIRS",
17    "THREE OF A KIND",
18    "STRAIGHT",
19    "FLUSH",
20    "FULL HOUSE",
21    "FOUR OF A KIND",
22    "STRAIGHT FLUSH",
23    "ROYAL FLUSH"
24 };
25
26 define GAP = 17;
27
28 class Player : Window
29 {
30    borderStyle = sizable;
31
32    bool human;
33    int numUp, numDown;
34    int money;
35    int up  [52];
36    int down[52];
37    int thisBet;
38    bool folded;
39    int bestHand[5];
40    int handType;
41    bool winner;
42
43    Player()
44    {
45       money = 40 * 2;
46    }
47
48    void OnRedraw(Surface surface)
49    {
50       Poker poker = (Poker)master;
51       int c;
52
53       for(c=0; c<numDown; c++)
54       {
55          poker.DrawCard(surface, c*GAP, 0, (human || gameOver && !folded) ? POKER_Card(down[c]) : -1);
56       }
57       POKER_HandType(bestHand);
58       for(c=0; c<numUp; c++)
59          poker.DrawCard(surface, c*GAP, 40, folded ? -1 : POKER_Card(up[c]));
60       if(folded)
61       {
62          surface.SetForeground(blue);
63          surface.WriteTextf(10, 175, "FOLDED");
64       }
65       else if(gameOver)
66       {
67          surface.SetForeground(red);
68          if(winner)
69             surface.WriteTextf(10, 175, "WINNER");
70          surface.SetForeground(blue);
71          surface.WriteTextf(80, 175, "%s", handTypes[handType]);
72       }
73       surface.SetForeground(white);
74       surface.WriteTextf(110, 155, "$%.2f", money / 2.0);
75    }
76 }