コード例 #1
0
ファイル: TileOrientation.cs プロジェクト: Zabanya/SharpFlame
        public TileOrientation GetRotated(TileOrientation Orientation)
        {
            TileOrientation ReturnResult = new TileOrientation();

            ReturnResult.SwitchedAxes = SwitchedAxes ^ Orientation.SwitchedAxes;

            if ( Orientation.SwitchedAxes )
            {
                if ( Orientation.ResultXFlip )
                {
                    ReturnResult.ResultXFlip = !ResultYFlip;
                }
                else
                {
                    ReturnResult.ResultXFlip = ResultYFlip;
                }
                if ( Orientation.ResultYFlip )
                {
                    ReturnResult.ResultYFlip = !ResultXFlip;
                }
                else
                {
                    ReturnResult.ResultYFlip = ResultXFlip;
                }
            }
            else
            {
                if ( Orientation.ResultXFlip )
                {
                    ReturnResult.ResultXFlip = !ResultXFlip;
                }
                else
                {
                    ReturnResult.ResultXFlip = ResultXFlip;
                }
                if ( Orientation.ResultYFlip )
                {
                    ReturnResult.ResultYFlip = !ResultYFlip;
                }
                else
                {
                    ReturnResult.ResultYFlip = ResultYFlip;
                }
            }

            return ReturnResult;
        }
コード例 #2
0
ファイル: TileDirection.cs プロジェクト: Zabanya/SharpFlame
        public TileDirection GetRotated(TileOrientation Orientation)
        {
            var returnResult = new TileDirection();

            if ( Orientation.SwitchedAxes )
            {
                if ( Orientation.ResultXFlip )
                {
                    returnResult.X = (byte)(2 - Y);
                }
                else
                {
                    returnResult.X = Y;
                }
                if ( Orientation.ResultYFlip )
                {
                    returnResult.Y = (byte)(2 - X);
                }
                else
                {
                    returnResult.Y = X;
                }
            }
            else
            {
                if ( Orientation.ResultXFlip )
                {
                    returnResult.X = (byte)(2 - X);
                }
                else
                {
                    returnResult.X = X;
                }
                if ( Orientation.ResultYFlip )
                {
                    returnResult.Y = (byte)(2 - Y);
                }
                else
                {
                    returnResult.Y = Y;
                }
            }

            return returnResult;
        }
        public static ArrayTileOrientation ToArrayTileOrientation(this TileOrientation orientation)
        {
            ArrayTileOrientation arrayOrientation;

            switch (orientation)
            {
            case TileOrientation.TiltLeft:
            case TileOrientation.TiltRight:
            case TileOrientation.Flipped:
                arrayOrientation = ArrayTileOrientation.TopDown;
                break;

            case TileOrientation.Straight:
            case TileOrientation.DoubleTiltLeft:
            case TileOrientation.DoubleTiltRight:
            default:
                arrayOrientation = ArrayTileOrientation.BottomUp;
                break;
            }

            return(arrayOrientation);
        }
