-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
106 lines (78 loc) · 2.84 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
using System;
namespace NumberGues
{
class Program
{
static void Main(string[] args)
{
GetAppInfo();
string userName = GetUserName();
GreetUser(userName);
Random random = new Random();
int correctNumber = random.Next(1, 11);
string test = "123";
bool correctAnswer = false;
Console.WriteLine("Zgdanij wylosowaną liczbę z przedziału od 1 do 10");
while (correctAnswer == false)
{
string input = Console.ReadLine();
int guess;
bool isNumber = int.TryParse(input, out guess);
if (!isNumber)
{
PrintColorMessage(ConsoleColor.Yellow, "Proszę wprowadzić liczbę!");
Console.ResetColor();
continue;
}
if (guess < 1 || guess > 10)
{
PrintColorMessage(ConsoleColor.Yellow, "Proszę wprowadzić liczbę w przedziale od 1 do 10");
Console.ResetColor();
continue;
}
if (guess < correctNumber)
{
PrintColorMessage(ConsoleColor.Red, "Błędna odpowiedź :(");
Console.ResetColor();
}
else if (guess > correctNumber)
{
PrintColorMessage(ConsoleColor.Red, "Błędna liczba, wylosowana liczba jest mniejsza");
Console.ResetColor();
}
else
{
correctAnswer = true;
PrintColorMessage(ConsoleColor.Green, "Brawo! Odpowiedź jest prawidłowa");
Console.ResetColor();
}
}
}
static void GetAppInfo()
{
string appName = "Zgadywanie liczby";
int appVersion = 1;
string appAuthor = "Oskar Przybysz";
string info = $"[{appName}] Wersja 0.{appVersion}, Author: {appAuthor}";
PrintColorMessage(ConsoleColor.Magenta, info);
Console.ForegroundColor = ConsoleColor.Magenta;
Console.ResetColor();
}
static string GetUserName()
{
Console.WriteLine("Jak masz na imię ?");
string inputUserName = Console.ReadLine();
return inputUserName;
}
static void GreetUser(string userName)
{
string greet = $"Powodzenia {userName}, odgadnij liczbę...";
PrintColorMessage(ConsoleColor.Blue, greet);
}
static void PrintColorMessage(ConsoleColor color, string message)
{
Console.ForegroundColor = color;
Console.WriteLine(message);
}
}
}