Kopiuj
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cwiczenia
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string[] draw =
{
" _________",
" | | |",
" | O |",
" | /|\\ |",
" | | |",
" | / \\ |",
" /|\\ /|\\",
"/ | \\ / | \\"
};
string[] allWords =
{
"telefon",
"komputer",
"rewolwer",
"autostrada",
"programowanie",
"huragan",
"kompresja",
"kasztan",
"helikopter",
"kamper",
"butelka",
"kaskader",
"laptop",
"komputer",
"myszka",
"telefon",
"pilot",
"koniunkcja",
"operator",
"stolik",
"wyrewolwerowany",
"pastuch",
"owca",
"paluszki",
"krakersy",
"serwis",
"mieszkanie",
"balon",
"obiad",
"karygodny",
"krokodyl",
"autostrada",
"policja",
"konfident",
"bachor",
"kataklizm",
"wariatka",
"kontakt"
};
Random rand = new Random();
string word;
int allWordsLen = allWords.Length;
int random = rand.Next(allWordsLen);
word = allWords[random];
int wordLen = word.Length;
char[] userWord = new char[wordLen];
for (int i = 0; i < wordLen; i++)
{
userWord[i] = '-';
}
int errCount = draw.Length;
int err = 0;
char[] errChars = new char[errCount];
bool game = true;
for (int i = 0; i < errCount; i++)
{
Console.WriteLine(draw[i]);
}
Console.WriteLine("\nNie daj się powiesić!\n");
while (game)
{
for (int i = 0; i < err; i++)
{
Console.WriteLine(draw[i]);
}
Console.WriteLine();
Console.WriteLine(userWord);
Console.WriteLine();
Console.Write("Podane błędne litery: ");
Console.Write(errChars);
Console.WriteLine("Pozostało prób: {0}", errCount - err);
Console.WriteLine("\nPodaj literę: ");
string s = Console.ReadLine();
char c;
if (s.Length > 0)
c = s.ElementAt(0);
else
continue;
bool charFound = false;
bool win = false;
for (int i = 0; i < wordLen; i++)
{
if (c == word.ElementAt(i))
{
userWord[i] = c;
charFound = true;
}
}
bool errCharFound = false;
if (!charFound)
{
err += 1;
for (int i = 0; i < errChars.Length; i++)
{
if (errChars[i] == c)
{
errCharFound = true;
break;
}
}
if (!errCharFound)
{
for (int i = 0; i < errChars.Length; i++)
{
if (errChars[i] == 0)
{
errChars[i] = c;
break;
}
}
}
}
for (int i = 0; i < wordLen; i++)
{
if (userWord[i] == '-')
{
win = false;
break;
}
win = true;
}
if (err == errCount)
{
Console.WriteLine("Powiesiłeś się za słowo: {0}!\n", word);
Console.ReadLine();
game = false;
}
if (win)
{
Console.WriteLine("\nZgadłeś słowo {0}!", word);
Console.ReadLine();
game = false;
}
}
}
}
}
}