-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTask3.cs
141 lines (138 loc) · 5.36 KB
/
Task3.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
using System;
namespace ThirdTask
{
class Program
{
public static void notNumber()
{
Console.WriteLine("There are three levels: Easy, Medium and Hard");
Console.Write ("Enter a level to play: ");
string userChoice = Console.ReadLine();
bool gameStart = true;
}
static void Main (string[] args)
{
//game variables
int guess;
int attempts = 0;
int guess_limit = 0;
bool gameStart = true;
string gameLevels = "There are three levels:Easy, Medium and Hard";
//game start
Console.Write("Welcome to my number guessing game. To exit at any time, type quit. ");
Console.WriteLine(gameLevels);
Console.Write("Enter a level to play: ");
string userChoice = Console.ReadLine();
while (gameStart)
{
if (userChoice == "easy")
{
guess_limit = 6;
int secretNumber = 7;
Console.WriteLine("Let the games begin... you have 6 chances to guess the number between 1 and 10.");
while (guess_limit != 0)
{
Console.Write("Guess the number: ");
string guess_value = Console.ReadLine();
attempts += 1;
guess_limit -= 1;
if(guess_value == "quit")
{
gameStart = false;
break;
}
else if (int.TryParse(guess_value, out guess))
{
if (guess == secretNumber)
{
Console.WriteLine("You got it right!");
break;
}
else
{
Console.WriteLine("That was wrong. You have " + guess_limit + " guesses left. ");
}
}
else
{
notNumber();
guess_limit = 6;
}
}
Console.WriteLine("Game Over!");
break;
}
else if (userChoice == "medium")
{
guess_limit = 4;
int secretNumber = 16;
Console.WriteLine("You are required to guess the number between 1 and 20, you have 4 guesses. \nLet the games begin...");
while (guess_limit != 0)
{
Console.Write("Guess the number: ");
string guess_value = Console.ReadLine();
attempts += 1;
guess_limit -= 1;
if (int.TryParse(guess_value, out guess))
{
if (guess == secretNumber)
{
Console.WriteLine("You got it right!");
break;
}
else
{
Console.WriteLine("That was wrong. You have " + guess_limit + " guesses left. ");
}
}
else
{
notNumber();
}
}
Console.WriteLine("Game Over!");
break;
}
else if (userChoice == "hard")
{
guess_limit = 3;
int secretNumber = 16;
Console.WriteLine("You are required to guess the number between 1 and 50 with only 3 attempts. \nLet the games begin...");
while (guess_limit != 0)
{
Console.Write("Guess the number: ");
string guess_value = Console.ReadLine();
attempts += 1;
guess_limit -= 1;
if (int.TryParse(guess_value, out guess))
{
if (guess == secretNumber)
{
Console.WriteLine("You got it right!");
break;
}
else
{
Console.WriteLine("That was wrong. You have " + guess_limit + " guesses left. ");
}
}
else
{
notNumber();
}
}
Console.WriteLine("Game Over!");
break;
}
else if (userChoice == "quit")
{
break;
}
else
{
Console.Write("Please enter easy medium or hard to play if not, quit.");
}
}
}
}
}