namespace WindowsFormsApplicat ion2 public partial class Form1 Form pu

  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
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public static int PlayersPoints;
public static int IIPoints;
public static int VictoryCountP;
public static int VictoryCountII;
public static List<string> cards;
public static List<string> playerscards;
public static int indexPC;
public static int indexIIC;
public static int CheckCards(List<string> PlayersCards, int index, int playerspoints)
{
int e=0;
char[] s = PlayersCards[index].ToCharArray();
for (int i = 54; i <= 57; i++)
{
if (s[0] == i) { playerspoints += e; return playerspoints; }
e++;
};
switch (s[0])
{
case 'z':
{
playerspoints += 10;
break;
}
case 'v':
{
playerspoints += 2;
break;
}
case 'd':
{
playerspoints += 3;
break;
}
case 'k':
{
playerspoints += 4;
break;
}
case 't':
{
playerspoints += 11;
break;
}
}
// if (s[0] == Convert.ToChar("z")) { playerspoints += 10; return playerspoints; }
// if (s[0] == Convert.ToChar("v")) { playerspoints += 2; return playerspoints; }
// if (s[0] == Convert.ToChar("d")) { playerspoints += 3; return playerspoints; }
// if (s[0] == Convert.ToChar("k")) { playerspoints += 4; return playerspoints; }
// if (s[0] == Convert.ToChar("t")) { playerspoints += 11; return playerspoints; }
return playerspoints;
return index;
}
public static void FindRndmCard(List<string> PlayersCards,List<string> Cards, int index, int Count)
{
Random rnd = new Random();
int rndm = rnd.Next(Count);
PlayersCards.Insert(PlayersCards.Count(), Cards[rndm]);
Cards.RemoveAt(rndm);
}
public Form1()
{
InitializeComponent();
//p-piki k-kresti c-chervi b-bubi
//v-valet d-dama k-korol t-tuz z-decyt
List<string> cards = new List<string> { "6p", "6k", "6c", "6b", "7p", "7k", "7c", "7b", "8p", "8k", "8c", "8b", "9p", "9k", "9c", "9b", "zp", "zk", "zc", "zb", "vp", "vk", "vc", "vb", "dp", "dk", "dc", "db", "kp", "kk", "kc", "kb", "tp", "tk", "tc", "tb" };
List<string> playerscards = new List<string>();
List<string> iiscards = new List<string>();
//player
FindRndmCard(playerscards, cards, indexPC, cards.Count());
PlayersPoints += CheckCards(playerscards, indexPC, PlayersPoints);
indexPC++;
FindRndmCard(playerscards, cards, indexPC, cards.Count());
PlayersPoints+=CheckCards(playerscards, indexPC, PlayersPoints);
indexPC++;
label10.Text = Convert.ToString(PlayersPoints);
if (PlayersPoints > 21)
{
label14.Visible = true;
label7.Visible = true;
label9.Visible = true;
label11.Visible = true;
VictoryCountP++;
}
//ii
FindRndmCard(iiscards, cards, indexIIC, cards.Count());
IIPoints += CheckCards(iiscards, indexIIC, IIPoints);
indexIIC++;
FindRndmCard(iiscards, cards, indexIIC, cards.Count());
IIPoints+=CheckCards(iiscards, indexIIC, IIPoints);
indexIIC++;
label11.Text = Convert.ToString(IIPoints);
if (IIPoints > 21)
{
label15.Visible = true;
label8.Visible = true;
label6.Visible = true;
label11.Visible = true;
VictoryCountII++;
}
while (IIPoints < 17)
{
FindRndmCard(iiscards, cards, indexIIC, cards.Count());
IIPoints += CheckCards(iiscards, indexIIC, IIPoints);
indexIIC++;
}
}
private void button3_Click(object sender, EventArgs e)
{
if (PlayersPoints > IIPoints)
{
label6.Visible = true;
label8.Visible = true;
label11.Visible = true;
VictoryCountP++;
}
else
{
label7.Visible = true;
label9.Visible = true;
label11.Visible = true;
VictoryCountII++;
}
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
FindRndmCard(playerscards, cards, indexPC, cards.Count());
PlayersPoints += CheckCards(playerscards, indexPC, PlayersPoints);
indexPC++;
}
private void button4_Click(object sender, EventArgs e)
{
label13.Text = Convert.ToString(VictoryCountP);
label12.Text = Convert.ToString(VictoryCountII);
}