コード例 #1
0
 public Plot(PlotTile tile, PlotImprovement improvementChip = PlotImprovement.None, bool isIrrigated = false, int bambooCount = 0)
 {
     Tile            = tile;
     ImprovementChip = improvementChip;
     IsIrrigated     = isIrrigated;
     BambooCount     = bambooCount;
 }
コード例 #2
0
        public void PlotEquality_DifferentColorsNotEqual()
        {
            var tile1 = new PlotTile(BambooColor.Green);
            var tile2 = new PlotTile(BambooColor.Pink);

            Assert.AreNotEqual(tile1, tile2);
        }
コード例 #3
0
        public void PlotEquality_DifferentImprovementsNotEqual()
        {
            var tile1 = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);
            var tile2 = new PlotTile(BambooColor.Green, PlotImprovement.Fertilizer);

            Assert.AreNotEqual(tile1, tile2);
        }
コード例 #4
0
    /// <summary>
    /// Sets the initial position and the bot settings of the cubot
    /// </summary>
    /// <param name="initialPlotTile"></param>
    /// <param name="initialOrientation"></param>
    public void SetUp(LevelDescriptor configuration, List <PlotTile> tilesInScene)
    {
        this.tilesInScene  = tilesInScene;
        CurrentOrientation = configuration.CharacterInitialOrientation;
        Vector3    cubotExtents             = this.GetComponent <Renderer>().bounds.extents;
        Vector3Int cubotPlotInitialPosition = configuration.CharacterStartPointInPlot;

        PlotTile initialPlotTile = tilesInScene.Where(t => t.PlotPosition == cubotPlotInitialPosition).First();

        float   rotY = (int)CurrentOrientation;
        Vector3 initialPlotTileExtents = initialPlotTile.GetComponent <Renderer>().bounds.extents;

        //Cubot must be over an initial plot tile, so we are going to position it
        Vector3 initialPosition = initialPlotTile.transform.position;

        initialPosition.y += cubotExtents.y + initialPlotTileExtents.y;

        Vector3 cubotInitialRotation = new Vector3(0, rotY, 0);

        this.transform.position = initialPosition;
        this.transform.rotation = Quaternion.Euler(cubotInitialRotation);

        Speed = configuration.CharacterSpeed;

        CurrentTile = initialPlotTile;
        CurrentTile.Step();
    }
コード例 #5
0
        public void PlotEquality()
        {
            var tile1 = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);
            var tile2 = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);

            Assert.AreEqual(tile1, tile2);
        }
コード例 #6
0
    /// <summary>
    /// Calls a forward movement to climb down
    /// The movement will consist on the character flying up and then going forward
    /// </summary>
    /// <param name="destinyTile"></param>
    public void ClimbDown()
    {
        try
        {
            // Gets the tile it is going to move to
            PlotTile nextTile = GetTileAhead();

            if (nextTile == null)
            {
                throw new NoTileAheadException();
            }

            // Validates if the next tile bellow the current level
            if (nextTile.PlotPosition.z >= CurrentTile.PlotPosition.z)
            {
                throw new NoHoleAheadException();
            }

            destination.movementPhases = new List <MovementType>()
            {
                MovementType.FORWARD, MovementType.CLIMB_DOWN, MovementType.NONE
            };
            destination.destinyTile = nextTile;

            ExecutingAction = true;
        }
        catch (Exception ex)
        {
            ResetMovement();
            throw ex;
        }
    }
コード例 #7
0
    /// <summary>
    /// Gets the tile in front of this object
    /// </summary>
    /// <returns></returns>
    public PlotTile GetTileAhead()
    {
        //First we get the translation in terms of PlotTile coordinates
        Vector3Int translationInPlot = new Vector3Int(0, 0, 0);

        switch (CurrentOrientation)
        {
        case CharacterOrientation.NORTH:
            translationInPlot.y = 1;
            break;

        case CharacterOrientation.SOUTH:
            translationInPlot.y = -1;
            break;

        case CharacterOrientation.EAST:
            translationInPlot.x = 1;
            break;

        case CharacterOrientation.WEST:
            translationInPlot.x = -1;
            break;
        }
        // Then we get the next tile coordinates
        Vector3Int nextPlotTileCoordinates = CurrentTile.PlotPosition + translationInPlot;
        // Then we set movement to next tile
        PlotTile nextTile = tilesInScene.Where(t => t.PlotPosition.x == nextPlotTileCoordinates.x && t.PlotPosition.y == nextPlotTileCoordinates.y).FirstOrDefault();

        return(nextTile);
    }
コード例 #8
0
ファイル: GameStateTests.cs プロジェクト: bolte-17/PandaGame
        public void PlaceTile_OriginFails()
        {
            var tile   = new PlotTile(BambooColor.Green);
            var origin = (0, 0);

            Assert.ThrowsException <ArgumentException>(() => initialGameState.PlaceTile(tile, origin));
        }
コード例 #9
0
ファイル: GameStateTests.cs プロジェクト: bolte-17/PandaGame
        public void PlaceTile_OverwriteFails()
        {
            var tile      = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);
            var location  = (0, 1);
            var nextState = initialGameState.PlaceTile(tile, location);

            Assert.ThrowsException <ArgumentException>(() => nextState.PlaceTile(tile, location));
        }
