Skip to content

Commit

Permalink
#2: Játék ciklikusság megoldása
Browse files Browse the repository at this point in the history
  • Loading branch information
PAULTR71 committed Mar 6, 2019
1 parent b37842b commit 388d506
Showing 1 changed file with 14 additions and 59 deletions.
73 changes: 14 additions & 59 deletions kpo/kpo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,38 @@ class Program
{
static void Main(string[] args)
{
///
///Program: Kő papir olló játék leprogramozása
///Irta: Tresó Pál / 2019.03.06
///Adott: számítógép - véletlenszerűen választ k/p/o
///Játékos: billentyűzeten választ

Random r = new Random();
string compChoice = "";
string playerChoice = "";

int compScore = 0;
int playerScore = 0;
///Megoldandó feladat 1:
///Ciklikus programfutás, amig a felhasználó szeretne játszani
bool moreGame = true;

bool l = true;
Console.WriteLine("*******Kő/Papir/Olló játék*********");

do
{


Console.WriteLine("Mit választasz? k/p/o");

switch (Console.ReadKey(true).KeyChar)
{
case 'k':
playerChoice = "kő";
break;
case 'p':
playerChoice = "papir";
break;
case 'o':
playerChoice = "olló";
break;
}
switch (r.Next(0, 3))
{
case 0:
compChoice = "kő";
break;
case 1:
compChoice = "papir";
break;
case 2:
compChoice = "olló";
break;
}

if (
(playerChoice == "kő" && compChoice == "papir") ||
(playerChoice == "papir" && compChoice == "olló") ||
(playerChoice == "olló" && compChoice == "kő")
)
{
Console.WriteLine("Számítógép: " + compChoice + " Te: " + playerChoice);
Console.WriteLine("Veszitettél! Állás: Szg: {0} Játékos: {1}", ++compScore, playerScore);

}


else if (playerChoice == compChoice)
{
Console.WriteLine("Számítógép: " + compChoice + " Te: " + playerChoice);
Console.WriteLine("Döntetlen! Állás: Szg: {0} Játékos: {1}", compScore, playerScore);
}
else
{
Console.WriteLine("Számítógép: " + compChoice + " Te: " + playerChoice);
Console.WriteLine("Nyertél! Állás: Szg: {0} Játékos: {1}", compScore, ++playerScore);

}

Console.WriteLine("Akarsz még játszani? i/n");
Console.Write("Akarsz még játszani? i/n");
if (Console.ReadKey(true).KeyChar == 'n')
{
l = false;
moreGame = false;
}
} while (l);

} while (moreGame);



Console.ReadKey();



}
}
}

0 comments on commit 388d506

Please sign in to comment.