SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Collections.Generic; | |
3 | using System.Linq; | |
4 | ||
5 | namespace Wisielec | |
6 | { | |
7 | class Program | |
8 | { | |
9 | static bool sprawdzenieWygranej(string haslo, List<char> listaLiter) | |
10 | { | |
11 | foreach (char litera in haslo) | |
12 | { | |
13 | if (!listaLiter.Contains(litera) && litera != ' ') | |
14 | { | |
15 | return false; | |
16 | } | |
17 | } | |
18 | return true; | |
19 | } | |
20 | ||
21 | static void pokazUzyteLitery(List<char> listaLiter) | |
22 | { | |
23 | Console.Write("Użyte litery to: "); | |
24 | foreach (char litera in listaLiter) | |
25 | { | |
26 | Console.Write(litera + ", "); | |
27 | } | |
28 | Console.WriteLine(); | |
29 | } | |
30 | ||
31 | static void pokazHaslo(string haslo, List<char> listaLiter) | |
32 | { | |
33 | foreach (var litera in haslo) | |
34 | { | |
35 | if (listaLiter.Contains(litera)) | |
36 | { | |
37 | Console.Write(litera); | |
38 | } | |
39 | else if (litera == ' ') | |
40 | { | |
41 | Console.Write(" "); | |
42 | } | |
43 | else | |
44 | { | |
45 | Console.Write("_ "); | |
46 | } | |
47 | } | |
48 | } | |
49 | ||
50 | static void Main(string[] args) | |
51 | { | |
52 | List<string> listaHasel = new List<string>(); | |
53 | ||
54 | listaHasel.Add("hograwts legacy"); | |
55 | listaHasel.Add("god of war"); | |
56 | listaHasel.Add("fortnite"); | |
57 | listaHasel.Add("minecraft"); | |
58 | listaHasel.Add("animal crossing"); | |
59 | ||
60 | Random generatorLiczb = new Random(); | |
61 | int iloscHasel = listaHasel.Count; | |
62 | int wylosowanyIndexHasla = generatorLiczb.Next(iloscHasel); | |
63 | string haslo = listaHasel[wylosowanyIndexHasla]; | |
64 | List<char> listaUzytychLiter = new List<char>(); | |
65 | ||
66 | int szanse = 5; | |
67 | bool czyWygrana = false; | |
68 | ||
69 | while (szanse > 0 && czyWygrana == false) | |
70 | { | |
71 | pokazHaslo(haslo, listaUzytychLiter); | |
72 | ||
73 | Console.WriteLine(); | |
74 | pokazUzyteLitery(listaUzytychLiter); | |
75 | Console.WriteLine("Pozostały Ci " + szanse + " szans"); | |
76 | ||
77 | Console.Write("Podaj literę: "); | |
78 | char wpisanaLitera = Console.ReadLine()[0]; | |
79 | wpisanaLitera = Char.ToLower(wpisanaLitera); | |
80 | Console.Clear(); | |
81 | ||
82 | if (listaUzytychLiter.Contains(wpisanaLitera)) | |
83 | { | |
84 | Console.WriteLine("Ta litera była już użyta"); | |
85 | } | |
86 | else if (haslo.Contains(wpisanaLitera)) | |
87 | { | |
88 | listaUzytychLiter.Add(wpisanaLitera); | |
89 | czyWygrana = sprawdzenieWygranej(haslo, listaUzytychLiter); | |
90 | } | |
91 | else | |
92 | { | |
93 | listaUzytychLiter.Add(wpisanaLitera); | |
94 | szanse--; | |
95 | } | |
96 | } | |
97 | ||
98 | if (czyWygrana) | |
99 | { | |
100 | Console.WriteLine("Wygrałeś!!!"); | |
101 | } | |
102 | else | |
103 | { | |
104 | Console.WriteLine("Niestety nie udało ci się tym razem. Hasło to: " + haslo); | |
105 | } | |
106 | } | |
107 | } | |
108 | } | |
109 | ||
110 |