forked from nathanhales/Rock-Paper-Scissors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissorsGame.cs
More file actions
136 lines (108 loc) · 4.28 KB
/
RockPaperScissorsGame.cs
File metadata and controls
136 lines (108 loc) · 4.28 KB
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
namespace Rock_Paper_Scissors
{
class RockPaperScissorsGame
{
public Player Player1 { get; set; }
public Player Player2 { get; set; }
public ScoreKeeper Score { get; set; }
public RockPaperScissorsGame()
{
Player Player1 = new Player("Player 1");
Player Player2 = new Player("Player 2");
}
public void Run()
{
// GAME START
int maxScore = 5;
ScoreKeeper Score = new ScoreKeeper();
Console.WriteLine("----- ROCK, PAPER, SCISSORS -----\n");
Console.WriteLine("Player 1, please enter your name... \n");
string player1Name = Console.ReadLine();
Player Player1 = new Player(player1Name);
Score.p1Name = Player1.Name;
//PLAYER TWO NAME SELECT
Console.Clear();
Console.WriteLine("Player 2, please enter your name... \n");
string player2Name = Console.ReadLine();
Player Player2 = new Player(player2Name);
Score.p2Name = Player2.Name;
Console.Clear();
Console.WriteLine($"Hello {player1Name} and {player2Name}, lets begin!\n");
Console.WriteLine("-------- Press ANY KEY to start --------\n");
Console.ReadKey();
Console.Clear();
int player1Wins = Score.P1Wins;
int player2Wins = Score.P2Wins;
int DetermineWinner(PlayerChoice choice1, PlayerChoice choice2)
{
if (choice1 == choice2)
{
Console.WriteLine("It's a Draw\n");
Score.UpdateScore(0);
return 0;
}
else if (choice1 == PlayerChoice.Rock)
{
if (choice2 == PlayerChoice.Scissors)
{
Score.UpdateScore(1);
Console.WriteLine(player1Name + " Wins!\n");
}
else
{
Score.UpdateScore(2);
Console.WriteLine(player2Name + " Wins!\n");
}
return choice2 == PlayerChoice.Scissors ? 1 : 2;
}
else if (choice1 == PlayerChoice.Scissors)
{
if (choice2 == PlayerChoice.Paper)
{
Score.UpdateScore(1);
Console.WriteLine(player1Name + " Wins!\n");
}
else
{
Score.UpdateScore(2);
Console.WriteLine(player2Name + " Wins!\n");
}
return choice2 == PlayerChoice.Paper ? 1 : 2;
}
else
{
Console.WriteLine(player1Name + " Wins!\n");
return choice2 == PlayerChoice.Rock ? 1 : 2;
}
}
while (player1Wins != maxScore && player2Wins != maxScore)
{
PlayerChoice choice1 = Player1.GetChoice();
Console.Clear();
PlayerChoice choice2 = Player2.GetChoice();
Console.Clear();
int winner = DetermineWinner(choice1, choice2);
if (winner == 1)
{
player1Wins++;
}
else if (winner == 2)
{
player2Wins++;
}
Score.ShowScoreBoard();
Console.WriteLine("\nPress ANY key to Continue...");
Console.ReadKey();
Console.Clear();
}
if (player1Wins == maxScore)
{
Console.WriteLine($"{player1Name}, you are the winner! Well done!");
}
else
{
Console.WriteLine($"{player2Name}, you are the winner! Well done!");
}
}
}
}