Beispiel #1
0
        public override void UpdateState()
        {
            ConstantDisplay();

            int confirmVal;

            AppState state = this;

            string input = Input.GetLine();

            switch (input)
            {
            case "c":
                Confirm(out confirmVal);

                // choose to cancel the current turn
                if (confirmVal == 1)
                {
                    m_game.GetManager().CancelTurn();
                    state = new StartPlay(m_game, 0);
                    state.UpdateState();
                }
                else
                {
                    UpdateState();
                }
                break;

            default:
                int    select;
                string testS = input;

                // check if input can be parsed and if the input is within the range of moves
                if (int.TryParse(input, out select))
                {
                    select--;
                    if (0 <= select && select < m_moves.Count)
                    {
                        // conducts the move selected (this method also checks for possible attack if the move was an attack
                        m_game.GetManager().ConductTurn(m_moves[select]);

                        List <Move> moves;

                        // if there is an attack available then the unit that just attacked will be available
                        // meaning they now have the option to make another move(attack)
                        if (m_game.GetManager().CellsAble.Count > 0)
                        {
                            moves = m_game.GetManager().GetMovesOfCell(m_game.GetManager().CellsAble[0]);

                            m_game.GetManager().AddCurrentMoment();

                            state = new SelectMove(m_game, moves);
                            state.UpdateState();
                        }
                        else
                        {
                            m_game.GetManager().FinishTurn();

                            m_game.CheckIfComplete();

                            state = new StartPlay(m_game, 0);
                            state.UpdateState();
                        }
                    }
                    else
                    {
                        m_errorTxt = "Invalid Selection!";
                        UpdateState();
                    }
                }
                else
                {
                    m_errorTxt = "Is not a number!";
                    UpdateState();
                }
                break;
            }
        }
Beispiel #2
0
        public override void UpdateState()
        {
            Console.Clear();
            Console.WriteLine("Crazy Draughts");

            Console.WriteLine("\n" + m_winnerTxt);

            Console.WriteLine("\nStart New Game: ng");
            Console.WriteLine("Load Game: lg");
            Console.WriteLine("Exit: e");
            Console.WriteLine("\nPlease choose action: ");

            int confirmVal = 0;

            // choose option specified above (e.g. Start New Game = ng)
            switch (Input.GetLine())
            {
            case "ng":
                Confirm(out confirmVal);

                if (confirmVal == 1)
                {
                    Console.WriteLine("\nFight against AI? y/n");

                    Game     game;
                    AppState state = this;

                    // decide if game willbe versus an AI
                    switch (Input.GetLine())
                    {
                    case "y":
                        game             = new Game(true);
                        Program.lastGame = game;

                        state = new StartPlay(game, 1);
                        state.UpdateState();
                        break;

                    case "n":
                        game             = new Game(false);
                        Program.lastGame = game;

                        state = new StartPlay(game, 1);
                        state.UpdateState();
                        break;

                    default:
                        UpdateState();
                        break;
                    }
                }
                else
                {
                    // regress back to start of state
                    UpdateState();
                }
                break;

            case "lg":
                Confirm(out confirmVal);

                if (confirmVal == 1)
                {
                    Console.WriteLine("\nPlease enter the game you want to load! [enter game number]");

                    string input = Input.GetLine();

                    int val;
                    int.TryParse(input, out val);
                    val -= 1;

                    if (val < Program.games.Count && val >= 0 && Program.games.Count > 0)
                    {
                        AppState state = this;
                        state = new StartPlay(val);
                        state.UpdateState();
                    }
                    else
                    {
                        Console.WriteLine("\nThis game does not exist! Press enter to continue...");
                        Input.GetLine();
                        UpdateState();
                    }
                }
                else
                {
                    // regress back to start of state
                    UpdateState();
                }
                break;

            case "e":
                Confirm(out confirmVal);

                // confirm if you want to exit the game
                if (confirmVal == 1)
                {
                    Environment.Exit(0);
                }
                else
                {
                    // regress back to start of state
                    UpdateState();
                }
                break;

            default:
                // invalid input results in regression back to start of state
                UpdateState();
                break;
            }
        }
Beispiel #3
0
        public override void UpdateState()
        {
            ConstantDisplay();

            int confirmVal;

            AppState state = this;

            string input = Input.GetLine();

            switch (input)
            {
            case "c":
                Confirm(out confirmVal);

                if (confirmVal == 1)
                {
                    // cancels the turn being taken (allows you to select different piece if possible)
                    m_game.GetManager().CancelTurn();
                    state = new StartPlay(m_game, 0);
                    state.UpdateState();
                }
                else
                {
                    UpdateState();
                }
                break;

            default:
                if (input.Length >= 3)
                {
                    // parses the x component of the cell you entered
                    int    x;
                    string testX = "" + input[0];
                    if (!int.TryParse(testX, out x))
                    {
                        // regress if value cannot parse
                        UpdateState();
                    }

                    int y = m_game.GetManager().Board.ConvertYAxisToInt(input[2]);

                    if (m_game.GetManager().IsCoordsOnBoard(new Coord(x, y)) && m_game.GetManager().CellsAble.Contains(m_game.GetManager().Board.Cells[x, y]))
                    {
                        List <Move> moves = m_game.GetManager().GetMovesOfCell(m_game.GetManager().Board.Cells[x, y]);

                        // ensure that you can only go to SelectMove state if a move is available otherwise finish turn
                        if (moves.Count >= 0)
                        {
                            state = new SelectMove(m_game, moves);
                            state.UpdateState();
                        }
                        else
                        {
                            m_game.GetManager().FinishTurn();

                            state = new StartPlay(m_game, 0);
                            state.UpdateState();
                        }
                    }
                    else
                    {
                        // if input is invalid then regress
                        m_game.GetManager().CancelTurn();
                        UpdateState();
                    }
                }
                else
                {
                    UpdateState();
                }
                break;
            }
        }