public bool GetMove(out Move move) { move = Move.Rock; var answer = proc.Read(true).FirstOrDefault(s => R.TextMoveLegal(s)); if (String.IsNullOrEmpty(answer)) { return(false); } answer = answer.ToLower(); if (answer == "rock") { move = Move.Rock; return(true); } else if (answer == "paper") { move = Move.Paper; return(true); } if (answer == "scissors") { move = Move.Scissors; return(true); } return(false); }
static void PlayGame(Player player1, Player player2) { var player1Color = ConsoleColor.Blue; var player2Color = ConsoleColor.Red; var oldColor = Console.ForegroundColor; Console.ForegroundColor = player1Color; Console.Write(player1.filename); Console.ForegroundColor = oldColor; Console.Write(" vs "); Console.ForegroundColor = player2Color; Console.Write(player2.filename); Console.WriteLine(); for (var game = 0; game < gamesPerRound; ++game) { player1.Capture(); player2.Capture(); if (debugPrint) { player1.pc.color = ConsoleColor.DarkGreen; player2.pc.color = ConsoleColor.DarkBlue; } player1.pc.Write($"RESET {player2.filename}"); player2.pc.Write($"RESET {player1.filename}"); for (var round = 0; round < numRounds; ++round) { var ans1 = player1.pc.Read(true).FirstOrDefault(s => R.TextMoveLegal(s)); var ans2 = player2.pc.Read(true).FirstOrDefault(s => R.TextMoveLegal(s)); player1.pc.Write(ans2); player2.pc.Write(ans1); var result = TallyScore(player1, player2, ans1, ans2); //Console.ForegroundColor = player1Color; //Console.Write(ans1); //Console.ForegroundColor = oldColor; //Console.Write(" vs "); //Console.ForegroundColor = player2Color; //Console.Write(ans2); //Console.ForegroundColor = oldColor; //Console.Write(" =>result: "); //if (result == Result.Player1Win) // Console.ForegroundColor = player1Color; //else if (result == Result.Player2Win) // Console.ForegroundColor = player2Color; //else // Console.ForegroundColor = tieColor; //Console.WriteLine(result); } player1.pc.Write("QUIT"); player2.pc.Write("QUIT"); } Console.ForegroundColor = oldColor; }