-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path21.cs
99 lines (98 loc) · 3.66 KB
/
21.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
using System;
namespace firstapp
{
class Program
{
static void Main(string[] args)
{
Game Game1 = new Game();
Gamer Gamer1 = new Gamer(1);
Gamer Gamer2 = new Gamer(0);
Console.Write("\n\n Gamer1:\n");
Game.DisplayCards(Gamer1);
Console.Write("\n\n You:\n");
Game.DisplayCards(Gamer2);
int i = 2;
if (Game.Calculate(Gamer1.Cards) != 21 && Game.Calculate(Gamer2.Cards) != 21)
{
while (Gamer.WantMorecard().KeyChar.ToString() == "y" && i < 8 && Game.Calculate(Gamer2.Cards) < 21)
{
Console.Write("\nGetting more cards\n");
Gamer2.Cards[i] = Game.GetCard();
i++;
Console.Write("\n\n Gamer1:\n");
Game.DisplayCards(Gamer1);
Console.Write("\n\n You:\n");
Game.DisplayCards(Gamer2);
if (Game.Calculate(Gamer2.Cards) >= 21)
break;
}
i = 2;
while (Game.Calculate(Gamer1.Cards) < 17)
{
Gamer1.Cards[i] = Game.GetCard();
i++;
}
}
Console.Write("\n\n Gamer1:\n");
Console.Write($"\nCard0 {Gamer1.Cards[0]}\n");
Game.DisplayCards(Gamer1);
Console.Write($"\nTotal: {Game.Calculate(Gamer1.Cards)}\n");
Console.Write("\n\n You:\n");
Game.DisplayCards(Gamer2);
if ((Game.Calculate(Gamer1.Cards) > Game.Calculate(Gamer2.Cards) && Game.Calculate(Gamer1.Cards) < 22) || Game.Calculate(Gamer2.Cards) > 21)
Console.Write("\n You lost!");
else if (Game.Calculate(Gamer1.Cards) == Game.Calculate(Gamer2.Cards))
Console.Write("\n No one win!");
else
Console.Write("\n You win!");
Console.ReadKey();
}
}
class Game
{
public static int GetCard()
{
int[] Cards = new int[52] { 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11 };
Random random = new Random();
int Index = random.Next(0, Cards.Length);
int Card = Cards[Index];
return Card;
}
public static int Calculate(int[] Cards)
{
int total = 0;
foreach (int i in Cards)
total = total + i;
return total;
}
public static void DisplayCards(Gamer GamerLocal)
{
for (int i = 0; i < 9; i++)
{
if (GamerLocal.Cards[i] > 0 && (GamerLocal.IsCas == 0 || i > 0))
Console.Write($"Card{i}: {GamerLocal.Cards[i]}\n");
}
if (GamerLocal.IsCas != 1)
Console.Write($"\n Total: {Game.Calculate(GamerLocal.Cards)}\n");
}
}
class Gamer
{
public int[] Cards = new int[9] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
public static ConsoleKeyInfo Answer;
public int IsCas;
public static ConsoleKeyInfo WantMorecard()
{
Console.WriteLine("\nWant more cards? (y\\n)\n");
Answer = Console.ReadKey();
return Answer;
}
public Gamer(int Cas)
{
Cards[0] = Game.GetCard();
Cards[1] = Game.GetCard();
IsCas = Cas;
}
}
}