-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
133 lines (101 loc) · 3.64 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
using System;
// Namespace
namespace NumberGuesser
{
//Main Class
class Program
{
// Entry Point Method
static void Main(string[] args)
{
/* string name = "Bruno Lopes";
int age = 25;
Console.WriteLine(name+" é "+age);
Console.WriteLine("{0} é {1}", name, age);*/
GetAppInfo(); //Run function
GreetUser(); //Run function
while (true)
{
//Init correct number
//int correctNumber = 7;
//Create a new random object
Random random = new Random();
int correctNumber = random.Next(1, 10);
// Init guess var
int guess = 0;
//Ask user for number
Console.WriteLine("Advinha um número entre 1 e 10");
//While guess is not correct
while (guess != correctNumber)
{
//Get users input
string input = Console.ReadLine();
// Make suer its a number
if (!int.TryParse(input, out guess))
{
PrintColorMessage(ConsoleColor.Red, "Tem que ser um numero pah!");
//Keep Going
continue;
}
// Cast to int and put in guess
guess = Int32.Parse(input);
//Match guee to correct number
if (guess != correctNumber)
{
PrintColorMessage(ConsoleColor.Red , "Incorrecto!, Tenta novamente");
}
}
//Output success message
PrintColorMessage(ConsoleColor.Yellow, "CORRETISSIMO PA!");
//Ask to play again
Console.WriteLine("Play again [Y or N]");
//Get answer
String answer = Console.ReadLine().ToUpper();
if(answer == "Y")
{
continue;
}
else if(answer == "N")
{
return;
}
else
{
return;
}
}
}
static void GetAppInfo()
{
// Set app vars
string appName = "Number Guesser";
string appVersion = "1.0.0";
string appAuthor = "Bruno Lopes";
//Change text color
Console.ForegroundColor = ConsoleColor.Green;
//Write out app info
Console.WriteLine("{0}: Version {1} by {2}", appName, appVersion, appAuthor);
//Reset text color
Console.ResetColor();
}
//Ask a users name
static void GreetUser()
{
//ask users name
Console.WriteLine("Qual é o teu nome?");
//Get user input
string inputName = Console.ReadLine();
Console.WriteLine("Hello {0}, let's play a game.", inputName);
}
//Print coor message
static void PrintColorMessage(ConsoleColor color, string message)
{
//Change text color
Console.ForegroundColor = color;
//tell user its not a number
Console.WriteLine(message);
//Reset text color
Console.ResetColor();
}
}
}