コード例 #4
0
        /// <summary>
        /// Checks if a tile can placed on the GameBoard, based on the tiles orientation,
        /// and another tile next to which the new tile should be placed
        /// </summary>
        /// <param name="tile">The tile which should be placed</param>
        /// <param name="otherName">The name of the other tile.</param>
        /// <param name="otherFace">The face of the other tile at which the new tile should be placed.</param>
        /// <returns>True, if the new tile can be placed, false if not.</returns>
        public bool CanPlaceTileOnGameBoard(string tileName, string otherName, TileFace?tileFace, TileFace?otherFace, out TriominoTile placableTile)
        {
            placableTile = null;

            // if it's the first tile it can always be placed.
            if (this.NumbTilesOnBoard == 0)
            {
                placableTile = new TriominoTile(tileName, TileOrientation.Straight, new Point(this.maxGameBoardSize / 2, this.maxGameBoardSize / 2));
                return(true);
            }

            // otherFace and otherName can only be null if it's the first tile
            if (otherFace == null || otherName == null || otherName == string.Empty)
            {
                return(false);
            }

            Point otherTileGridCoordinates   = this.GetTileCoordsByName(otherName);
            Point possibleNewGridCoordinates = this.GetTileGridPositionFromOtherTilePositionAndFace(otherTileGridCoordinates, otherFace.Value);

            if (possibleNewGridCoordinates.Y == -1 || possibleNewGridCoordinates.X == -1)
            {
                return(false);
            }

            TileOrientation tileOrientation = GameBoard.GetTileOrienationFromOtherTileOrientationAndFaces(this.GetTileFromGrid(otherTileGridCoordinates).Orientation, otherFace.Value, tileFace.Value);
            TriominoTile    tile            = new TriominoTile(tileName, tileOrientation, possibleNewGridCoordinates);

            // If Tile values can be placed it will be returned
            if (this.CheckValueGridAtTileGridPosition(tile))
            {
                placableTile = tile;
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: Tile.cs プロジェクト: JohnAkerman/Graven
        public Tile(TileType typeIn, int xIn, int yIn, int totalWidthIn, int totalHeightIn, Random rand, TileCollision collision, int decoration = -1)
        {
            tileType = typeIn;
            size.X = size.Y = 16;
            position = new Vector2(xIn * size.X, yIn * size.Y);
            render = true;
            decorationValue = decoration;
            tileOrientation = TileOrientation.Regular;
            totalHeight = totalHeightIn;
            totalWidth = totalWidthIn;
            tileCollision = collision;

            if (tileType == TileType.Dirt)
            {
                hitsRequired = 1;
                if (rand.Next(1, 25) == 5)
                {
                    //damage = rand.Next(1, 3);
                    //  health = damage * 30;
                }
            }
            else if (tileType == TileType.Metal)
                hitsRequired = 5;
        }
コード例 #6
0
        public void Rotate(TileOrientation Orientation, Util.ObjectRotateMode ObjectRotateMode)
        {
            var X                  = 0;
            var Y                  = 0;
            var Pos                = new XYInt(0, 0);
            var RotatedPos         = new XYInt();
            var NewTerrainPosA     = TileUtil.GetRotatedPos(Orientation, new XYInt(0, 0), Terrain.TileSize);
            var NewTerrainPosB     = TileUtil.GetRotatedPos(Orientation, Terrain.TileSize, Terrain.TileSize);
            var VertexLimits       = new XYInt(Math.Max(NewTerrainPosA.X, NewTerrainPosB.X), Math.Max(NewTerrainPosA.Y, NewTerrainPosB.Y));
            var NewTerrain         = new clsTerrain(VertexLimits);
            var NewTileLimits      = new XYInt(NewTerrain.TileSize.X - 1, NewTerrain.TileSize.Y - 1);
            var NewSideHLimits     = new XYInt(NewTerrain.TileSize.X - 1, NewTerrain.TileSize.Y);
            var NewSideVLimits     = new XYInt(NewTerrain.TileSize.X, NewTerrain.TileSize.Y - 1);
            var OldTileLimits      = new XYInt(Terrain.TileSize.X - 1, Terrain.TileSize.Y - 1);
            var OldPosLimits       = new XYInt(Terrain.TileSize.X * Constants.TerrainGridSpacing, Terrain.TileSize.Y * Constants.TerrainGridSpacing);
            var ReverseOrientation = new TileOrientation();
            var TriDirection       = new TileDirection();

            ReverseOrientation = Orientation;
            ReverseOrientation.Reverse();

            for (Y = 0; Y <= NewTerrain.TileSize.Y; Y++)
            {
                Pos.Y = Y;
                for (X = 0; X <= NewTerrain.TileSize.X; X++)
                {
                    Pos.X      = X;
                    RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, VertexLimits);
                    NewTerrain.Vertices[X, Y].Height  = Terrain.Vertices[RotatedPos.X, RotatedPos.Y].Height;
                    NewTerrain.Vertices[X, Y].Terrain = Terrain.Vertices[RotatedPos.X, RotatedPos.Y].Terrain;
                }
            }
            for (Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++)
            {
                Pos.Y = Y;
                for (X = 0; X <= NewTerrain.TileSize.X - 1; X++)
                {
                    Pos.X      = X;
                    RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewTileLimits);
                    NewTerrain.Tiles[X, Y].Texture             = Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Texture;
                    NewTerrain.Tiles[X, Y].Texture.Orientation = NewTerrain.Tiles[X, Y].Texture.Orientation.GetRotated(Orientation);
                    NewTerrain.Tiles[X, Y].DownSide            = Terrain.Tiles[RotatedPos.X, RotatedPos.Y].DownSide;
                    NewTerrain.Tiles[X, Y].DownSide            = NewTerrain.Tiles[X, Y].DownSide.GetRotated(Orientation);
                    if (Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Tri)
                    {
                        TriDirection = TileUtil.TopLeft;
                    }
                    else
                    {
                        TriDirection = TileUtil.TopRight;
                    }
                    TriDirection = TriDirection.GetRotated(Orientation);
                    NewTerrain.Tiles[X, Y].Tri =
                        Convert.ToBoolean(TileUtil.IdenticalTileDirections(TriDirection, TileUtil.TopLeft) ||
                                          TileUtil.IdenticalTileDirections(TriDirection, TileUtil.BottomRight));
                    if (Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Tri)
                    {
                        if (Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriTopLeftIsCliff)
                        {
                            TileUtil.RotateDirection(TileUtil.TopLeft, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                        if (Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriBottomRightIsCliff)
                        {
                            TileUtil.RotateDirection(TileUtil.BottomRight, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                    }
                    else
                    {
                        if (Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriTopRightIsCliff)
                        {
                            TileUtil.RotateDirection(TileUtil.TopRight, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                        if (Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriBottomLeftIsCliff)
                        {
                            TileUtil.RotateDirection(TileUtil.BottomLeft, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                    }
                    NewTerrain.Tiles[X, Y].Terrain_IsCliff = Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Terrain_IsCliff;
                }
            }
            if (Orientation.SwitchedAxes)
            {
                for (Y = 0; Y <= NewTerrain.TileSize.Y; Y++)
                {
                    Pos.Y = Y;
                    for (X = 0; X <= NewTerrain.TileSize.X - 1; X++)
                    {
                        Pos.X      = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideHLimits);
                        NewTerrain.SideH[X, Y].Road = Terrain.SideV[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
                for (Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++)
                {
                    Pos.Y = Y;
                    for (X = 0; X <= NewTerrain.TileSize.X; X++)
                    {
                        Pos.X      = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideVLimits);
                        NewTerrain.SideV[X, Y].Road = Terrain.SideH[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
            }
            else
            {
                for (Y = 0; Y <= NewTerrain.TileSize.Y; Y++)
                {
                    Pos.Y = Y;
                    for (X = 0; X <= NewTerrain.TileSize.X - 1; X++)
                    {
                        Pos.X      = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideHLimits);
                        NewTerrain.SideH[X, Y].Road = Terrain.SideH[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
                for (Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++)
                {
                    Pos.Y = Y;
                    for (X = 0; X <= NewTerrain.TileSize.X; X++)
                    {
                        Pos.X      = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideVLimits);
                        NewTerrain.SideV[X, Y].Road = Terrain.SideV[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
            }

            var Unit = default(Unit);

            foreach (var tempLoopVar_Unit in Units)
            {
                Unit = tempLoopVar_Unit;
                Unit.Sectors.Clear();
                if (ObjectRotateMode == Util.ObjectRotateMode.All)
                {
                    Unit.Rotation = (MathUtil.AngleClamp(MathUtil.RadOf360Deg -
                                                         TileUtil.GetRotatedAngle(Orientation,
                                                                                  MathUtil.AngleClamp(MathUtil.RadOf360Deg - Unit.Rotation * MathUtil.RadOf1Deg))) / MathUtil.RadOf1Deg).ToInt();
                    if (Unit.Rotation < 0)
                    {
                        Unit.Rotation += 360;
                    }
                }
                else if (ObjectRotateMode == ObjectRotateMode.Walls)
                {
                    if (Unit.TypeBase.Type == UnitType.PlayerStructure)
                    {
                        if (((StructureTypeBase)Unit.TypeBase).StructureType == StructureType.Wall)
                        {
                            Unit.Rotation = (MathUtil.AngleClamp(MathUtil.RadOf360Deg -
                                                                 TileUtil.GetRotatedAngle(Orientation,
                                                                                          MathUtil.AngleClamp(MathUtil.RadOf360Deg - Unit.Rotation * MathUtil.RadOf1Deg))) / MathUtil.RadOf1Deg)
                                            .ToInt();

                            if (Unit.Rotation < 0)
                            {
                                Unit.Rotation += 360;
                            }
                            //If Unit.Rotation = 180 Then
                            //    Unit.Rotation = 0
                            //ElseIf Unit.Rotation = 270 Then
                            //    Unit.Rotation = 90
                            //End If
                        }
                    }
                }
                Unit.Pos.Horizontal = TileUtil.GetRotatedPos(Orientation, Unit.Pos.Horizontal, OldPosLimits);
            }

            var ZeroPos = new XYInt(0, 0);

            var Position = 0;

            foreach (var tempLoopVar_Unit in Units.GetItemsAsSimpleList())
            {
                Unit = tempLoopVar_Unit;
                if (!App.PosIsWithinTileArea(Unit.Pos.Horizontal, ZeroPos, NewTerrain.TileSize))
                {
                    Position = Unit.MapLink.ArrayPosition;
                    UnitRemove(Position);
                }
            }

            Terrain = NewTerrain;

            var Gateway = default(Gateway);

            foreach (var tempLoopVar_Gateway in Gateways.GetItemsAsSimpleClassList())
            {
                Gateway = tempLoopVar_Gateway;
                GatewayCreate(TileUtil.GetRotatedPos(Orientation, Gateway.PosA, OldTileLimits),
                              TileUtil.GetRotatedPos(Orientation, Gateway.PosB, OldTileLimits));
                Gateway.Deallocate();
            }

            if (readyForUserInput)
            {
                CancelUserInput();
                InitializeUserInput();
            }
        }
コード例 #7
0
        /// <summary>
        /// Performs tile placement.
        /// </summary>
        /// <param name="color">Color of the player making the move.</param>
        /// <param name="scheme">Scheme of the tile.</param>
        /// <param name="coords">Coordinates of the tile.</param>
        /// <param name="orientation">Orientation of the tile.</param>
        private void PlaceTile(PlayerColor color, TileScheme scheme, Coords coords, TileOrientation orientation)
        {
            // Place the tile
            TileRectangle newRectangle = new TileRectangle();

            newRectangle.SetLayout(scheme, orientation);

            Canvas.SetLeft(newRectangle, coords.X * 100);
            Canvas.SetTop(newRectangle, coords.Y * 100);

            newRectangle.Coords = coords;

            TilesCanvas.Children.Add(newRectangle);

            PlacedTiles.Add(coords, newRectangle);

            // Remove empty tile and create new
            if (EmptyTiles.ContainsKey(coords))
            {
                TilesCanvas.Children.Remove(EmptyTiles[coords]);
                EmptyTiles.Remove(coords);
            }

            foreach (var or in new TileOrienationEnumerator())
            {
                var neigh = coords.GetNeighbouringCoords(or);

                if (!PlacedTiles.ContainsKey(neigh) && !EmptyTiles.ContainsKey(neigh))
                {
                    var emptyTile = new EmptyTileRectangle(neigh);
                    emptyTile.MouseClick += EmptyTile_MouseClick;
                    EmptyTiles.Add(neigh, emptyTile);

                    Canvas.SetLeft(emptyTile, neigh.X * 100);
                    Canvas.SetTop(emptyTile, neigh.Y * 100);

                    emptyTile.Visibility = Visibility.Collapsed;

                    TilesCanvas.Children.Add(emptyTile);
                }

                PassMoveBtn.IsEnabled = true;
            }

            CurrentCoords = coords;

            // If player is on move
            if (CurrentOnMove == PlayerColor)
            {
                // Activate the tile to be clicked on (placing follower)
                newRectangle.RegionMouseEventEnabled = true;
                newRectangle.RegionMouseClick       += PlacedTile_RegionMouseClick;

                // Deactivate empty tiles
                foreach (var et in EmptyTiles.Values)
                {
                    et.MouseEventEnabled = false;
                    et.Visibility        = Visibility.Collapsed;
                }

                // Activate the tiles with followers
                foreach (var c in PlacedFollowerPositions)
                {
                    PlacedTiles[c].FollowerMouseEventEnabled = true;
                }
            }
        }
コード例 #8
0
        public void SetImageElementToGrid()
        {
            SlideDirection   slideDirection   = TempProfile.SlideDirection.Value;
            TileOrientation  orientaition     = TempProfile.TileOrientation.Value;
            TileOrigin       origin           = TempProfile.TileOrigin.Value;
            TileImageStretch tileImageStretch = TempProfile.TileImageStretch.Value;

            int numofRow = MainGrid.RowDefinitions.Count;
            int numofCol = MainGrid.ColumnDefinitions.Count;

            // スライド方向から自動で配置を決定する場合
            if (TempProfile.UseDefaultTileOrigin.Value)
            {
                switch (slideDirection)
                {
                default:
                case SlideDirection.Left:
                    orientaition = TileOrientation.Vertical;
                    origin       = TileOrigin.TopLeft;
                    break;

                case SlideDirection.Top:
                    orientaition = TileOrientation.Horizontal;
                    origin       = TileOrigin.TopLeft;
                    break;

                case SlideDirection.Right:
                    orientaition = TileOrientation.Vertical;
                    origin       = TileOrigin.TopRight;
                    break;

                case SlideDirection.Bottom:
                    orientaition = TileOrientation.Horizontal;
                    origin       = TileOrigin.BottomRight;
                    break;
                }
            }

            Action <int, int> setToGrid = (i, j) =>
            {
                // Image
                Image image = new Image();

                if (tileImageStretch == TileImageStretch.UniformToFill)
                {
                    image.Stretch             = Stretch.UniformToFill;
                    image.HorizontalAlignment = HorizontalAlignment.Center;
                    image.VerticalAlignment   = VerticalAlignment.Center;
                }
                else if (tileImageStretch == TileImageStretch.Fill)
                {
                    image.Stretch = Stretch.Fill;
                }

                // Border
                Border border = new Border();
                border.Background = new SolidColorBrush(Colors.Transparent); // Border内部の空白をクリック時にヒットテスト可能にするため
                int tilePadding = TempProfile.TilePadding.Value;
                if (tilePadding != 0)
                {
                    border.BorderThickness = new Thickness(tilePadding + 2);
                    border.Margin          = new Thickness(-2); // これと↑の-2は隣のGridとの境目を完全に消すため
                }
                border.BorderBrush = new SolidColorBrush(TempProfile.GridLineColor.Value);
                border.Child       = image;

                // セット
                MainGrid.Children.Add(border);
                Grid.SetRow(border, i);
                Grid.SetColumn(border, j);
            };

            if (orientaition == TileOrientation.Horizontal)
            {
                switch (origin)
                {
                default:
                case TileOrigin.TopLeft:
                    for (int i = 0; i < numofRow; i++)
                    {
                        for (int j = 0; j < numofCol; j++)
                        {
                            setToGrid(i, j);
                        }
                    }
                    break;

                case TileOrigin.TopRight:
                    for (int i = 0; i < numofRow; i++)
                    {
                        for (int j = numofCol - 1; j >= 0; j--)
                        {
                            setToGrid(i, j);
                        }
                    }
                    break;

                case TileOrigin.BottomRight:
                    for (int i = numofRow - 1; i >= 0; i--)
                    {
                        for (int j = numofCol - 1; j >= 0; j--)
                        {
                            setToGrid(i, j);
                        }
                    }
                    break;

                case TileOrigin.BottomLeft:
                    for (int i = numofRow - 1; i >= 0; i--)
                    {
                        for (int j = 0; j < numofCol; j++)
                        {
                            setToGrid(i, j);
                        }
                    }
                    break;
                }
            }
            else
            {
                switch (origin)
                {
                default:
                case TileOrigin.TopLeft:
                    for (int i = 0; i < numofCol; i++)
                    {
                        for (int j = 0; j < numofRow; j++)
                        {
                            setToGrid(j, i);
                        }
                    }
                    break;

                case TileOrigin.TopRight:
                    for (int i = numofCol - 1; i >= 0; i--)
                    {
                        for (int j = 0; j < numofRow; j++)
                        {
                            setToGrid(j, i);
                        }
                    }
                    break;

                case TileOrigin.BottomRight:
                    for (int i = numofCol - 1; i >= 0; i--)
                    {
                        for (int j = numofRow - 1; j >= 0; j--)
                        {
                            setToGrid(j, i);
                        }
                    }
                    break;

                case TileOrigin.BottomLeft:
                    for (int i = 0; i < numofCol; i++)
                    {
                        for (int j = numofRow - 1; j >= 0; j--)
                        {
                            setToGrid(j, i);
                        }
                    }
                    break;
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// Tells player that tile is placed.
 /// </summary>
 /// <param name="color">Color of the player making the move.</param>
 /// <param name="tile">Scheme of tile that was placed.</param>
 /// <param name="coordinates">Coodrinates of the placed tile.</param>
 /// <param name="orientation">Orientation of the placed tile.</param>
 public void PlaceTile(PlayerColor color, TileScheme tile, Coords coordinates, TileOrientation orientation)
 {
     _Executor.PlaceTile(color, tile, coordinates, orientation);
 }
コード例 #10
0
        /// <summary>
        /// Determines the orientation of a Tile, which should be placed on the GameBoard, based on another 
        /// tiles orientation, and the faces with which both tiles should be aligned towards each other.
        /// </summary>
        /// <param name="otherOrientation">Other tiles orientation.</param>
        /// <param name="otherFace">Other tiles face.</param>
        /// <param name="tileFace">New tiles face.</param>
        /// <returns>the orientation of the new tile.</returns>
        private TileOrientation GetTileOrienationFromOtherTileOrientationAndFaces(TileOrientation otherOrientation, TileFace otherFace, TileFace tileFace)
        {
            if ((otherOrientation == TileOrientation.Straight && otherFace == TileFace.Left && tileFace == TileFace.Left) ||
                (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Right && tileFace == TileFace.Right) ||
                (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) ||
                (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Bottom) ||
                (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Left) ||
                (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Right) ||
                (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Left && tileFace == TileFace.Right) ||
                (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Right && tileFace == TileFace.Bottom) ||
                (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Left))
            {
                return TileOrientation.Flipped;
            }
            else if ((otherOrientation == TileOrientation.Straight && otherFace == TileFace.Left && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Right && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Bottom && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Left && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Right && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Right))
            {
                return TileOrientation.TiltRight;
            }
            else if ((otherOrientation == TileOrientation.Straight && otherFace == TileFace.Left && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Right && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.Straight && otherFace == TileFace.Bottom && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.DoubleTiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Left && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Right && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.DoubleTiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom))
            {
                return TileOrientation.TiltLeft;
            }
            else if ((otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Left && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Right && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Bottom && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Left && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Right && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Left))
            {
                return TileOrientation.DoubleTiltRight;
            }
            else if ((otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Left && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Right && tileFace == TileFace.Right) ||
                     (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Left && tileFace == TileFace.Bottom) ||
                     (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Right && tileFace == TileFace.Left) ||
                     (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Right))
            {
                return TileOrientation.Straight;
            }
            else if((otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Left && tileFace == TileFace.Bottom) ||
                    (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Right && tileFace == TileFace.Left) ||
                    (otherOrientation == TileOrientation.TiltLeft && otherFace == TileFace.Bottom && tileFace == TileFace.Right) ||
                    (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Left && tileFace == TileFace.Right) ||
                    (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Right && tileFace == TileFace.Bottom) ||
                    (otherOrientation == TileOrientation.Flipped && otherFace == TileFace.Bottom && tileFace == TileFace.Left) ||
                    (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Left && tileFace == TileFace.Left) ||
                    (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Right && tileFace == TileFace.Right) ||
                    (otherOrientation == TileOrientation.TiltRight && otherFace == TileFace.Bottom && tileFace == TileFace.Bottom))
            {
                return TileOrientation.DoubleTiltLeft;
            }

            throw new ArgumentException("The combination TileOrientation, TileFace, TileFace cannot be determined");
        }
コード例 #11
0
        /// <summary>
        /// /// Adds a new Edge to this graph, if it isn't already part of it.
        /// </summary>
        /// <param name="vertex1">Vertex1 of the edge to be added.</param>
        /// <param name="vertex2">Vertex2 of the edge to be added.</param>
        /// <param name="vertex3">Vertex3 of the edge to be added.</param>
        /// <returns></returns>
        public HyperEdge AddEdge(Vertex vertex1, Vertex vertex2, Vertex vertex3 = null, TileOrientation tileOrientation = TileOrientation.None)
        {
            if (vertex1.EqualsOnEdgeBasis(vertex2) || vertex1.EqualsOnEdgeBasis(vertex3) || vertex2.EqualsOnEdgeBasis(vertex3))
            {
                throw new ArgumentException("Vertices must not be equal.");
            }

            if (!this.HasVertex(vertex1.Value))
            {
                throw new ArgumentException($"This graph does not conatin a vertex with value '{vertex1}'.");
            }

            if (!this.HasVertex(vertex2.Value))
            {
                throw new ArgumentException($"This graph does not conatin a vertex with value '{vertex2}'.");
            }

            if (vertex3 != null && !this.HasVertex(vertex3.Value))
            {
                throw new ArgumentException($"This graph does not conatin a vertex with value '{vertex3}'.");
            }

            Vertex v1 = Vertex.CreateFromVertex(this.Vertices.Where(v => v.Value.Equals(vertex1.Value)).First());
            Vertex v2 = Vertex.CreateFromVertex(this.Vertices.Where(v => v.Value.Equals(vertex2.Value)).First());
            Vertex v3 = vertex3 != null?Vertex.CreateFromVertex(this.Vertices.Where(v => v.Value.Equals(vertex3.Value)).First()) : null;

            HyperEdge edge = new HyperEdge(v1, v2, v3, tileOrientation);

            if (this.HasEdge(edge))
            {
                throw new ArgumentException($"This Graph has already an edge '{edge}'.");
            }

            this.Edges.Add(edge);
            return(edge);
        }
コード例 #12
0
        /// <summary>
        /// Checks whether tile can be placed on given position.
        /// </summary>
        /// <param name="grid">Grid with all placed tiles.</param>
        /// <param name="tile">Scheme of the tile.</param>
        /// <param name="coords">Coordinates of the tile.</param>
        /// <param name="orientation">Orientation of the tile.</param>
        /// <param name="first">Is the tile first to be placed?</param>
        /// <exception cref="GameException">Exception describing the error.</exception>
        public static void CheckTilePlacement(Dictionary <Coords, TilePlacement> grid, TileScheme tile, Coords coords, TileOrientation orientation, bool first)
        {
            bool hasNeighbour = false;

            // Check all neighbours
            foreach (var or in new TileOrienationEnumerator())
            {
                if (grid.TryGetValue(coords.GetNeighbouringCoords(or), out TilePlacement neighTile))
                {
                    hasNeighbour = true;

                    // Retrieve IDs of regions on appropriate positions
                    var thisSchemeOr  = or.Derotate(orientation);
                    var neighSchemeOr = or.Rotate(TileOrientation.S).Derotate(neighTile.Orientation);

                    int thisRegionId  = tile.GetRegionOnBorder(thisSchemeOr);
                    int neighRegionId = neighTile.Scheme.GetRegionOnBorder(neighSchemeOr);

                    // Check if region types are corresponding
                    if (neighTile.Scheme.GetRegionType(neighRegionId) != tile.GetRegionType(thisRegionId))
                    {
                        throw new WrongTileSurroundingsException();
                    }
                }
            }

            // If first tile has neighbour or not-first tile has not neighbour
            if (first == hasNeighbour)
            {
                throw new NoTileSurroundingsException();
            }
        }
コード例 #13
0
ファイル: Tile.cs プロジェクト: JohnAkerman/Graven
        public void calculateOrientation(ref Tile[,,]tiles)
        {
            tileX = getTileCoords("X");
            tileY = getTileCoords("Y");

            int tmpY = grabY(-1);
            int tmpY2 = grabY(1);
            int tmpX = grabX(-1);
            int tmpX2 = grabX(1);

            if (tmpY == -1 || tmpY2 == -1)
                return;
            if (tmpX == -1 || tmpX2 == -1)
               return;

            if (tileX == 0)
                tileOrientation = TileOrientation.Single;

            if (tiles[1, grabY(-1), tileX].tileType != tileType)
                topMost = true;
            else
                topMost = false;

            if (tiles[1, grabY(1), tileX].tileType != tileType)
                bottomMost = true;
            else
                bottomMost = false;

            if (tiles[1, tileY, grabX(1)].tileType != tileType)
                rightMost = true;
            else
                rightMost = false;

            if (tileX > 0 && tiles[1, tileY, grabX(-1)].tileType != tileType)
                leftMost = true;
            else
                leftMost = false;

            if (topMost && !rightMost && !leftMost && !bottomMost)
                tileOrientation = TileOrientation.Top;
            else if (topMost && rightMost && !leftMost && !bottomMost)
                tileOrientation = TileOrientation.TopRight;
            else if (!topMost && rightMost && !leftMost && !bottomMost)
                tileOrientation = TileOrientation.Right;
            else if (!topMost && rightMost && !leftMost && bottomMost)
                tileOrientation = TileOrientation.BottomRight;
            else if (!topMost && !rightMost && !leftMost && bottomMost)
                tileOrientation = TileOrientation.Bottom;
            else if (!topMost && !rightMost && leftMost && bottomMost)
                tileOrientation = TileOrientation.BottomLeft;
            else if (!topMost && !rightMost && leftMost && !bottomMost)
                tileOrientation = TileOrientation.Left;
            else if (topMost && !rightMost && leftMost && !bottomMost)
                tileOrientation = TileOrientation.TopLeft;
            else if (topMost && !rightMost && !leftMost && bottomMost)
                tileOrientation = TileOrientation.TopBottom;
            else if (!topMost && rightMost && leftMost && !bottomMost)
                tileOrientation = TileOrientation.LeftRight;
            else if (!topMost && !rightMost && !leftMost && !bottomMost)
                tileOrientation = TileOrientation.Single;
            else if (topMost && !rightMost && leftMost && bottomMost)
                tileOrientation = TileOrientation.TopBottomLeft;
            else if (topMost && rightMost && !leftMost && bottomMost)
                tileOrientation = TileOrientation.TopBottomRight;
            else if (topMost && rightMost && leftMost && !bottomMost)
                tileOrientation = TileOrientation.TopLeftRight;
            else if (!topMost && rightMost && leftMost && bottomMost)
                tileOrientation = TileOrientation.BottomLeftRight;
            else
                tileOrientation = TileOrientation.Regular;
        }
コード例 #14
0
 protected void Executor_TilePlacedEvent(PlayerColor player, TileScheme tile, Coords coords, TileOrientation orientation)
 {
     Socket.SendToAll(new ServerResponse()
     {
         Type        = ServerResponseType.TILE_PLACEMENT,
         Color       = player,
         Coords      = coords,
         Scheme      = tile,
         Orientation = orientation
     });
 }
コード例 #15
0
    public override void OnInspectorGUI()
    {
        EditorUtility.SetDirty(target);
        script = (TileOrientation)target;


        EditorGUILayout.PrefixLabel("Tile Mask");
        for (int i = 0; i < 9; i++)
        {
            int rowIndex = i % 3;
            if (rowIndex == 0)
            {
                EditorGUILayout.BeginHorizontal(toggleMenuOptions);
            }
            if (i != 4)
            {
                script.tileMask[i] = EditorGUILayout.Toggle(script.tileMask[i]);
            }
            else
            {
                EditorGUILayout.Toggle(false);
            }
            if (rowIndex == 2)
            {
                EditorGUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.PrefixLabel("Floor Mask");
        for (int i = 0; i < 9; i++)
        {
            int rowIndex = i % 3;
            if (rowIndex == 0)
            {
                EditorGUILayout.BeginHorizontal(toggleMenuOptions);
            }
            if (i != 4)
            {
                script.floorMask[i] = EditorGUILayout.Toggle(script.floorMask[i]);
            }
            else
            {
                EditorGUILayout.Toggle(false);
            }
            if (rowIndex == 2)
            {
                EditorGUILayout.EndHorizontal();
            }
        }

        EditorGUILayout.PrefixLabel("Has inverse");
        script.hasInverse = EditorGUILayout.Toggle(script.hasInverse);

        EditorGUILayout.LabelField("Tiles");
        bool[] markedForDeletion = new bool[script.tiles.Length];
        int    index             = 0;
        int    marked            = 0;

        foreach (GameObject prefab in script.tiles)
        {
            Object obj = EditorGUILayout.ObjectField(prefab, typeof(GameObject), false);
            if (obj == null)
            {
                markedForDeletion[index] = true;
                marked++;
            }
            index++;
        }
        if (marked != 0)
        {
            GameObject[] newTiles = new GameObject[script.tiles.Length - marked];
            int          ci       = 0;
            for (int i = script.tiles.Length - 1; i >= 0; i--)
            {
                if (!markedForDeletion[i])
                {
                    newTiles[ci] = script.tiles[i];
                    ci++;
                }
            }
            script.tiles = newTiles;
        }
        EditorGUILayout.PrefixLabel("Add new tile");
        script.addTile((GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), false));
    }
コード例 #16
0
        public static void ProblemOne()
        {
            // load in all tiles into a List<Tile> (id, list of string representing picture)
            List <Tile>    tiles = new List <Tile>();
            Queue <string> input = new Queue <string>(File.ReadAllLines(Path.Combine(Environment.CurrentDirectory, "input", "day_20.txt")).ToList());

            while (input.Count > 0)
            {
                // dequeue and get ID, create a new object
                var tileLine = input.Dequeue().Split("Tile ");
                int tileId   = int.Parse(tileLine[1].TrimEnd(':'));

                // while next line not empty, build up the picture
                List <string> picture = new List <string>();
                while (input.Count > 0 && !string.IsNullOrEmpty(input.Peek()))
                {
                    picture.Add(input.Dequeue());
                }

                // create the tile and add it to the list of tiles.
                tiles.Add(new Tile(tileId, picture));

                // remove the spacer
                if (input.Count > 0)
                {
                    input.Dequeue();
                }
            }

            // determine size of output picture and store this data in a List<Tile> (square root of the number is the size of the big pic)
            int bigPictureSize = Convert.ToInt32(Math.Sqrt(tiles.Count));

            List <Tile> foundTiles = new List <Tile>();

            // start looking for matches... alter the second if it doesn't match
            List <Tile> outerLoop = tiles;

            for (int i = 0; i < outerLoop.Count; i++)
            {
                Tile first = outerLoop.ElementAt(i);
                for (int j = 0; j < tiles.Count; j++)
                {
                    Tile second = tiles.ElementAt(j);
                    if (first != second)
                    {
                        TileOrientation currentTileOrientation = 0;
                        bool            match = false;
                        while (!match && Enum.IsDefined(typeof(TileOrientation), currentTileOrientation))
                        {
                            match = TryMatch(first, second);

                            try
                            {
                                currentTileOrientation++;

                                switch (currentTileOrientation)
                                {
                                case TileOrientation.Rotate90:
                                    second.RotatePicture();
                                    break;

                                case TileOrientation.Rotate180:
                                    second.RotatePicture();
                                    break;

                                case TileOrientation.Rotate270:
                                    second.RotatePicture();
                                    break;

                                case TileOrientation.Flip:
                                    second.RotatePicture();
                                    second.FlipPicture();
                                    break;

                                case TileOrientation.FlipAndRotate90:
                                    second.RotatePicture();
                                    break;

                                case TileOrientation.FlipAndRotate180:
                                    second.RotatePicture();
                                    break;

                                case TileOrientation.FlipAndRotate270:
                                    second.RotatePicture();
                                    break;

                                default:
                                    break;
                                }
                            }
                            catch { }
                        }

                        if (match)
                        {
                            if (!foundTiles.Any(x => x.ID == first.ID))
                            {
                                foundTiles.Add(first);
                            }
                            if (!foundTiles.Any(x => x.ID == second.ID))
                            {
                                foundTiles.Add(second);
                            }

                            if (foundTiles.Count > 1)
                            {
                                outerLoop = foundTiles;
                            }
                            else
                            {
                                outerLoop = tiles;
                            }
                        }
                    }
                }
            }

            // all tiles should be in the correct rotations now, let's go back through them and find other matches
            for (int i = 0; i < tiles.Count; i++)
            {
                Tile first = tiles.ElementAt(i);
                for (int j = 0; j < tiles.Count; j++)
                {
                    Tile second = tiles.ElementAt(j);
                    if (first != second)
                    {
                        TryMatch(first, second);
                    }
                }
            }

            // after all have been "found", iterate through the found tiles to figure out the rest of the tiles it matches.
            int[,] bigPicture = ValidateBigPicture(bigPictureSize, tiles);

            // calculate the product (use a long) of the four tiles in the corners (those ones will be have null top/left, top/right, bottom/left, bottom/right values)
            long product = (long)bigPicture[0, 0] * (long)bigPicture[0, bigPictureSize - 1] * (long)bigPicture[bigPictureSize - 1, 0] * (long)bigPicture[bigPictureSize - 1, bigPictureSize - 1];

            Console.WriteLine($"Product of corners: {product}");
        }
コード例 #17
0
 /// <summary>
 /// Intantiates a new Object of this class.
 /// </summary>
 /// <param name="vertex1">vertex1</param>
 /// <param name="vertex2">vertex2</param>
 /// <param name="vertex3">vertex3 (can be null, if edge has only two vertices)</param>
 public HyperEdge(string vertex1, string vertex2, string vertex3 = null, TileOrientation orientation = TileOrientation.None)
     : this(new Vertex(vertex1), new Vertex(vertex2), (vertex3 != null) ? new Vertex(vertex3) : null, orientation)
 {
 }
コード例 #18
0
 private void Simulation_TilePlacedEvent(PlayerColor player, TileScheme scheme, Coords coords, TileOrientation orientation)
 {
     if (_Running)
     {
         _Serializer.Serialize(_Writer, new ServerResponse()
         {
             Type        = ServerResponseType.TILE_PLACEMENT,
             Color       = player,
             Scheme      = scheme,
             Coords      = coords,
             Orientation = orientation
         });
     }
 }
コード例 #19
0
 /// <summary>
 /// Determines the incoming face of a edge for the next hexagon position.
 /// </summary>
 /// <param name="nextTileOrientation">The orientation of the edge for the new hexagon position.</param>
 /// <returns>Incoming face for new hexgon position.</returns>
 private TileFace GetIncomingFaceForNextHexagonPosition(TileOrientation nextTileOrientation)
 {
     return(this.GetIncomingFace(this.CalcNextPointerValue(this.Pointer), nextTileOrientation));
 }
コード例 #20
0
 /// <summary>
 /// Gets tile orientation that was initial to given rotated angle.
 /// </summary>
 /// <param name="orientation">Orientation after rotation.</param>
 /// <param name="angle">Angle of rotation.</param>
 /// <returns>Orientation before rotation.</returns>
 public static TileOrientation Derotate(this TileOrientation orientation, TileOrientation angle)
 {
     return((TileOrientation)(((int)orientation + 4 - (int)angle) & 0b11));
 }