-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
187 lines (147 loc) · 6.68 KB
/
Program.cs
File metadata and controls
187 lines (147 loc) · 6.68 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
using System;
using System.Net.Http.Headers;
namespace RPGDemo
{
internal class Program
{
static void Main(string[] args)
{
// Define the list that is going to keep track of the game history
List<string> gameHistory = new List<string>();
// Create and store the random class
Random random = new Random();
// Create the player character
Player player = new Player();
// Output the text stating that we want the players name
Console.WriteLine("What is your name?");
// Store the players name entered
player.Name = Console.ReadLine();
// Let the player know their name
Console.WriteLine("Thank you for entering your name, " + player.Name + ".\n");
// Create a variable to track the first enemy
Enemy firstEnemy = new Enemy("Giant Enemy Crab");
// Perform the battle game loop
GameLoop(firstEnemy, random, player, 5, 20, gameHistory);
// Check if the player was the one who died
if (!player.IsDead)
{
// Create the boss character
Boss boss = new Boss();
GameLoop(boss, random, player, 50, 10, gameHistory);
if (!player.IsDead)
{
// The player won the game
Console.WriteLine("Congratulations " + player.Name + ".\nYour Winner!");
}
else
{
GameOver();
}
}
else
{
// The game is over
GameOver();
}
// Let the player know the history
Console.WriteLine("\n\nThis is the history of the game.\n\n");
// Loop through the whole game history
foreach (var history in gameHistory)
{
// Write out the game history
Console.WriteLine(history);
}
}
/// <summary>
/// Writes out what happens when the game is over
/// </summary>
private static void GameOver()
{
// The player is dead, let the user know the game is over
Console.WriteLine("GAME OVER");
}
/// <summary>
/// The main game loop that allows the player to attack an enemy
/// </summary>
/// <param name="enemy">The enemy the player will attack</param>
/// <param name="random">The rng we will use to generate random numbers</param>
/// <param name="player">The player that we are playing as</param>
/// <param name="max_attack_power">The max attack power the enemy has</param>
/// <param name="max_player_attack_power">The player's max attack power</param>
/// <param name="gameHistoryList">The list that contains the game history that we will add to</param>
private static void GameLoop(Enemy enemy, Random random, Player player, int max_attack_power, int max_player_attack_power, List<string> gameHistoryList)
{
// Define a list of the strings we will use to write out
string initialText = player.Name + " you have encountered a " + enemy.Name + "!";
string attackText = null;
string enemyAttackText = null;
// Write out to the screen about the enemy attack
Console.WriteLine(initialText);
// Add the string to the game history
gameHistoryList.Add(initialText);
// While the enemy and player are not dead, repeat the playable cycle
while (!enemy.IsDead && !player.IsDead)
{
//Write out to the screen your options
Console.WriteLine("What would you like to do?\n\n1.Single Attack\n2.Three Strike Attack\n3.Defend\n4.Heal");
//Store what action the player chose
string playersAction = Console.ReadLine();
// Check what action the player took
switch (playersAction)
{
case "1":
// Save the attack text
attackText = "You chose to single attack " + enemy.Name + "!";
// Write out that we chose 1
Console.WriteLine(attackText);
// Add to history
gameHistoryList.Add(attackText);
// Apply the attack damage to the enemy
enemy.GetsHit(random.Next(1, max_player_attack_power));
break;
case "2":
attackText = "You chose to multi attack the " + enemy.Name + "!";
Console.WriteLine(attackText);
gameHistoryList.Add(attackText);
// Loop three times to perform out multi attack
for (int i = 0; i < 3; i++)
{
enemy.GetsHit(random.Next(1, max_player_attack_power));
// Check if the enemy is dead
if (enemy.IsDead)
{
// Break out of the for loop
break;
}
}
break;
case "3":
attackText = "You chose to defend!";
Console.WriteLine(attackText);
gameHistoryList.Add(attackText);
// Set that the player is guarding
player.IsGaurding = true;
break;
case "4":
attackText = "You chose to heal!";
Console.WriteLine(attackText);
gameHistoryList.Add(attackText);
// Heal the player a random amount
player.Heal(random.Next(5, 15));
break;
default:
Console.WriteLine("You chose to wait.");
break;
}
// Make sure the enemy is not dead
if (!enemy.IsDead)
{
// Write out that the enemy attacked
gameHistoryList.Add("The enemy attacked the player.");
// Have the enemy attack the player
player.GetsHit(random.Next(1, max_attack_power));
}
}
}
}
}