Example #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;
            }
        }
Example #2
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;
            }
        }