Exemplo n.º 1
0
        static void Main(string[] args)
        {
            #region instantiates classes needed
            MainMenu       menu        = new MainMenu();
            SplashScreen   splash      = new SplashScreen();
            Win            isItWin     = new Win();
            GameBoard      game        = new GameBoard();
            GameLogic      logic       = new GameLogic();
            PlayerOne      playerOne   = new PlayerOne();
            PlayerTwo      playerTwo   = new PlayerTwo();
            AiPlayer       aiPlayer    = new AiPlayer();
            GameBackGround background  = new GameBackGround();
            WatchReplay    watch       = new WatchReplay();
            LeaderBoard    leaderBoard = new LeaderBoard();
            GameRules      rules       = new GameRules();
            #endregion



            splash.DrawSplashScreen();

            #region draws menu and allows user to exit, pick game mode or watch replay
            while (menu.MenuSel != 7)
            {
                menu.Menu(game.GameBg);

                switch (menu.MenuSel)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine("\n\n\n\n\n                                            you have selected a 1 player game");
                    //adds objects to array
                    background.Objects(game.GameBg);
                    //gets players names
                    playerOne.GetPlayerName();
                    aiPlayer.GetPlayerName();
                    //draws game board
                    game.Draw(game.GameBg, playerOne, aiPlayer);
                    Console.Clear();
                    //loops through logic until win not true
                    while (logic.Win != true)
                    {
                        logic.Logic(game.GameBg, playerOne, aiPlayer, watch);
                    }
                    //when logic is true draws win screen
                    if (logic.Win == true)
                    {
                        Console.Clear();
                        isItWin.Winner();
                    }
                    //add player score to leaderboard
                    if (playerOne.PlayerScore > playerTwo.PlayerScore)
                    {
                        string score = playerOne.PlayerScore + ": " + playerOne.PlayerName;
                        leaderBoard.Leaderboard.Add(score);
                    }
                    else if (playerTwo.PlayerScore > playerOne.PlayerScore)
                    {
                        string score = playerTwo.PlayerScore + ": " + playerTwo.PlayerName;
                        leaderBoard.Leaderboard.Add(score);
                    }
                    Console.Clear();
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("                                                     you have selected a 2 player game");
                    //adds objects to game B array
                    background.Objects(game.GameBg);
                    //gets playerone one
                    playerOne.GetPlayerName();
                    //gets player two name
                    playerTwo.GetPlayerName(playerOne);
                    Console.Clear();
                    while (logic.Win != true)
                    {
                        logic.Logic(game.GameBg, playerOne, playerTwo, watch);
                    }

                    if (logic.Win == true)
                    {
                        Console.Clear();
                        isItWin.Winner();
                    }
                    Console.Clear();
                    break;

                case 3:
                    Console.WriteLine("                                                    you have chosen to watch the replay of the last game");
                    //starts replay
                    watch.Replay(game, playerOne, playerTwo);
                    break;

                case 4:
                    leaderBoard.SortedLeaderboard();
                    break;

                case 5:
                    rules.DisplayRules();
                    Console.Clear();
                    break;

                case 6:
                    Console.WriteLine("                                                    you have chosen to quit");
                    Environment.Exit(0);
                    break;
                }
                #endregion
            }
        }
