-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
173 lines (151 loc) · 4.53 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarlosSeptica
{
public enum PlayerType
{
PLAYER_HUMAN,
PLAYER_AI
}
public class Player : Clonable
{
public PlayerType Type
{
get;
set;
}
private Card[] hand;
public int CardsInHand
{
get
{
int cards = 0;
for(int i = 0; i < hand.Length; ++i)
{
if(hand[i] != null)
{
++cards;
}
}
// hand.ToList().Select(card => card != null).Count() seems to be fucked up so manually counting...
return cards;
}
}
public bool IsHandFull
{
get
{
return CardsInHand == hand.Length;
}
}
private List<Card> collectedCardStack;
public int Score
{
get
{
return collectedCardStack.Where(card => card.Number == CardNumber.CARD_10 || card.Number == CardNumber.CARD_A).Count();
}
}
public Player(PlayerType type)
{
Type = type;
hand = new Card[4];
collectedCardStack = new List<Card>();
}
public Card[] GetCardsInHand()
{
return hand;
}
public void AddCardToStack(Card card)
{
collectedCardStack.Add(card);
}
public void AddCardInHand(Card card)
{
// Fill cards from left to right for player and right to left for A.I.
// Or maybe the other way around
//int start = Type == PlayerType.PLAYER_HUMAN ? 3 : 0;
//int end = 3 - start;
//int increment = start < end ? 1 : -1;
//for(int i = start; i != (end + increment); i += increment)
//{
// if (hand[i] == null)
// {
// hand[i] = card;
// break;
// }
//}
//
// ^^^ I like this shit better, but the teammates doesn't seem to agree... fuck my life :|
//
for (int i = 0; i < hand.Length; ++i)
{
if (hand[i] == null)
{
hand[i] = card;
break;
}
}
}
public int GetCardHandIndexAtCoords(int x, int y)
{
if(y >= 0 && y <= 133)
{
for(int i = 0; i < hand.Length; ++i)
{
if(x >= 100*i && x <= 100*i + 98)
{
return i;
}
}
}
return -1;
}
public void Draw(Graphics g, int x, int y)
{
// Draw cards in hand
for(int i = 0; i < hand.Length; ++i)
{
if(hand[i] != null)
{
// TODO: REPLACE FALSE WITH Type == PlayerType.PLAYER_AI
// TO HIDE AI CARDS AFTER DEBUGGING
hand[i].Draw(g, x + 100 * i, y, Type == PlayerType.PLAYER_AI);
}
}
// Draw cards in stack
for (int i = 0; i < collectedCardStack.Count; ++i)
{
collectedCardStack[i].Draw(g, 450 + x + i, y, true);
}
// Draw name
Font drawFont = new Font("Arial", 32);
SolidBrush drawBrush = new SolidBrush(Color.Black);
bool h = Type == PlayerType.PLAYER_HUMAN;
g.DrawString(h ? "HOOMAN" : "CARLOS A.I.", drawFont, drawBrush, h ? x + 100 : x + 70, h ? y + 150 : y - 50);
// Draw score
drawFont = new Font("Arial", 16);
g.DrawString("Score: " + Score, drawFont, drawBrush, x + 450, h ? y + 16 + 133 : y - 20 - 16);
}
public Clonable Clone()
{
Player clone = new Player(Type);
for(int i = 0; i < hand.Length; ++i)
{
if(hand[i] != null)
{
clone.hand[i] = (Card)hand[i].Clone();
}
}
foreach(Card c in collectedCardStack)
{
clone.AddCardToStack((Card)c.Clone());
}
return clone;
}
}
}