Example #1
0
    public static GamesRecord operator +(GamesRecord a, GamesRecord b)
    {
        int displayRecordIndex;

        if (b.gamesRecordCurrentSize < b.gamesRecordSize)
        {
            displayRecordIndex = 0;
        }
        else
        {
            displayRecordIndex = b.gamesRecordCurrentIndex;
        }

        if (a.gamesRecordCurrentSize + b.gamesRecordCurrentSize > a.gamesRecordSize)
        {
            GamesRecord Ap = new GamesRecord(a.gamesRecordCurrentSize + b.gamesRecordCurrentSize);
            for (int i = 0; i < a.gamesRecordCurrentSize; i++)
            {
                Ap.AddRecord(a.gamesRecord[i, 0],
                             a.gamesRecord[i, 1],
                             a.gamesRecord[i, 2]);
            }
            Ap.gamesRecordCurrentIndex = a.gamesRecordCurrentIndex;
            Ap.gamesRecordCurrentSize  = a.gamesRecordCurrentSize;
            a = Ap;
        }
        for (int i = 0; i < b.gamesRecordCurrentSize; i++)
        {
            a.AddRecord(b.gamesRecord[displayRecordIndex, 0],
                        b.gamesRecord[displayRecordIndex, 1],
                        b.gamesRecord[displayRecordIndex, 2]);
            displayRecordIndex = (displayRecordIndex + 1) % b.gamesRecordCurrentSize;
        }
        return(a);
    }
Example #2
0
 public Game()
 {
     gamesRecord = new GamesRecord(10);
     playerOne   = new Player();
     playerTwo   = new Player();
     MainMenuLoop();
 }
Example #3
0
 public Game(int inputGamesRecordSize = 10)
 {
     playerOne   = new Player();
     playerTwo   = new Player();
     gamesRecord = new GamesRecord(inputGamesRecordSize);
     MainMenuLoop();
 }
Example #4
0
    public void MainMenuLoop()
    {
        // Declare the variable used for input
        ConsoleKeyInfo inputKey;

        // Control the effect of input to call a proper function
        do
        {
            // Clear the console
            Clear();
            // Write the menu message
            WriteLine("Game Menu - Current game [{0}]:\n[1] Player vs Player\n[2] Player vs AI\n[3] Show rules\n[4] Display last games' record\n[5] Change game\n[ESC] Exit", gameType[currentGameTypeIndex]);
            inputKey = ReadKey(true);
            if (inputKey.Key == ConsoleKey.D1)
            {
                if (gameType[currentGameTypeIndex] == "RPS")
                {
                    game = new GameRPS();
                }
                else if (gameType[currentGameTypeIndex] == "MyNewGame")
                {
                    game = new GameMyGame();
                }

                else
                {
                    throw new ArgumentException("No such game");
                }
                game.Play();
                gamesRecord += game.gamesRecord;
            }
            else if (inputKey.Key == ConsoleKey.D2)
            {
                game = new GameRPS(true);
                game.Play();
                gamesRecord += game.gamesRecord;
            }
            else if (inputKey.Key == ConsoleKey.D3)
            {
                DisplayRules(game, false); // false to not display the "Welcome.." part
            }
            else if (inputKey.Key == ConsoleKey.D4)
            {
                gamesRecord.DisplayGamesHistory();
            }
            else if (inputKey.Key == ConsoleKey.D5)
            {
                currentGameTypeIndex = (currentGameTypeIndex + 1) % gameType.Length;
                continue;
            }
            else
            {
                continue;
            }
            WriteLine("(click any key to continue)");
            ReadKey(true);
        } while (inputKey.Key != ConsoleKey.Escape);
    }
    public Game(int inputGamesRecordSize = 10)
    {
        playerOne   = new Player();
        playerTwo   = new Player();
        gamesRecord = new GamesRecord(inputGamesRecordSize);

        bool AI = chooseGameFormat();

        MainMenuLoop(AI);
    }
Example #6
0
        public Game(bool singleplayer = false)
        {
            playerOne = new Player();

            if (singleplayer)
            {
                playerTwo = new AIPlayer();
            }
            else
            {
                playerTwo = new Player();
            }
            gamesRecord = new GamesRecord();
        }
Example #7
0
    public GameMyGame(bool singleplayer = false)
    {
        GameName   = "Moja Gra";
        GameRules  = "Zasady gry...Rzut kością- gracz z największą liczbą wygrywa.";
        inputTable = new Dictionary <string, string>()
        {
            { "1", "Roll" }
        };
        while (true)
        {
            try
            {
                playerOne = new Player();
            }
            catch (Exception e)
            {
                continue;
            }
            break;
        }

        while (true)
        {
            try
            {
                if (singleplayer)
                {
                    playerTwo = new AIPlayer();
                }
                else
                {
                    playerTwo = new Player();
                }
            }
            catch (Exception e)
            {
                continue;
            }
            break;
        }


        gamesRecord = new GamesRecord();

        random = new Random();
    }
Example #8
0
        public void MainMenuLoop()//bool AI)
        {
            ConsoleKeyInfo inputKey;

            do
            {
                Console.Clear();
                Console.WriteLine("Rock-Paper-Scissors Menu:\n\t[1] Play vs human\n\t[2] Play vs robot\n\t[3] Show rules\n\t[4] Display last games' record\n\t[ESC] Exit");
                inputKey = Console.ReadKey(true);

                if (inputKey.Key == ConsoleKey.D1)
                {
                    game = new Game();
                    game.Play();// AI);
                    gamesRecord += game.gamesRecord;
                }
                else if (inputKey.Key == ConsoleKey.D2)
                {
                    game = new Game(true);
                    game.Play();// AI);
                    gamesRecord += game.gamesRecord;
                }
                else if (inputKey.Key == ConsoleKey.D3)
                {
                    game.DisplayRules(false);
                }
                else if (inputKey.Key == ConsoleKey.D4)
                {
                    gamesRecord.DisplayGamesHistory();
                }
                else
                {
                    continue;
                }

                Console.WriteLine("(click any key to continue)");
                Console.ReadKey(true);
            } while (inputKey.Key != ConsoleKey.Escape);
        }
Example #9
0
    public GameRPS(bool singleplayer = false)
    {
        GameName  = "Rock-Paper-Scissors";
        GameRules = "The rules are very simple - each player chooses Rock, Paper or Scissors choice by entering the choice's number\n[1] Rock\n[2] Paper\n[3] Scissors\nand confirm it by clicking Enter.\nAfter both player choose, the winner is determined. After each game the application will ask the players if they want to continue, and if the player repond with anything else than [y]es than the game finishes and presents the record of the last up to 10 games.\n\nHave fun!";


        inputTable = new Dictionary <string, string>()
        {
            { "1", "Rock" },
            { "2", "Paper" },
            { "3", "Scissors" }
        };
        playerOne = new Player();
        if (singleplayer)
        {
            playerTwo = new AIPlayer();
        }
        else
        {
            playerTwo = new Player();
        }
        gamesRecord = new GamesRecord();
    }
Example #10
0
 public GameController()
 {
     gamesRecord = new GamesRecord();
 }