Exemplo n.º 2
0
        public void Logic(string[,] gameBg, PlayerOne playerOne, PlayerTwo playerTwo, WatchReplay watchReplay)
        {
            //checks if there any checkers left on the board
            IsItWin(gameBg, playerOne, playerTwo);
            //adds first move to replay
            watchReplay.AddToQueue(gameBg);

            //checks if its players one turn
            if (playerOne.IsItMyTurn == true)
            {
                //draws the gameboard
                game.Draw(gameBg, playerOne, playerTwo);

                //sets pickIsValid and MoveIsValid
                valid.PickIsValid = false;
                valid.MoveIsValid = false;

                //checks if if a checkertaken is true and anothermove is false or Movecomplete is true and anotherMove is false... checks if the players turn has ended then passes to the next player
                if (detection.CheckerTaken == true && detection.AnotherMove == false || detection.MoveComplete == true && detection.AnotherMove == false)
                {
                    detection.CheckerTaken = false;
                    playerOne.YourTurn();
                    playerTwo.MyTurn();
                    game.Draw(gameBg, playerOne, playerTwo);
                }
                else
                {
                    Console.Clear();
                    game.Draw(gameBg, playerOne, playerTwo);
                    //checks if the player has anyforce moves to make
                    move.ForceJumpPlayerOne(gameBg);
                    //gets players move input
                    Console.WriteLine("\n\n{0} Enter the Row of the Checker you want to Move", playerOne.PlayerName.ToUpper());
                    pickRow = Console.ReadKey().KeyChar;
                    Console.WriteLine("\nEnter the Column of the Checker you want to Move");
                    pickCol = Console.ReadKey().KeyChar;
                    //checks if the player input is valid
                    valid.IsItValidFirstMove(gameBg, pickRow, pickCol, playerOne, playerTwo);
                }
                //checks if player pick row and column is valid
                if (playerOne.IsItMyTurn == true && valid.PickIsValid == true)
                {
                    detection.MoveComplete = false;

                    //checks if the force move list has any elements
                    if (move.MustPickRowAndCol.Count > 0)
                    {
                        int convertedPickCol = Convert.ToInt16(pickCol.ToString());

                        //checks if the player pick input is contained in the list
                        if (move.MustPickRowAndCol.Contains(pickRow.ToString() + convertedPickCol.ToString()) == true)
                        {
                            Console.WriteLine("\nEnter the Row you want to move to", playerOne.PlayerName);
                            moveRow = Console.ReadKey().KeyChar;
                            Console.WriteLine("\nEnter the Column you want to move to", playerOne.PlayerName);
                            moveCol = Console.ReadKey().KeyChar;
                            //checks if the player input is valid
                            valid.IsItValidSecondMove(moveRow, moveCol, valid.PickIsValid);
                        }
                        else
                        {
                            Console.WriteLine("\nyou must must pick one of the moves in the list above");
                            Console.ReadKey();
                        }
                    }
                    //checks if the list contains any values
                    else
                    {
                        Console.WriteLine("\nEnter the Row you want to move to", playerOne.PlayerName);
                        moveRow = Console.ReadKey().KeyChar;
                        Console.WriteLine("\nEnter the Column you want to move to", playerOne.PlayerName);
                        moveCol = Console.ReadKey().KeyChar;
                        //checks if the player input is valid
                        valid.IsItValidSecondMove(moveRow, moveCol, valid.PickIsValid);
                    }
                }

                //checks if playerOne and moveIsValid  is true
                if (playerOne.IsItMyTurn == true && valid.MoveIsValid == true)
                {
                    //checks if the list contains any values
                    if (move.MustMoveRowAndCol.Count > 0)
                    {
                        int convertedMoveCol = Convert.ToInt16(moveCol.ToString());

                        //checks if the players move input is contained in the list
                        if (move.MustMoveRowAndCol.Contains(moveRow.ToString() + convertedMoveCol.ToString()) == true)
                        {
                            Console.WriteLine("\n\nyou have elected to move\n    {0}{1}  To  {2}{3}", pickRow.ToString().ToUpper(), pickCol, moveRow.ToString().ToUpper(), moveCol);
                            Console.ReadKey();
                            //adds gameBg move to stack
                            undo.AddToUndoStack(gameBg);
                            //updates the gameboard
                            detection.CheckAndUpdate(gameBg, valid.ConvRow, valid.ConvCol, valid.NewConvRow, valid.NewConvCol, playerOne, playerTwo);
                            //adds gameBg move to Queue
                            watchReplay.AddToQueue(gameBg);
                            //adds gameBg to redo stack
                            undo.AddToRedoStack(gameBg);
                            //redraws the gameboard
                            game.Draw(gameBg, playerOne, playerTwo);
                            // adds one to turn count
                            playerOne.GetPlayerTurnCount();


                            //if the players move is complete and asks if they want to undo thier move
                            if (detection.AnotherMove == false && playerOne.PlayerTurnCount != 0)
                            {
                                undo.UndoPlayerMove(gameBg, playerOne, playerTwo);
                            }
                        }
                        //if the move is not in list shows error message
                        else
                        {
                            Console.WriteLine("you must select one of the moves above");
                            Console.ReadKey();
                            detection.MoveComplete = false;
                        }
                    }
                    else
                    {
                        Console.WriteLine("\n\nyou have elected to move\n    {0}{1}  To  {2}{3}", pickRow.ToString().ToUpper(), pickCol, moveRow.ToString().ToUpper(), moveCol);
                        Console.ReadKey();
                        //adds gameBg move to stack
                        undo.AddToUndoStack(gameBg);
                        //updates the gameboard
                        detection.CheckAndUpdate(gameBg, valid.ConvRow, valid.ConvCol, valid.NewConvRow, valid.NewConvCol, playerOne, playerTwo);
                        //adds gameBg move to Queue
                        watchReplay.AddToQueue(gameBg);
                        //adds gameBg to redo stack
                        undo.AddToRedoStack(gameBg);
                        // adds one to turn count
                        playerOne.GetPlayerTurnCount();
                        //redraws the gameboard
                        game.Draw(gameBg, playerOne, playerTwo);


                        //if the players move is complete and asks if they want to undo thier move
                        if (detection.AnotherMove == false && playerOne.PlayerTurnCount != 0)
                        {
                            undo.UndoPlayerMove(gameBg, playerOne, playerTwo);
                        }
                    }
                }
                else
                {
                    detection.MoveComplete = false;
                }
            }
            //checks if it's player twos turn
            else if (playerTwo.IsItMyTurn == true)
            {
                //redraws gameboard
                game.Draw(gameBg, playerOne, playerTwo);

                //set bools to false
                valid.PickIsValid = false;
                valid.MoveIsValid = false;

                //checks if if a checkertaken is true and anothermove is false or Movecomplete is true and anotherMove is false... checks if the players turn has ended then passes to the next player
                if (detection.CheckerTaken == true && detection.AnotherMove == false || detection.MoveComplete == true && detection.AnotherMove == false)
                {
                    detection.CheckerTaken = false;
                    playerTwo.YourTurn();
                    playerOne.MyTurn();
                    game.Draw(gameBg, playerOne, playerTwo);
                }
                else
                {
                    Console.Clear();
                    game.Draw(gameBg, playerOne, playerTwo);
                    //checks if player has any force move to complete
                    move.ForceJumpPlayerTwo(gameBg);
                    Console.WriteLine("\n\n{0} Enter the Row of the Checker you want to Move", playerTwo.PlayerName.ToUpper());
                    pickRow = Console.ReadKey().KeyChar;
                    Console.WriteLine("\nEnter the Column of the Checker you want to Move");
                    pickCol = Console.ReadKey().KeyChar;
                    //checks if player input is valid
                    valid.IsItValidFirstMove(gameBg, pickRow, pickCol, playerOne, playerTwo);
                }
                //checks if player two move and pickIsValid is true
                if (playerTwo.IsItMyTurn == true && valid.PickIsValid == true)
                {
                    detection.MoveComplete = false;

                    //checks if list contains any values
                    if (move.MustPickRowAndCol.Count > 0)
                    {
                        int convertedPickCol = Convert.ToInt16(pickCol.ToString());
                        //checks if the players move input is contained in the list
                        if (move.MustPickRowAndCol.Contains(pickRow.ToString() + convertedPickCol.ToString()) == true)
                        {
                            Console.WriteLine("\nEnter the Row you want to move to", playerTwo.PlayerName);
                            moveRow = Console.ReadKey().KeyChar;
                            Console.WriteLine("\nEnter the Column you want to move to", playerTwo.PlayerName);
                            moveCol = Console.ReadKey().KeyChar;
                            //checks if move is valid
                            valid.IsItValidSecondMove(moveRow, moveCol, valid.PickIsValid);
                        }
                        else
                        {
                            Console.WriteLine("\nyou must must pick one of the moves in the list above");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nEnter the Row you want to move to", playerTwo.PlayerName);
                        moveRow = Console.ReadKey().KeyChar;
                        Console.WriteLine("\nEnter the Column you want to move to", playerTwo.PlayerName);
                        moveCol = Console.ReadKey().KeyChar;
                        //checks if move is valid
                        valid.IsItValidSecondMove(moveRow, moveCol, valid.PickIsValid);
                    }
                }
                else
                {
                    detection.MoveComplete = false;
                }
                //checks if playerTwo and moveIsValid is true
                if (playerTwo.IsItMyTurn == true && valid.MoveIsValid == true)
                {
                    //checks if list contains any values
                    if (move.MustMoveRowAndCol.Count > 0)
                    {
                        int convertedMoveCol = Convert.ToInt16(moveCol.ToString());
                        //checks if player input matchs the list
                        if (move.MustMoveRowAndCol.Contains(moveRow.ToString() + convertedMoveCol.ToString()) == true)
                        {
                            Console.WriteLine("\n\nyou have elected to move\n    {0}{1}  To  {2}{3}", pickRow.ToString().ToUpper(), pickCol, moveRow.ToString().ToUpper(), moveCol);
                            Console.ReadKey();
                            //adds gameBg move to stack
                            undo.AddToUndoStack(gameBg);
                            //updates the gameboard
                            detection.CheckAndUpdate(gameBg, valid.ConvRow, valid.ConvCol, valid.NewConvRow, valid.NewConvCol, playerOne, playerTwo);
                            //adds gameBg move to Queue
                            watchReplay.AddToQueue(gameBg);
                            //adds gameBg to redo stack
                            undo.AddToRedoStack(gameBg);
                            //adds one to turn count
                            playerTwo.GetPlayerTurnCount();
                            //redraws the gameboard
                            game.Draw(gameBg, playerOne, playerTwo);

                            //checks if move completed and asks if they want to undo thier move
                            if (detection.AnotherMove == false && playerOne.PlayerTurnCount != 0)
                            {
                                undo.UndoPlayerMove(gameBg, playerOne, playerTwo);
                            }
                        }
                        else
                        {
                            Console.WriteLine("you must select one of the moves above");
                            Console.ReadKey();
                            detection.MoveComplete = false;
                        }
                    }
                    else
                    {
                        Console.WriteLine("\n\nyou have elected to move\n    {0}{1}  To  {2}{3}", pickRow.ToString().ToUpper(), pickCol, moveRow.ToString().ToUpper(), moveCol);
                        Console.ReadKey();
                        //adds gameBg move to stack
                        undo.AddToUndoStack(gameBg);
                        //updates the gameboard
                        detection.CheckAndUpdate(gameBg, valid.ConvRow, valid.ConvCol, valid.NewConvRow, valid.NewConvCol, playerOne, playerTwo);
                        //adds gameBg move to Queue
                        watchReplay.AddToQueue(gameBg);
                        //adds gameBg to redo stack
                        undo.AddToRedoStack(gameBg);
                        //adds one to turn count
                        playerTwo.GetPlayerTurnCount();
                        //redraws the gameboard
                        game.Draw(gameBg, playerOne, playerTwo);

                        //checks if move completed and asks if they want to undo thier move
                        if (detection.AnotherMove == false && playerOne.PlayerTurnCount != 0)
                        {
                            undo.UndoPlayerMove(gameBg, playerOne, playerTwo);
                        }
                    }
                }
            }
        }