Exemplo n.º 1
0
        private string Postfix(string prefix)
        {
            var result = new StringBuilder(prefix);

            result.Append(TileDirectionUtil.GetChar(Direction));
            return(result.ToString());
        }
Exemplo n.º 2
0
        public void Turn(TurnDirection turn)
        {
            switch (turn)
            {
            case TurnDirection.Left:
                Direction = TileDirectionUtil.TurnLeft(Direction);
                break;

            case TurnDirection.Right:
                Direction = TileDirectionUtil.TurnRight(Direction);
                break;
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static Tile MakeTile(Board board, string tileString, int x, int y)
        {
            Tile result;

            // the first character is the Concrete Tile
            switch (tileString[0])
            {
            case 'F':
                result = new Floor(board, x, y);
                break;

            case 'P':
                result = new Pit(board, x, y);
                break;

            default:
                return(null);
            }

            //All following characters are Decorator Tiles
            var i = 1;

            while (i < tileString.Length)
            {
                int number;
                var turnString = "12345";
                switch (tileString[i])
                {
                case 'C':     // Conveyor Belt
                    result = new ConveyorBelt(board, result, TileDirectionUtil.Get(tileString[++i]),
                                              TurnDirectionUtil.Get(tileString[++i]), x, y);
                    break;

                case 'E':     // Express Conveyor Belt
                    result = new ExpressConveyorBelt(board, result, TileDirectionUtil.Get(tileString[++i]),
                                                     TurnDirectionUtil.Get(tileString[++i]), x, y);
                    break;

                case 'F':     // Flag
                    number = Convert.ToInt32(tileString[++i].ToString());
                    if (number >= 1 && number <= 8)
                    {
                        result = new Flag(board, result, number, x, y);
                    }
                    break;

                case 'G':     // Gear
                    result = new Gear(board, result, TurnDirectionUtil.Get(tileString[++i]), x, y);
                    break;

                case 'L':     // Laser
                    number = Convert.ToInt32(tileString[++i].ToString());
                    if (number >= 1 && number <= 3)
                    {
                        result = new Laser(board, result, number, x, y);
                    }
                    break;

                case 'P':     // Pusher
                    var turns     = new bool[5];
                    var direction = TileDirectionUtil.Get(tileString[++i]);
                    while (i < tileString.Length - 1 && turnString.Contains(tileString[i + 1].ToString()))
                    {
                        turns[Convert.ToInt32(tileString[++i].ToString()) - 1] = true;
                    }
                    result = new Pusher(board, result, direction, turns, x, y);
                    break;

                case 'R':     // Repair
                    result = new Repair(board, result, x, y);
                    break;

                case 'S':     // Spawnpoint
                    number = Convert.ToInt32(tileString[++i].ToString());
                    if (number >= 1 && number <= 8)
                    {
                        result = new SpawnPoint(board, result, number, x, y);
                    }
                    break;

                case 'W':     // Wall
                    result = new Wall(board, result, TileDirectionUtil.Get(tileString[++i]), x, y);
                    break;
                }
                i++;
            }
            return(result);
        }