So i got my hangman up and running but the what i dont like is the way my program picks the random word (which isnt completely random and can be guessed, pseudo)..
NOTE: Some parts in the code are in Slovene language. I changed the important ones to english.
I'm trying to make a simpler and actually random way to pick that word. I did try to implement various other options but without success...
Also i do not really understand how DateTime.Now.Ticks picks a word.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace HANGMAN //moj imenski prostor
{
class Program
{
static void Main(string[] args)
{
Random random = new Random((int)DateTime.Now.Ticks);
string[] WORDBANK = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF" };
string WordToGuess = WORDBANK[random.Next(0, WORDBANK.Length)];
string WordToGuessUppercase = WordToGuess.ToUpper();
StringBuilder displayToPlayer = new StringBuilder(WordToGuess.Length);
for (int i = 0; i < WordToGuess.Length; i++)
displayToPlayer.Append('_');
List<char> correctGuesses = new List<char>();
List<char> incorrectGuesses = new List<char>();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("__________________________________________________________________");
Console.WriteLine();
Console.Write("VISLICE - Maturitetna Naloga pri predmetu Informatika");
Console.WriteLine();
Console.WriteLine("__________________________________________________________________");
Console.WriteLine();
Console.WriteLine("-> Imas 5 poizkusov <-");
Console.WriteLine();
Thread.Sleep(500);
int lives = 5;
bool won = false;
int lettersRevealed = 0;
string input;
char Guess;
while (!won && lives > 0)
{
Thread.Sleep(500);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Ugani besedo, izberi crko: ");
Console.WriteLine();
input = Console.ReadLine().ToUpper();
Ugib = input[0];
if (correctGuesses.Contains(Guess))
{
Thread.Sleep(500);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Crko '{0}' si ze uporabil, bila je pravilna!", Guess);
Console.WriteLine("____________________________________________");
continue;
}
else if (nepravilniUgibi.Contains(Ugib))
{
Thread.Sleep(500);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Crko '{0}' si ze uporabil, bila je napacna!", Guess);
Console.WriteLine("___________________________________________");
continue;
}
if (WordToGuessUppercase.Contains(Guess))
{
pravilniUgibi.Add(Ugib);
for (int i = 0; i < WordToGuess.Length; i++)
{
if (WordToGuessUppercase[i] == Guess)
{
displayToPlayer[i] = WordToGuess[i];
lettersRevealed++;
}
}
if (lettersRevealed == WordToGuess.Length)
won = true;
}
else
{
incorrectGuesses.Add(Guess);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Narobe, crke '{0}', ni v besedi!", Guess);
Console.WriteLine("________________________________");
Console.WriteLine();
poizkusi--;
}
Console.WriteLine(displayToPlayer.ToString());
}
if (won)
{
Console.WriteLine();
Thread.Sleep(500);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Zmaga!");
Console.WriteLine();
Thread.Sleep(1000);
Console.WriteLine("KONEC IGRE");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine();
Thread.Sleep(1000);
Console.WriteLine("Zal si to igro zgubil. Poskusi ponovno! Pravilna beseda je bila '{0}'", WordToGuess);
}
}
}
}