Beispiel #1
0
        private static void playerMoveView(Player i_ThePlayerIsTurn)
        {
            bool isExit = false;

            if (s_LastMoveStr != null)
            {
                if (s_MoreEating)
                {
                    Console.WriteLine(s_Game.PlayerTurn.Name + " Move's was " + "(" + s_Game.PlayerTurn.SignOfPlayer + "): " + s_LastMoveStr);
                    s_MoreEating = false;
                }
                else
                {
                    Console.WriteLine(s_Game.GetOpponent(s_Game.PlayerTurn).Name + " Move's was " + "(" + s_Game.GetOpponent(s_Game.PlayerTurn).SignOfPlayer + "): " + s_LastMoveStr);
                }
            }

            Console.WriteLine(i_ThePlayerIsTurn.Name + "'s Turn " + "(" + s_Game.PlayerTurn.SignOfPlayer + "):");
            Console.WriteLine();
            Console.WriteLine("Press Q to quit");
            string      MoveStrFromUser;
            bool        checkIfReadGood;
            e_EatStatus theMoveIsEating = e_EatStatus.EATISNOTPOSSIBLE;

            if (s_NumOfPlayers == 1 && i_ThePlayerIsTurn.ID == e_PlayerID.SECOND)
            {
                MoveStrFromUser = i_ThePlayerIsTurn.GetRandomMoveAsStr();
                if (MoveStrFromUser == string.Empty)
                {
                    // no more move for computer player.
                    Console.WriteLine("No more moves. the turn move the the Enemy player.");
                }
            }
            else
            {
                do
                {
                    checkIfReadGood = true;
                    theMoveIsEating = e_EatStatus.EATISNOTPOSSIBLE;
                    MoveStrFromUser = Console.ReadLine();

                    if (MoveStrFromUser.Equals("Q"))
                    {
                        s_Game.IsQuited = true;
                        i_ThePlayerIsTurn.Quit();
                        ////s_Game.PlayerQuited(i_ThePlayerIsTurn.ID);
                        isExit          = true;
                        checkIfReadGood = true;
                    }

                    if (!isExit)
                    {
                        if (MoveStrFromUser.Length != 5 ||
                            MoveStrFromUser[0] < 'A' || MoveStrFromUser[0] > (char)(BoardSize + (int)'A' - 1) ||
                            MoveStrFromUser[1] < 'a' || MoveStrFromUser[1] > (char)(BoardSize + (int)'a' - 1) ||
                            MoveStrFromUser[2] != '>' ||
                            MoveStrFromUser[3] < 'A' || MoveStrFromUser[3] > (char)(BoardSize + (int)'A' - 1) ||
                            MoveStrFromUser[4] < 'a' || MoveStrFromUser[4] > (char)(BoardSize + (int)'a' - 1) ||
                            (!i_ThePlayerIsTurn.isValidMove(Board, (int)MoveStrFromUser[0] - (int)'A', (int)MoveStrFromUser[1] - (int)'a', (int)MoveStrFromUser[3] - 'A', (int)MoveStrFromUser[4] - 'a')))
                        {
                            checkIfReadGood = false;
                            Console.WriteLine("Invalid move, try again:");
                        }
                        else
                        {
                            theMoveIsEating = i_ThePlayerIsTurn.GetTheEatableStatusOfMove(MoveStrFromUser);
                            if (theMoveIsEating == e_EatStatus.EATISPOSSIBALEBUTNOTDONE)
                            {
                                checkIfReadGood = false;
                                Console.WriteLine("You can't move if you don't 'eat' your opponent piece:");
                            }
                        }
                    }
                }while (!checkIfReadGood);
                ////i_ThePlayerIsTurn.
                ////we need to call func in model to check if the move is good and move the soldier in board.
                ////and in thr fun to call to PrintBoard after the soldier moved.
            }

            if (!isExit)
            {
                i_ThePlayerIsTurn.movePiece(Board, (int)MoveStrFromUser[0] - (int)'A', (int)MoveStrFromUser[1] - (int)'a', (int)MoveStrFromUser[3] - 'A', (int)MoveStrFromUser[4] - 'a');
                if (!(theMoveIsEating == e_EatStatus.EAT && i_ThePlayerIsTurn.ChecksIfThereAreAnyEatableInStright(MoveStrFromUser)))
                {
                    s_Game.PlayerTurn = s_Game.GetOpponent(i_ThePlayerIsTurn);
                }
                else
                {
                    s_MoreEating = true;
                }

                s_LastMoveStr = MoveStrFromUser;
                PrintBoard();
            }
        }