public HandSign GetAIHandSign(int AIHandSign)
        {

            int ChosenHandSign =AIHandSign;
            switch (ChosenHandSign)
            {
                case 0:
                    Rock rock = new Rock("Rock");
                    return rock;
                case 1:
                    Paper paper = new Paper("Paper");
                    return paper;
                case 2:
                    Scissors scissors = new Scissors("Scissors");
                    return scissors;
                case 3:
                    Lizard lizard = new Lizard("Lizard");
                    return lizard;
                case 4:
                    Spock spock = new Spock("Spock");
                    return spock;
                default:
                    return GetUserInputHandSign();
            }
        }
        public HandSign GetUserInputHandSign()
        {

            string ChosenHandSign = null;
            Console.WriteLine("What hand sign do you want to choose Rock, Paper, Scissors, Lizard, or Spock?");
            ChosenHandSign = Console.ReadLine();
            switch (ChosenHandSign)
            {
                case "Rock":
                    Rock rock = new Rock("Rock");
                    return rock;
                case "Paper":
                    Paper paper = new Paper("Paper");
                    return paper;
                case "Scissors":
                    Scissors scissors = new Scissors("Scissors");
                    return scissors;
                case "Lizard":
                    Lizard lizard = new Lizard("Lizard");
                    return lizard;
                case "Spock":
                    Spock spock = new Spock("Spock");
                    return spock;
                default:
                    return GetUserInputHandSign();
            }
        }
        private static void PlayGame()
        {
            PrintLineBreak();

            gamesCounter++;
            Console.WriteLine(roundString);

            Hand userHand       = new Hand();
            bool incorrectInput = true;

            while (incorrectInput)
            {
                string userInput = Console.ReadLine().ToLower();

                if (userInput == "p")
                {
                    playerPaperCounter++;
                    userHand       = new Paper();
                    incorrectInput = false;
                }
                else if (userInput == "s")
                {
                    playerScissorsCounter++;
                    userHand       = new Scissors();
                    incorrectInput = false;
                }
                else if (userInput == "r")
                {
                    playerRockCounter++;
                    userHand       = new Rock();
                    incorrectInput = false;
                }
                else
                {
                    PrintIncorrectCommand();
                }
            }

            Console.WriteLine("Player selected hand: " + FirstLetterToUpper(userHand.value));

            Hand compHand = ReturnRandomHand();

            Console.WriteLine("Computer selected hand: " + FirstLetterToUpper(compHand.value));

            Hand winningHand = CompareTwoHands(userHand, compHand);

            string winningValue;
            string winner = "";

            if (winningHand == null)
            {
                drawCounter++;
                Console.WriteLine("Draw!");
                winner = "Draw";
            }
            else if (winningHand.value == userHand.value && winningHand.value != compHand.value)
            {
                winningValue = FirstLetterToUpper(winningHand.value);
                winCounter++;
                Console.WriteLine("Winning value: " + winningValue);
                Console.WriteLine("You won!");
                winner = "Player";
            }
            else if (winningHand.value == compHand.value && winningHand.value != userHand.value)
            {
                winningValue = FirstLetterToUpper(winningHand.value);
                loseCounter++;
                Console.WriteLine("Winning value: " + winningValue);
                Console.WriteLine("You lost!");
                winner = "CPU";
            }
            else
            {
                Console.WriteLine("Error!");
            }

            new GameRecord(winner, userHand, compHand);

            PrintLineBreak();

            ShowMainMenu();
        }
