Ejemplo n.º 1
0
        /// <summary>
        /// Do things with robots and tiles
        /// </summary>
        /// <param name="robot">The robot that sent the data</param>
        /// <param name="data">The data</param>
        private void DoRobotyStuff(Autobot robot, string data)
        {
            switch (data[1])
            {
            case '0':
                ArrayHelper tileStraight = new ArrayHelper(tiles.Images[1], TileType.STRAIGHT);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileStraight.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    //Orientation is relative to the default position of the tile as depicted in the images
                    tileStraight.TileOrientation = Orientation.EAST;
                    tileStraight.AddDirections(new List <string> {
                        "up", "down"
                    });
                    break;

                case Orientation.EAST:
                    tileStraight.TileOrientation = Orientation.NORTH;
                    tileStraight.AddDirections(new List <string> {
                        "left", "right"
                    });
                    break;

                case Orientation.SOUTH:
                    tileStraight.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileStraight.TileOrientation = Orientation.EAST;
                    tileStraight.AddDirections(new List <string> {
                        "up", "down"
                    });
                    break;

                case Orientation.WEST:
                    tileStraight.TileOrientation = Orientation.NORTH;
                    tileStraight.AddDirections(new List <string> {
                        "left", "right"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileStraight, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '1':
                ArrayHelper tileTLeft = new ArrayHelper(tiles.Images[3], TileType.TTILE);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileTLeft.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileTLeft.TileOrientation = Orientation.EAST;
                    tileTLeft.AddDirections(new List <string> {
                        "up", "left", "down"
                    });
                    break;

                case Orientation.EAST:
                    tileTLeft.TileImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    tileTLeft.TileOrientation = Orientation.SOUTH;
                    tileTLeft.AddDirections(new List <string> {
                        "left", "right", "up"
                    });
                    break;

                case Orientation.SOUTH:
                    tileTLeft.TileImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    tileTLeft.TileOrientation = Orientation.WEST;
                    tileTLeft.AddDirections(new List <string> {
                        "up", "down", "right"
                    });
                    break;

                case Orientation.WEST:
                    tileTLeft.TileOrientation = Orientation.NORTH;
                    tileTLeft.AddDirections(new List <string> {
                        "left", "right", "down"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileTLeft, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '2':
                ArrayHelper tileTRight = new ArrayHelper(tiles.Images[3], TileType.TTILE);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileTRight.TileImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    tileTRight.TileOrientation = Orientation.WEST;
                    tileTRight.AddDirections(new List <string> {
                        "up", "right", "down"
                    });
                    break;

                case Orientation.EAST:
                    tileTRight.TileOrientation = Orientation.NORTH;
                    tileTRight.AddDirections(new List <string> {
                        "left", "right", "down"
                    });
                    break;

                case Orientation.SOUTH:
                    tileTRight.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileTRight.TileOrientation = Orientation.EAST;
                    tileTRight.AddDirections(new List <string> {
                        "up", "left", "down"
                    });
                    break;

                case Orientation.WEST:
                    tileTRight.TileImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    tileTRight.TileOrientation = Orientation.SOUTH;
                    tileTRight.AddDirections(new List <string> {
                        "left", "right", "up"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileTRight, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '3':
                ArrayHelper tileX = new ArrayHelper(tiles.Images[4], TileType.XTILE);
                tileX.TileOrientation = Orientation.NORTH;
                tileX.AddDirections(new List <string> {
                    "left", "right", "down", "up"
                });
                UpdateRobotArray(robot, tileX, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '4':
                ArrayHelper tileCornerLeft = new ArrayHelper(tiles.Images[2], TileType.CORNER);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileCornerLeft.TileImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    tileCornerLeft.TileOrientation = Orientation.SOUTH;
                    tileCornerLeft.AddDirections(new List <string> {
                        "left", "down"
                    });
                    break;

                case Orientation.EAST:
                    tileCornerLeft.TileImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    tileCornerLeft.TileOrientation = Orientation.WEST;
                    tileCornerLeft.AddDirections(new List <string> {
                        "left", "up"
                    });
                    break;

                case Orientation.SOUTH:
                    tileCornerLeft.TileOrientation = Orientation.NORTH;
                    tileCornerLeft.AddDirections(new List <string> {
                        "up", "right"
                    });
                    break;

                case Orientation.WEST:
                    tileCornerLeft.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileCornerLeft.TileOrientation = Orientation.EAST;
                    tileCornerLeft.AddDirections(new List <string> {
                        "right", "down"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileCornerLeft, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '5':
                ArrayHelper tileCornerRight = new ArrayHelper(tiles.Images[2], TileType.CORNER);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileCornerRight.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileCornerRight.TileOrientation = Orientation.EAST;
                    tileCornerRight.AddDirections(new List <string> {
                        "right", "down"
                    });
                    break;

                case Orientation.EAST:
                    tileCornerRight.TileImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    tileCornerRight.TileOrientation = Orientation.SOUTH;
                    tileCornerRight.AddDirections(new List <string> {
                        "left", "down"
                    });
                    break;

                case Orientation.SOUTH:
                    tileCornerRight.TileImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    tileCornerRight.TileOrientation = Orientation.WEST;
                    tileCornerRight.AddDirections(new List <string> {
                        "left", "up"
                    });
                    break;

                case Orientation.WEST:
                    tileCornerRight.TileOrientation = Orientation.NORTH;
                    tileCornerRight.AddDirections(new List <string> {
                        "up", "right"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileCornerRight, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '6':
                ArrayHelper tileT = new ArrayHelper(tiles.Images[3], TileType.TTILE);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileT.TileOrientation = Orientation.NORTH;
                    tileT.AddDirections(new List <string> {
                        "left", "right", "down"
                    });
                    break;

                case Orientation.EAST:
                    tileT.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileT.TileOrientation = Orientation.EAST;
                    tileT.AddDirections(new List <string> {
                        "left", "up", "down"
                    });
                    break;

                case Orientation.SOUTH:
                    tileT.TileImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    tileT.TileOrientation = Orientation.SOUTH;
                    tileT.AddDirections(new List <string> {
                        "left", "right", "up"
                    });
                    break;

                case Orientation.WEST:
                    tileT.TileImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    tileT.TileOrientation = Orientation.WEST;
                    tileT.AddDirections(new List <string> {
                        "up", "right", "down"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileT, data);
                UpdateRobotOrientation(robot, data);
                break;

            case '7':
                ArrayHelper tileDeadEnd = new ArrayHelper(tiles.Images[0], TileType.DEADEND);
                switch (robot.Orientation)
                {
                case Orientation.NORTH:
                    tileDeadEnd.TileOrientation = Orientation.NORTH;
                    tileDeadEnd.AddDirections(new List <string> {
                        "down"
                    });
                    break;

                case Orientation.EAST:
                    tileDeadEnd.TileImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    tileDeadEnd.TileOrientation = Orientation.EAST;
                    tileDeadEnd.AddDirections(new List <string> {
                        "left"
                    });
                    break;

                case Orientation.SOUTH:
                    tileDeadEnd.TileImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    tileDeadEnd.TileOrientation = Orientation.SOUTH;
                    tileDeadEnd.AddDirections(new List <string> {
                        "up"
                    });
                    break;

                case Orientation.WEST:
                    tileDeadEnd.TileImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    tileDeadEnd.TileOrientation = Orientation.WEST;
                    tileDeadEnd.AddDirections(new List <string> {
                        "right"
                    });
                    break;
                }
                UpdateRobotArray(robot, tileDeadEnd, data);
                UpdateRobotOrientation(robot, data);
                break;
            }
        }