Example #1
0
 private void MoveAIOnce(AI ai)
 {
     MoveAIOnce(ai, ai.Direction);
 }
Example #2
0
        internal void ExecuteProgramCard(AI ai, ProgramCard card)
        {
            switch (card.CardAction)
            {
                case ProgramCardAction.RotateLeft:
                    ai.Direction = TileDirectionUtil.TurnLeft(ai.Direction);
                    break;

                case ProgramCardAction.RotateRight:
                    ai.Direction = TileDirectionUtil.TurnRight(ai.Direction);
                    break;

                case ProgramCardAction.UTurn:
                    ai.Direction = TileDirectionUtil.Opposite(ai.Direction);
                    break;

                case ProgramCardAction.Move1:
                    MoveAIOnce(ai);
                    break;

                case ProgramCardAction.Move2:
                    MoveAIOnce(ai);
                    MoveAIOnce(ai);
                    break;

                case ProgramCardAction.Move3:
                    MoveAIOnce(ai);
                    MoveAIOnce(ai);
                    MoveAIOnce(ai);
                    break;

                case ProgramCardAction.BackUp:
                    MoveAIOnce(ai, TileDirectionUtil.Opposite(ai.Direction));
                    break;
            }
        }
Example #3
0
        internal void MoveAIOnce(AI ai, TileDirection direction)
        {
            if (direction != TileDirection.None)
            {
                var toX = ai.X;
                var toY = ai.Y;

                switch (direction)
                {
                    case TileDirection.Up:
                        toY--;
                        break;

                    case TileDirection.Down:
                        toY++;
                        break;

                    case TileDirection.Left:
                        toX--;
                        break;

                    case TileDirection.Right:
                        toX++;
                        break;
                }

                //Check if movement is off the board
                if (toX < 0 || toY < 0 || toX >= Width || toY >= Height)
                {
                    if (!this[ai.X, ai.Y].HasWall(direction))
                    {
                        ai.Die();
                    }
                }
                else
                {
                    //Check if movement is blocked by walls
                    if (!this[ai.X, ai.Y].HasWall(ai.Direction) &&
                        !this[toX, toY].HasWall(TileDirectionUtil.Opposite(direction)))
                    {
                        //Check if movement is into a Pit
                        if (this[toX, toY].IsPit())
                        {
                            ai.X = toX;
                            ai.Y = toY;
                            ai.Die();
                        }
                        else
                        {
                            //Check if an AI is already on the new Tile
                            if (this[toX, toY].HasAI() != null)
                            {
                                //Move the AI on the new Tile (if not possible the AI stays)
                                //MoveAIOnce(this[toX, toY].HasAI(), direction);
                                //If the other AI moved, move this AI
                                if (this[toX, toY].HasAI() == null)
                                {
                                    ai.X = toX;
                                    ai.Y = toY;
                                }
                            }
                            else
                            {
                                //When there are no problems, just move the AI
                                ai.X = toX;
                                ai.Y = toY;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
 private void SetWinner(AI ai)
 {
     winner = ai;
     finished = true;
 }