コード例 #10
0
ファイル: GameStateTests.cs プロジェクト: bolte-17/PandaGame
        public void PlaceTile_Success()
        {
            var tile     = new PlotTile(BambooColor.Green);
            var location = (0, 1);
            var newState = GameStateService.PlaceTile(initialGameState, new PlotTile(BambooColor.Green), location);

            Assert.AreEqual(tile, newState.PlotGrid[location].Tile);
        }
コード例 #11
0
        public void PlotEquality_Nulls()
        {
            var      tile1     = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);
            PlotTile nullTile1 = null;
            PlotTile nullTile2 = null;

            Assert.AreEqual(nullTile1, nullTile2);
            Assert.AreNotEqual(tile1, nullTile1);
            Assert.AreNotEqual(nullTile1, tile1);
            Assert.IsTrue(nullTile2 != tile1);
        }
コード例 #12
0
        public void PlotEquality_HashCodes()
        {
            var tile1 = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);
            var tile2 = new PlotTile(BambooColor.Green, PlotImprovement.Enclosure);

            Assert.AreEqual(tile1.GetHashCode(), tile2.GetHashCode());

            var set = new HashSet <PlotTile> {
                tile1, tile2
            };

            Assert.AreEqual(1, set.Count);
        }
コード例 #13
0
    // Builds the tile plot
    public void BuildTilePlot()
    {
        PlotTile templateTile         = LevelConfiguration.FirstTile;
        Renderer templateTileRenderer = templateTile.GetComponent <Renderer>();
        // The extents give half of each dimension (width, length, and height)
        Vector3 tileExtents = templateTileRenderer.bounds.extents;
        float   tileWidth   = 2 * tileExtents.x;
        float   tileLength  = 2 * tileExtents.z;
        float   tileHeight  = 2 * tileExtents.y;

        // Important note!
        // The coordinates of a Tile in the Plot Tile do not translate directly to the Coordinates in world
        // plotX <-> worldX, plotY <-> worldZ, plotZ <-> worldY
        // This is to facilitate the configuration of the level, turning it more readable

        //tilesInScene.Add(tile);
        for (int plotY = 0; plotY < LevelConfiguration.PlotLength; plotY++)    //iterates through lines (y)
        {
            for (int plotX = 0; plotX < LevelConfiguration.PlotWidth; plotX++) //iterates through columns (x)
            {
                int plotZ = 0;
                //Verifies for this (plotX,plotY) if there is a special coordinate that modifies heigth
                Vector3Int specialCoordinate = LevelConfiguration.SpecialCoordinates.Where(a => a.x == plotX && a.y == plotY).FirstOrDefault();
                if (specialCoordinate != null)
                {
                    plotZ = specialCoordinate.z;
                }

                // Gets a new tile (or reuses the template if we are on the first position)
                PlotTile newTile = plotY == 0 && plotX == 0 ? templateTile : Instantiate(templateTile);
                newTile.PlotPosition = new Vector3Int(plotX, plotY, plotZ);

                //Defines the new tile position in the world
                Vector3 newTilePosition = newTile.transform.position;
                newTilePosition.x += plotX * tileWidth;
                newTilePosition.y += plotZ * tileHeight;
                newTilePosition.z += plotY * tileLength;

                //Sets the new position
                newTile.transform.position = newTilePosition;

                //Saves the tile in the tile list
                tilesInScene.Add(newTile);
            }
        }
    }
コード例 #14
0
    /// <summary>
    /// Calls a forward movement to climb up
    /// The movement will consist on the character flying up and then going forward
    /// </summary>
    /// <param name="destinyTile"></param>
    public void ClimbUp()
    {
        try
        {
            // Gets the tile it is going to move to
            PlotTile nextTile = GetTileAhead();

            if (nextTile == null)
            {
                throw new NoTileAheadException();
            }

            // Validates if there is a next tile, and its not bellow the current level
            if (nextTile.PlotPosition.z < CurrentTile.PlotPosition.z)
            {
                throw new HoleAheadException();
            }

            //Throws exception if no obstacle ahead
            if (nextTile.PlotPosition.z <= CurrentTile.PlotPosition.z)
            {
                throw new NoObstacleAheadException();
            }


            destination.movementPhases = new List <MovementType>()
            {
                MovementType.CLIMB_UP, MovementType.FORWARD, MovementType.NONE
            };
            destination.destinyTile = nextTile;

            ExecutingAction = true;
        }
        catch (Exception ex)
        {
            ResetMovement();
            throw ex;
        }
    }
コード例 #15
0
        public static GameState PlaceTile(this GameState gameState, PlotTile tile, HexIndex location)
        {
            if (location == (0, 0))
            {
                throw new ArgumentException("Cannot place tile at pond's location (0,0)", nameof(location));
            }
            var newDeck = gameState.PlotTileDeck.Remove(tile);

            if (newDeck.Count == gameState.PlotTileDeck.Count)
            {
                throw new ArgumentException("Tile not available in deck", nameof(tile));
            }
            if (gameState.PlotGrid.ContainsKey(location))
            {
                throw new ArgumentException("Plot already exists at location", nameof(location));
            }

            return(new GameState(
                       newDeck,
                       gameState.ImprovementChipPool,
                       gameState.PlotGrid.Add(location, new Plot(tile)),
                       gameState.IrrigationGrid
                       ));
        }