Exemplo n.º 1
0
        /// <summary>
        /// The main method to see who won - the computer or the player. This is Where the magic happens
        /// </summary>
        private void GameEngine()
        {
            // What the computer "selected":
            Random Computer = new Random();
            int    rnd      = Computer.Next(1, 4); // 1 meaning rock, 2 - paper, 3 - scissors

            // What the player selected:
            playa.Clear();
            playa.TotalGames++;
            if (rockCheck.Checked)
            {
                playa.Rock = true;
                // even steven
                if (rnd == 1)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "Even",
                        PlayerImage   = @"Images\rock.jpg",
                        ComputerImage = @"Images\rock.jpg"
                    };
                    rs.Show();
                }
                // computer wins
                else if (rnd == 2)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "You Lost!",
                        PlayerImage   = @"Images\rock.jpg",
                        ComputerImage = @"Images\paper.jpg"
                    };
                    rs.Show();
                    playa.LostGames++;
                    playa.RockTotal++;
                    playa.Streak = 0;
                    CalcWinrates();
                }

                // player win
                else if (rnd == 3)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "You Won!",
                        PlayerImage   = @"Images\rock.jpg",
                        ComputerImage = @"Images\scissors.jpg"
                    };
                    rs.Show();
                    playa.WonGames++;
                    playa.Streak++;
                    playa.RockWon++;
                    playa.RockTotal++;
                    CalcWinrates();
                }
            }
            else if (paperCheck.Checked)
            {
                playa.Paper = true;
                // Player wins:
                if (rnd == 1)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "You Won!",
                        PlayerImage   = @"Images\paper.jpg",
                        ComputerImage = @"Images\rock.jpg"
                    };
                    rs.Show();
                    playa.WonGames++;
                    playa.Streak++;
                    playa.PaperWon++;
                    playa.PaperTotal++;
                    CalcWinrates();
                }
                // Even steven
                else if (rnd == 2)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "Even",
                        PlayerImage   = @"Images\paper.jpg",
                        ComputerImage = @"Images\paper.jpg"
                    };
                    rs.Show();
                }

                // Computer wins
                else if (rnd == 3)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "You Lost!",
                        PlayerImage   = @"Images\paper.jpg",
                        ComputerImage = @"Images\scissors.jpg"
                    };
                    rs.Show();
                    playa.LostGames++;
                    playa.Streak = 0;
                    playa.PaperTotal++;
                    CalcWinrates();
                }
            }
            else if (scissorsCheck.Checked)
            {
                playa.Scissors = true;
                // Computer wins
                if (rnd == 1)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "You Lost!",
                        PlayerImage   = @"Images\scissors.jpg",
                        ComputerImage = @"Images\rock.jpg"
                    };
                    rs.Show();
                    playa.LostGames++;
                    playa.Streak = 0;
                    playa.ScissorsTotal++;
                    CalcWinrates();
                }
                // Player wins
                else if (rnd == 2)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "You Won!",
                        PlayerImage   = @"Images\scissors.jpg",
                        ComputerImage = @"Images\paper.jpg"
                    };
                    rs.Show();
                    playa.WonGames++;
                    playa.Streak++;
                    playa.ScissorsWon++;
                    playa.ScissorsTotal++;
                    CalcWinrates();
                }

                // Even steven
                else if (rnd == 3)
                {
                    ResultScreen rs = new ResultScreen
                    {
                        ResultLabel   = "Even",
                        PlayerImage   = @"Images\scissors.jpg",
                        ComputerImage = @"Images\scissors.jpg"
                    };
                    rs.Show();
                }
            }

            rockCheck.CheckState     = CheckState.Unchecked;
            paperCheck.CheckState    = CheckState.Unchecked;
            scissorsCheck.CheckState = CheckState.Unchecked;


            RenewLabels();
        }