-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShadowWizardMoneyGame.cs
More file actions
198 lines (172 loc) · 6.31 KB
/
ShadowWizardMoneyGame.cs
File metadata and controls
198 lines (172 loc) · 6.31 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.IO;
class Score
//create and keep score incrementally at the end of each game
{
private static int player1Score =0;
private static int player2Score =0;
public static int GetScore(int playerNum)
{
if (playerNum == 1)
{
return player1Score;
}
else
{
return player2Score;
}
}
public static int IncreaseScore(int playerNum)
{
if (playerNum == 1)
{
player1Score++;
return player1Score;
}
else
{
player2Score++;
return player2Score;
}
}
}
class Program
{
public static string[] moves = {"rock", "paper", "scissors"};
public static int currentGame = 1;
public static int maxNumOfGames =6;
public static string savedFile = "gamelog.txt";
//name save file for the rest of program
public static void Main (string[] args)
{
string playAgain = "y";
GameTitle("Shadow Wizard Money Game");
string player1Name = InputName(1);
string player2Name = InputName(2);
while(playAgain == "y" && currentGame < maxNumOfGames)//loop starts here so players don't input names each round
{
Console.Clear();
//shows scores from the save file at top of screen
if (File.Exists(savedFile) == true)
{
Console.WriteLine("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
Console.WriteLine("Previous Game Scores;");
ReadFromFile();
Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n");
}
Console.WriteLine($"\nWelcome {player1Name} and {player2Name}! You are now within the Shadow Arena.\n");
Console.WriteLine("Game Number: " + currentGame);
int player1Move = InputMove(player1Name);
int player2Move = InputMove(player2Name);
GameResult(player1Name, player2Name, player1Move, player2Move);
if (currentGame < 5)//This prevents the player being asked if they want to play again at the end of their final game
{
playAgain = PlayAgain();
}
currentGame++;
Console.Clear();
}
DisplayScores(player1Name, player2Name);
}
//Display the game title with decorations
public static void GameTitle(string programName)
{
Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n"+
$"Welcome to {programName}!\n\n"+
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n");
Console.WriteLine("In the Shadow Arena, whoever has the most wins out of 5 games is the winner, the loser is shadow cursed for eternity");
}
//I'm using string interpolation for number and playerName because it was easier to get working the way I wanted.
public static string InputName(int number)
//players enter their names
{
Console.WriteLine($"\nPlayer {number}, what is your name? Press ENTER when you're ready to continue");
string playerName = Console.ReadLine();
return playerName;
}
public static int InputMove(string playerName)
//players pick spell, ints are adjusted so spells are printed with correct number next to it
{
int spellNumber = 1;
Console.WriteLine($"{playerName} It's your turn to cast a spell");
foreach (string spell in moves)
{
Console.WriteLine(Convert.ToString(spellNumber) + ". " + spell);
spellNumber++;
}
Console.WriteLine("Enter '1' for Rock '2' for Paper or '3' for Scissors and press ENTER to confirm");
int move = Convert.ToInt32(Console.ReadLine()) -1;
return move;
}
public static string PlayAgain()
//players can quit or continue between rounds
{
string playAgain;
Console.WriteLine ("Thank you for playing Shadow Wizard Money Game");
Console.WriteLine ("Press 'y' and ENTER if you want to play again");
playAgain = Console.ReadLine();
return playAgain;
}
public static void DisplayScores(string player1Name, string player2Name)
//displays final score at the end of 5 rounds and delcares the winner based on best of 5
{
Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
Console.WriteLine(player1Name + "'s Score: ");
Console.WriteLine(Score.GetScore(1));
Console.WriteLine(player2Name + "'s Score: ");
Console.WriteLine(Score.GetScore(2));
Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
if (Score.GetScore(1) == Score.GetScore(2))
{
Console.WriteLine("The contest is a tie! Both players are shadow cursed for eternity...");
}
else if (Score.GetScore(1) > Score.GetScore(2))
{
Console.WriteLine(player1Name + " wins the Shadow Wizard Money Game!");
Console.WriteLine(player2Name + " is shadow cursed for eternity...");
}
else
{
Console.WriteLine(player2Name + " wins the Shadow Wizard Money Game!");
Console.WriteLine(player1Name + " is shadow cursed for eternity...");
}
WriteToFile("The Final Scores of the last game played:\n" + player1Name + "'s Score: " + Score.GetScore(1) + "\n" +player2Name + "'s Score: " + Score.GetScore(2));
}
public static void GameResult(string player1Name, string player2Name, int player1Move, int player2Move)
//game logic to figure out who wins the round and adds 1 to the score of the winner
{
// Combine the moves into a single string
string resultCombined = moves[player1Move] + moves[player2Move];
// Check the combined moves and display the winner or draw
if (resultCombined == "rockscissors" || resultCombined == "scissorspaper" || resultCombined == "paperrock")
{
Console.WriteLine (player1Name + " WINS!");
Score.IncreaseScore(1);
}
else if (resultCombined == "rockpaper" || resultCombined == "scissorsrock" || resultCombined == "paperscissors")
{
Console.WriteLine (player2Name + " WINS!");
Score.IncreaseScore(2);
}
else if (resultCombined == "rockrock" || resultCombined == "scissorsscissors" || resultCombined == "paperpaper")
{
Console.WriteLine ("Draw");
//my way of catching incorrect input no longer works but it's not needed for assignment requirements
}
}
public static void WriteToFile(string Log)
//saves to the savefile for future access
{
string writeText = Log;
File.WriteAllText(savedFile, writeText);
}
public static void ReadFromFile()
//Reads from saved file
{
string[] lines = File.ReadAllLines(savedFile);
foreach (string line in lines)
{
Console.WriteLine(line);
}
}
}