static void Main(string[] args) { //Data input and welcome information Console.WriteLine("Welcome!!!"); Console.Write("Enter Your name please: "); var name = Console.ReadLine(); string izbor = "11"; string quit = "quit"; Console.WriteLine(DBkomunikacija.Welcome(name)); Console.WriteLine(); while (!(izbor.Equals(quit))) { //Loops until valid choice is entered do { izbor = Selections.GetPlayerChoice(); }while (!(izbor == Selections.Outcomes.paper.ToString() || izbor == Selections.Outcomes.rock.ToString() || izbor == Selections.Outcomes.scissors.ToString())); //Coverts Humans and CPU's choice to Enum Selections.Outcomes Human; Enum.TryParse(izbor, out Human); Selections.Outcomes CPU; Enum.TryParse(ComputerPKM.GetSelection(), out CPU); //Decites winner Selections.DecideWinner(name, Human, CPU); } }
public static void DecideWinner(string name, Outcomes human, Outcomes cpu) { Node stone = new Node(); Node paper = new Node(Outcomes.paper, stone); Node scissors = new Node(Outcomes.scissors, paper); stone.data = Outcomes.rock; stone.next = scissors; Node current = paper; for (int i = 0; i < 3; i++) { if (current.data == cpu) { break; } else { current = current.next; } } if (human == current.data) { Console.WriteLine("It's a tie!"); } if (human == current.next.data) { var i = DBkomunikacija.NumberofVictories(name); int k = i + 1; Console.WriteLine($"Congratulations, You won! Your opponent chose {FirstCharToUpper(cpu.ToString())}. Your number of wins is: " + k); DBkomunikacija.InsertDataIntoDB(name, k); } if (human == current.next.next.data) { Console.WriteLine($"Too bad, the opponent chose {FirstCharToUpper(cpu.ToString())}. You lost..."); } }