-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
178 lines (154 loc) · 7.22 KB
/
Program.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
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
using System;
using System.Collections.Generic;
namespace heist
{
class Program
{
static void Main(string[] args)
{
// Store a value for the bank's difficulty level. Set this value to 100.
//? At the beginning of the program, prompt the user to enter the difficulty level of the bank.
Console.Write("Pick a number between 0 and one hundred (bank difficulty)? ");
int difficultyLevel = 0;
bool difficulty = int.TryParse(Console.ReadLine(), out difficultyLevel);
try
{
while (!difficulty || difficultyLevel < 0 || difficultyLevel > 100)
{
if (!difficulty)
{
Console.Write("Can you please enter a number? ");
}
else if (difficultyLevel < 0 || difficultyLevel > 100)
{
Console.Write("Please enter a number between 0 and one hundred: ");
}
difficulty = int.TryParse(Console.ReadLine(), out difficultyLevel);
}
}
catch
{
Console.WriteLine("you broke it");
}
// Create a random number between -10 and 10 for the heist's luck value.
int luckValue = new Random().Next(-10, 10);
Console.WriteLine("Plan Your Heist!");
// Prompt the user to enter a team member's name and save that name.
Squad Squad = new Squad();
string Name = "0";
while (Name != "")
{
Console.Write("Enter a team member's name: ");
Name = Console.ReadLine();
// Prompt the user to enter a team member's skill level and save that skill level with the name.
//? Stop Collecting Team Members when empty string is entered
if (Name != "")
{
Console.Write("Enter a team member's skill level: ");
string Answer = Console.ReadLine();
int SkillLevel;
bool isNum = int.TryParse(Answer, out SkillLevel);
try
{
while (!isNum || SkillLevel < 0)
{
if (!isNum)
{
Console.Write("Can you please enter a number");
}
else if (SkillLevel < 0)
{
Console.Write("Please enter a number greater than 0: ");
}
Answer = Console.ReadLine();
isNum = int.TryParse(Answer, out SkillLevel);
}
}
catch
{
Console.WriteLine("you broke it");
}
// Validation of user input
// And store variables
// Prompt the user to enter a team member's courage factor and save that courage factor with the name.
Console.Write("Enter a team member's courage factor from 0.0 to 2.0: ");
string courageAnswer = Console.ReadLine();
double courageFactor;
isNum = double.TryParse(courageAnswer, out courageFactor);
try
{
while (!isNum || courageFactor < 0.0 || courageFactor > 2.0)
{
if (!isNum)
{
Console.Write("Can you please enter a number");
}
else if (courageFactor < 0.0 || courageFactor > 2.0)
{
Console.Write("Please enter a value between 0.0 and 2.0: ");
}
courageAnswer = Console.ReadLine();
isNum = double.TryParse(courageAnswer, out courageFactor);
}
}
catch
{
Console.WriteLine("you broke it");
}
if (Name != "")
{
//? Collect Several Team Members' information
TeamMember Newguy = new TeamMember(Name, SkillLevel, courageFactor);
Squad.AddTeamMember(Newguy);
}
}
}
//? display team member information
Squad.DisplayTeam();
int trials;
//? After the user enters the team information, prompt them to enter the number of trial runs the program should perform.
Console.Write("How many trials do you want to run? ");
bool newTrials = int.TryParse(Console.ReadLine(), out trials);
while (!newTrials || trials < 1)
{
if (!newTrials)
{
Console.Write("Can you please enter a number");
}
else if (trials < 0)
{
Console.Write("Please enter a number greater than 0: ");
}
newTrials = int.TryParse(Console.ReadLine(), out trials);
}
//* Run the scenario multiple times.
//? Loop through the difficulty / skill level calculation based on the user-entered number of trial runs. Choose a new luck value each time.
int successes = 0;
for (int i = 0; i < trials; i++)
{
// Create a random number between -10 and 10 for the heist's luck value.
luckValue = new Random().Next(-10, 10);
// Add this number to the bank's difficulty level.
int totalDifficulty = difficultyLevel + luckValue;
Console.WriteLine("Bank Difficulty:" + " " + totalDifficulty);
// Before displaying the success or failure message, display a report that shows.
// The team's combined skill level
// The bank's difficulty level
Console.WriteLine("Team Level:" + " " + Squad.TeamLevel);
// Compare the number with the bank's difficulty level. If the team's skill level is greater than or equal to the bank's difficulty level, Display a success message, otherwise display a failure message.
if ((totalDifficulty) <= Squad.TeamLevel)
{
successes++;
Console.WriteLine("Heist is a success!");
}
else
{
Console.WriteLine("Heist failed! Send 'em to Gitmo.");
}
}
//? At the end of the program, display a report showing the number of successful runs and the number of failed runs.
Console.WriteLine("Number of Successes: " + successes);
Console.WriteLine("Number of Failures: " + (trials - successes));
}
}
}