Exemple #4
0
        public void VsComputer()
        {
            display = new Display();
            player = new Player();
            ai = new AI("AI");
            rock = new Rock("Rock");
            paper = new Paper("Paper");
            scissors = new Scissors("Scissors");
            bool gameActive = true;

            while (gameActive == true)
            {
                display.OutputToFile("ScoresVsAI.txt");
                Console.WriteLine("New game? yes/no");
                string userContinue = Console.ReadLine().ToLower();
                Console.Clear();
                display.DisplayScoreBoardVsAI();

                if (userContinue == "no")
                {
                    display.OutputToFile("ScoresVsAI.txt");
                    break;
                }

                if (userContinue == "yes")
                {
                    ai.AITurn();
                    player.Player1Input();
                    Console.WriteLine(Environment.NewLine);

                    //rock
                    if (ai.aiChoice == "rock")
                    {
                        if (player.player1Choice == "rock")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            Console.WriteLine("It is a tie.\r\n");
                        }
                        else if (player.player1Choice == "paper")
                        {
                            display.player1Score++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            paper.DisplayWin(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("You win!\r\n");
                        }
                        else if (player.player1Choice == "scissors")
                        {
                            display.aiScore++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            scissors.DisplayLoss(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("{0} wins!\r\n",ai.Name);
                        }
                        else
                        {
                            Console.WriteLine("You must choose Rock, Paper, or Scissors!\r\n");
                        }

                    }
                    //paper
                    else if (ai.aiChoice == "paper")
                    {
                        if (player.player1Choice == "rock")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            rock.DisplayLoss(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("{0} wins!\r\n",ai.Name);
                            display.aiScore++;
                        }
                        else if (player.player1Choice == "paper")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, paper.Name);
                            Console.WriteLine("It is a tie\r\n");                            

                        }
                        else if (player.player1Choice == "scissors")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, paper.Name);
                            scissors.DisplayWin(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("You win!\r\n");
                            display.player1Score++;

                        }
                        else
                        {
                            Console.WriteLine("You must choose Rock, Paper, or Scissors!\r\n");
                        }
                    }

                    //scissors
                    else if (ai.aiChoice == "scissors")
                    {
                        if (player.player1Choice == "rock")
                        {
                            //ai scissors, you rock = win
                            display.player1Score++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, scissors.Name);
                            rock.DisplayWin(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("You win!\r\n");
                        }
                        else if (player.player1Choice == "paper")
                        {
                            //ai scissors, you paper = lose
                            display.aiScore++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, scissors.Name);
                            paper.DisplayLoss(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("{0} wins!\r\n", ai.Name);
                        
                        }
                        else if (player.player1Choice == "scissors")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, scissors.Name);
                            Console.WriteLine("It is a tie\r\n");
                        }
                        else
                        {
                            Console.WriteLine("You must choose Rock, Paper, or Scissors!\r\n");
                        }

                    }
                }
            }
        }
        static void Main(string[] args)
        {
            bool playAgain = true;

            Rock rock = new Rock();
            rock.rockRules();
            Paper paper = new Paper();
            paper.paperRules();
            Scissors scissors = new Scissors();
            scissors.scissorsRules();
            Lizard lizard = new Lizard();
            lizard.lizardRules();
            Spock spock = new Spock();
            spock.spockRules();

            prompts startGame = new prompts();
            startGame.startGame();

                    multiPlayerOptions multiPlayerOptions = new multiPlayerOptions();
                    int selectedPlayers = multiPlayerOptions.setPlayers();

                if (selectedPlayers == 2)
                {
                    playerNames playerNames = new playerNames();
                    string playerOneName = playerNames.playerOneName();
                    string playerTwoName = playerNames.playerTwoName();

                    while (playAgain)
                    {
                    playerOneTurn playerOneChoice = new playerOneTurn();
                    string result1 = playerOneChoice.goPlayerOne(playerOneName);

                    playerTwoTurn playerTwoChoice = new playerTwoTurn();
                    string result2 = playerTwoChoice.goPlayerTwo(playerTwoName);

                    results results = new results();
                    results.gameResults(result1, result2, playerOneName, playerTwoName);

                    Console.WriteLine("Do you want to play again?(y/n)");
                    string loop = Console.ReadLine();
                    if (loop == "y")
                    {
                        playAgain = true;
                        
                    }
                    else if (loop == "n")
                    {
                        playAgain = false;
                    }
                    else
                    {

                    }

                }

                }
                else
                {
                    playerNames playerNames = new playerNames();
                    string playerOneName = playerNames.playerOneName();
                    string cpuName = playerNames.cpuName();

                    while (playAgain)
                    {
                    playerOneTurn playerOneChoice = new playerOneTurn();
                    string result1 = playerOneChoice.goPlayerOne(playerOneName);

                    cpuChoice cpuChoice = new cpuChoice();
                    string result2 = cpuChoice.randomChoice();

                    results results = new results();
                    results.gameResults(result1, result2, playerOneName, cpuName);

                    Console.WriteLine("Do you want to play again?(y/n)");
                    string loop = Console.ReadLine();
                    if (loop == "y")
                    {
                        playAgain = true;
                        Console.Clear();
                    }
                    else if (loop == "n")
                    {
                        playAgain = false;
                    }
                    else
                    {

                    }
                }
                }

        }