Example #1
0
 //clear board with dll
 public void upDateOutPut(CheckersBoard i_Board, Player i_PrevPlayer, Move i_PrevMove, Player i_CurrentPlayer, Boolean i_FirstMove)
 //if you recive no previus move it means first message format
 {
     if (i_FirstMove)
     {
         i_Board.printBoardToConsole();
         Console.WriteLine(i_CurrentPlayer.m_Name + "'s " + "turn:");
     }
     else
     {
         i_Board.printBoardToConsole();
         Console.WriteLine(i_PrevPlayer.m_Name + "'s move was (" + teamSign(i_PrevPlayer) + "):" + i_PrevMove.MoveToString());
         Console.WriteLine(i_CurrentPlayer.m_Name + "'s " + "Turn" + "(" + teamSign(i_CurrentPlayer) + "):");
     }
 }
Example #2
0
        public void startGame()
        {
            //create user interface
            UserInterface userInterface = new UserInterface();

            //welcome message
            userInterface.GameEntry();

            //initealize player
            String playerName = userInterface.getPlayerName();

            this.player1 = new Player(playerName, false, Soilder.Group.Black);

            //get board size
            int boardSize = userInterface.getSizeOfBoard();

            //set player two
            if (userInterface.isPlayer2Computer())
            {
                player2 = new Player("computer", true, Soilder.Group.White);
            }
            else
            {
                player2 = new Player(userInterface.getPlayerName(), false, Soilder.Group.White);
            }

            this.endtournemnetCondision = false;

            while (!endtournemnetCondision)
            {
                //start the board - needs to move to constractor
                this.playingBoard = new CheckersBoard(boardSize);
                playingBoard.InitWhiteTeam();
                playingBoard.InitBlackTeam();
                this.endGameCondision = false;
                this.turn             = player1;
                this.prevTurn         = player2;
                //start the game


                Move    PlayerMove = new Move();
                Boolean firstMove  = true;

                while (!endGameCondision)   //change to do while
                {
                    //print cuurent sqreen - first time move is empty
                    userInterface.upDateOutPut(playingBoard, prevTurn, previosMove, turn, firstMove);
                    firstMove = false;
                    Boolean     stopTheGame       = false; //in case the user wants to quit and can
                    List <Move> currentValidMoves = new List <Move>();
                    if (this.turn.m_Group == Soilder.Group.Black)
                    {
                        currentValidMoves = this.playingBoard.getAllVaildTeamMoves(playingBoard.m_BlackSoilders);
                    }
                    else
                    {
                        currentValidMoves = this.playingBoard.getAllVaildTeamMoves(playingBoard.m_WhiteSoilders);
                    }
                    //if the current player is a computer use AI class
                    if (turn.m_IsComputer)
                    {
                        PlayerMove = AI.GenerateRandomMove(currentValidMoves);
                    }
                    else
                    {
                        PlayerMove = userInterface.getValidMoveFromUser(currentValidMoves); //if user want out move is an empty move

                        while (userInterface.m_UserWantsToQuit)                             //uses a public flag to check -maybe we will need to change this
                        {
                            if (checkIfPlayerCanQuit(turn))                                 //a gamemaneger methode to calculate score
                            {
                                stopTheGame = true;
                                userInterface.m_UserWantsToQuit = false; //set the flag back to false for next game
                                break;
                            }
                            else
                            {
                                userInterface.notifyPlayer("You can not quit because you have more or the same number of points ");
                                userInterface.m_UserWantsToQuit = false; //set the flag back to false
                                PlayerMove = userInterface.getValidMoveFromUser(currentValidMoves);
                            }
                        }
                    }
                    if (stopTheGame)
                    {
                        break; //end the game and go to score calculation
                    }
                    //move with move or eat
                    if (PlayerMove.m_IsEatingMove)
                    {
                        playingBoard.Eat(PlayerMove);
                        //if last move has more eating moves if it does eat again
                        Boolean stillEating = true;
                        while (stillEating)
                        {
                            Soilder     eatingSoilder       = playingBoard.soilderAt(PlayerMove.m_To);
                            List <Move> PossibleEatingMoves = playingBoard.getVaildMoves(eatingSoilder);
                            if (PossibleEatingMoves.Count != 0)
                            {
                                if (PossibleEatingMoves.First().m_IsEatingMove)
                                {
                                    userInterface.upDateOutPut(playingBoard, turn, PlayerMove, turn, firstMove); //print the same turn
                                    PlayerMove = userInterface.getValidMoveFromUser(PossibleEatingMoves);
                                    playingBoard.Eat(PlayerMove);
                                }
                                else
                                {
                                    stillEating = false;
                                }
                            }
                            else
                            {
                                stillEating = false;
                            }
                        }
                    }
                    else
                    {
                        playingBoard.Move(PlayerMove);
                    }
                    //up date score
                    upDateScore();
                    //up date winning condision
                    upDateEndGameCondision();
                    //turn change
                    swapTurns(PlayerMove);
                }
                //game ended
                Player  winner = player1;
                Boolean teko   = false;
                if (player1.m_Score < player2.m_Score)
                {
                    winner = player2;
                }
                if (player1.m_Score == player2.m_Score)
                {
                    teko = true;
                }
                userInterface.endOfGame(player1, player2, winner, teko);

                //update overall score and ask user if he wants to continue
                upDateOverAllScore();  //this also resets game score
                if (!userInterface.wantAnotherGame())
                {
                    endtournemnetCondision = true;
                }
            }
            //end of over all game - send user final result and termenate program
            Player  bigWinner = player1;
            Boolean draw      = false;

            if (player1.m_OverAllScore < player2.m_OverAllScore)
            {
                bigWinner = player2;
            }
            if (player1.m_OverAllScore == player2.m_OverAllScore)
            {
                draw = true;
            }
            userInterface.endOftournament(player1, player2, bigWinner, draw);
            Console.WriteLine("press any key to exit");
            Console.Read();
        }