Exemplo n.º 1
0
        public void FieldDecryptionTest()
        {
            var textField = new[]
            {
                "W#@#",
                "#W##",
                "P###"
            };
            var field    = Field.FromLines(textField);
            var initCell = new FieldCell(0, 2, FieldCellStates.Player);
            var winCell  = new FieldCell(2, 0, FieldCellStates.WinCell);
            var weed1    = new Weed(0, 0);
            var weed2    = new Weed(1, 1);

            Assert.AreEqual(field.initialCell.X, initCell.X);
            Assert.AreEqual(field.initialCell.Y, initCell.Y);
            Assert.AreEqual(field.initialCell.State, initCell.State);

            Assert.AreEqual(field.winCell.X, winCell.X);
            Assert.AreEqual(field.winCell.Y, winCell.Y);
            Assert.AreEqual(field.winCell.State, winCell.State);

            Assert.AreEqual(field.weeds[0].X, weed1.X);
            Assert.AreEqual(field.weeds[0].Y, weed1.Y);
            Assert.AreEqual(field.weeds[0].WeedState, weed1.WeedState);

            Assert.AreEqual(field.weeds[1].X, weed2.X);
            Assert.AreEqual(field.weeds[1].Y, weed2.Y);
            Assert.AreEqual(field.weeds[1].WeedState, weed2.WeedState);
        }
Exemplo n.º 2
0
 // Constructors
 public PathGenerator(int width, int length, int fillRate, FieldCell cellPrefab)
 {
     this.fieldWidth    = width;
     this.fieldLength   = length;
     this.fieldFillRate = fillRate;
     this.fieldCell     = cellPrefab;
 }
Exemplo n.º 3
0
        public void SetRelativeTo(FieldCell cell, int stepX, int stepY)
        {
            float posX = stepX != 0 ? (cell.CellCenterPx() + stepX * Constant.CELL_WIDTH) : px;
            float posY = stepY != 0 ? (cell.CellCenterPy() + stepY * Constant.CELL_HEIGHT) : py;

            SetPos(posX, posY);
        }
Exemplo n.º 4
0
        private void Cell_Click(object sender, EventArgs e)
        {
            FieldCell clickedCell = (FieldCell)sender;

            if (clickedCell.Gem == null)
            {
                return;
            }

            if (_prevCell != null)
            {
                clickedCell.Gem.WasMoved = true;
                _prevCell.Gem.WasMoved   = true;
                Move = new CurrentMove(clickedCell, _prevCell);
                GemsController.SwapGems(Move.FirstCell, Move.SecondCell);

                foreach (var cell in GameField)
                {
                    if (cell.Gem != null)
                    {
                        cell.Gem.IsClicked = false;
                    }
                    GemsController.UpdateGemTexture(cell.Gem);
                }

                _prevCell = null;
            }
            else
            {
                clickedCell.Gem.IsClicked = true;
                GemsController.UpdateGemTexture(clickedCell.Gem);
                _prevCell = clickedCell;
            }
        }
    public float GetSqrDistance(FieldCell fieldCell)
    {
        var currentCellPos = new Vector2(transform.position.x, transform.position.z);
        var targetCellPos  = new Vector2(fieldCell.transform.position.x, fieldCell.transform.position.z);

        return((targetCellPos - currentCellPos).sqrMagnitude);
    }
Exemplo n.º 6
0
 public void DrawMove(Player player)
 {
     foreach (var pair in Map.cellMap)
     {
         Vector2Int pos = pair.Key;
         _tilemap.SetColor((Vector3Int)pos, Color.white);
         if (!pair.Value.isAvaiable)
         {
             continue;
         }
         for (int addX = -1; addX <= 1; ++addX)
         {
             for (int addY = -1; addY <= 1; ++addY)
             {
                 if (addX == 0 && addY == 0)
                 {
                     continue;
                 }
                 Vector2Int neighbourPos = new Vector2Int(pos.x + addX, pos.y + addY);
                 if (!Map.cellMap.ContainsKey(neighbourPos))
                 {
                     continue;
                 }
                 FieldCell neighbour = Map.cellMap[neighbourPos];
                 if (neighbour.tilePlayer == player)
                 {
                     _tilemap.SetColor((Vector3Int)pos, turnColor);
                     addX = 2;
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
    // Gameplay-Related Methods
    public virtual void Move(Direction direction)
    {
        // Just in case
        StopAllCoroutines();
        // Face that direction
        StartCoroutine(this.IFace(DirectionGuide.getRotation(direction, this.faceDirection)));
        // He faces that direction now
        this.faceDirection = direction;
        // Check if that destination exists and it is walkable
        IntVector2 dest           = new IntVector2(DirectionGuide.getDirection(direction) + this.transform.position);
        FieldCell  destCell       = this.GameManager.CaveGenerator.FindCell(dest);
        Collider2D detectedObject = this.Detect();

        if (destCell != null)           // If there is a cell in that direction
        {
            if (detectedObject != null) // if the destination's cell is occupied?
            {
                this.PickAction(detectedObject);
            }
            else if (destCell.IsWalkable)
            {
                // The current position shall be marked as walkable again
                this.gameManager.CaveGenerator.MarkCellAsWalkable(this.Cell);
                // The destination mustn't be walkable anymore
                this.gameManager.CaveGenerator.MarkCellAsUnwalkable(destCell);
                // Move
                StartCoroutine(this.IMove(DirectionGuide.getDirection(direction)));
            }
        }
    }
Exemplo n.º 8
0
 // Retrieve the list of walkable cells
 public void MarkCellAsWalkable(FieldCell cell)
 {
     if (!this.walkable.Contains(cell))
     {
         this.walkable.Add(cell);
     }
     cell.IsWalkable = true;
 }
Exemplo n.º 9
0
 public static void DeleteGem(FieldCell cell)
 {
     if (cell.Gem != null)
     {
         GameState.Score += cell.Gem.ScorePrice;
         cell.Gem         = null;
     }
 }
Exemplo n.º 10
0
 public void MarkCellAsUnwalkable(FieldCell cell)
 {
     if (this.walkable.Contains(cell))
     {
         this.walkable.Remove(cell);
     }
     cell.IsWalkable = false;
 }
Exemplo n.º 11
0
        //////////////////////////////////////////////////////////////////////////////

        #region Collider

        public virtual bool HandleCollision(FieldCell cell)
        {
            if (cell.IsMovable())
            {
                return(HandleCollision(cell.AsMovable()));
            }

            return(HandleStaticCollision(cell));
        }
Exemplo n.º 12
0
        //////////////////////////////////////////////////////////////////////////////

        #region Collisions

        public override bool HandleCollision(FieldCell cell)
        {
            if (IsAlive)
            {
                return(base.HandleCollision(cell));
            }

            return(false);
        }
Exemplo n.º 13
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            var key      = e.KeyData;
            var position = new FieldCell(0, 0, FieldCellStates.Empty);

            switch (key)
            {
            case Keys.Right:
                if (game.player.CanMove(game.player.CurrentPos.X + 1, game.player.CurrentPos.Y, game.field))
                {
                    position.X += 1;
                }
                break;

            case Keys.Left:
                if (game.player.CanMove(game.player.CurrentPos.X - 1, game.player.CurrentPos.Y, game.field))
                {
                    position.X -= 1;
                }
                break;

            case Keys.Up:
                if (game.player.CanMove(game.player.CurrentPos.X, game.player.CurrentPos.Y - 1, game.field))
                {
                    position.Y -= 1;
                }
                break;

            case Keys.Down:
                if (game.player.CanMove(game.player.CurrentPos.X, game.player.CurrentPos.Y + 1, game.field))
                {
                    position.Y += 1;
                }
                break;

            case Keys.D:
                game.DigUpWeed(new Weed(game.player.CurrentPos.X, game.player.CurrentPos.Y - 1));
                break;

            case Keys.A:
                game.FreezeWeed(new Weed(game.player.CurrentPos.X, game.player.CurrentPos.Y));
                break;
            }
            ;

            var newX = game.player.CurrentPos.X + position.X;
            var newY = game.player.CurrentPos.Y + position.Y;

            if (newX >= 0 && newX < game.field.Width &&
                newY >= 0 && newY < game.field.Height &&
                !game.field.weeds.Contains(new Weed(newX, newY)))
            {
                position.State         = FieldCellStates.Player;
                game.player.CurrentPos = new FieldCell(newX, newY, FieldCellStates.Player);
            }
        }
Exemplo n.º 14
0
        public void MoveFromOverlap(FieldCell other)
        {
            Debug.Assert(IsMoving());

            float dx = OverlapX(other);
            float dy = OverlapY(other);

            MoveBackX(dx);
            MoveBackY(dy);
        }
Exemplo n.º 15
0
        /* Not movable cell */
        protected virtual bool HandleStaticCollision(FieldCell other)
        {
            if (other.IsObstacle())
            {
                MoveFromOverlap(other);
                return(true);
            }

            return(false);
        }
Exemplo n.º 16
0
 public void Initialize(int fieldSize)
 {
     FieldCells = new FieldCell[fieldSize][];
     for (var index = 0; index < FieldCells.Length; index++)
     {
         FieldCells[index] = new FieldCell[fieldSize];
     }
     FreeCells = new List <FieldCell>();
     EventManager.Instance.AddListener(EventType.AgentGotCell, OnAgentGotCell);
 }
Exemplo n.º 17
0
    private void CmdPlaceBuilding(GameObject cellObject, NetworkHash128 buildingId)
    {
        FieldCell cell     = cellObject.GetComponent <FieldCell>();
        Building  building = ClientScene.prefabs[buildingId].GetComponent <Building>();

        if (cell == null || building == null)
        {
            return;
        }

        cell.PlaceBuilding(building, this);
    }
Exemplo n.º 18
0
 private static void ChangeGemInBlastRadius(FieldCell fieldCell)
 {
     if (fieldCell.Gem != null && (fieldCell.Gem.Type == GemType.Bomb ||
                                   fieldCell.Gem.Type == GemType.HorizontalLine ||
                                   fieldCell.Gem.Type == GemType.VerticalLine))
     {
         fieldCell.Gem.WasMoved = true;
     }
     else
     {
         GemsController.DeleteGem(fieldCell);
     }
 }
Exemplo n.º 19
0
        protected override bool HandleStaticCollision(FieldCell other)
        {
            if (other.IsFlame())
            {
                return(HandleCollision(other.AsFlame()));
            }

            if (other.IsPowerup())
            {
                return(HandleCollision(other.AsPowerup()));
            }

            return(base.HandleStaticCollision(other));
        }
Exemplo n.º 20
0
        public FieldCellView MapCell(FieldCell cell)
        {
            switch (cell.Entity)
            {
            case Creature _:
                return(Creature);

            case Entity _:
                return(Entity);

            default:
                return(Empty);
            }
        }
Exemplo n.º 21
0
/*
		public IFieldCell this[byte x, byte y]
		{
			get { return cell[x, y]; }
		}
*/

		public PlayField()
		{
			cell = new FieldCell[length, length];
			for (int x = 0; x < length; x++)
				for (int y = 0; y < length; y++)
				{
					var c = new FieldCell();
					if (x == 0) c.left = 10;
					if (y == 0) c.up = 10;
					if (x == length) c.right = 10;
					if (y == length) c.down = 10;
					cell[x, y] = c;
				}
		}
Exemplo n.º 22
0
        public static void LaunchDestroyers(FieldCell cell)
        {
            switch (cell.Gem.Type)
            {
            case GemType.HorizontalLine:
                GameState.Destroyers.Add(new Destroyer(cell.Position, DirectionType.Horizontal, CoordinateDirection.Right));
                GameState.Destroyers.Add(new Destroyer(cell.Position, DirectionType.Horizontal, CoordinateDirection.Left));
                break;

            case GemType.VerticalLine:
                GameState.Destroyers.Add(new Destroyer(cell.Position, DirectionType.Vertical, CoordinateDirection.Up));
                GameState.Destroyers.Add(new Destroyer(cell.Position, DirectionType.Vertical, CoordinateDirection.Down));
                break;
            }
        }
Exemplo n.º 23
0
        public static void SwapGems(FieldCell firstCell, FieldCell secondCell)
        {
            var isCellsNearby = GameBoardConroller.IsCellsNearby(firstCell, secondCell);

            if (isCellsNearby)
            {
                var gem = (Gem)firstCell.Gem.Clone();

                firstCell.Gem          = (Gem)secondCell.Gem.Clone();
                firstCell.Gem.Position = firstCell.Position;

                secondCell.Gem          = gem;
                secondCell.Gem.Position = secondCell.Position;
            }
        }
Exemplo n.º 24
0
    private void CellOnClick(FieldCell cell)
    {
        if (_currentShovelCount > 0)
        {
            SetCurrentShovelCount(_currentShovelCount - 1);
            cell.Dig();
            if (Random.Range(0f, 1f) < _treasureSpawnRate)
            {
                var treasure = Instantiate(_treasureCell, cell.transform);
                treasure.Init(_canvasTransform, _treasureSprites[Random.Range(0, _treasureSprites.Length)], _treasureGroupTransform);
                treasure.GetComponent <RectTransform>().SetParent(_treasureGroupTransform);

                treasure.DragEnd += TreasureOnDragEnd;
            }
        }
    }
Exemplo n.º 25
0
        internal bool HandleObstacleCollistion(FieldCell other)
        {
            Debug.Assert(isActive);
            Debug.Assert(IsMoving());

            MoveOutOfCell(other);

            if (TryJellyOnObstacle())
            {
                return(true);
            }

            StopMoving();

            return(true);
        }
Exemplo n.º 26
0
        private static void CheckGemAndActivateBonus(FieldCell cell)
        {
            switch (cell.Gem.Type)
            {
            case GemType.Bomb:
                ActivatedBombs.Add((FieldCell)cell.Clone());
                GemsController.DeleteGem(cell);
                break;

            case GemType.VerticalLine:
            case GemType.HorizontalLine:
                BonusController.LaunchDestroyers(cell);
                GemsController.DeleteGem(cell);
                break;
            }
        }
Exemplo n.º 27
0
        private FieldCell[,] GetPlayingField()
        {
            FieldCell[,] result = new FieldCell[DefaultField.BoardSize, DefaultField.BoardSize];
            var random = new Random();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    var cell = GameBoardConroller.GenerateNewFieldCell(j, i, random, Cell_Click);
                    result[i, j] = cell;
                }
            }

            return(result);
        }
Exemplo n.º 28
0
    public virtual void Chase(Humanoid target)
    {
        if (!this.isMoving) // Only if he is not moving
        {
            if (target == null)
            {
                throw new Exception("Catched Bug: No target to pursue!");
            }

            FieldCell        s = this.GameManager.CaveGenerator.FindCell(this.Position);
            FieldCell        e = this.GameManager.CaveGenerator.FindCell(target.Position);
            List <FieldCell> w = this.gameManager.CaveGenerator.FindWalkableCells();

            // Find path
            List <FieldCell> path = PathFinder.FindShortestPath(w, s, e);

            if (path == null)
            {
                return;
            }

            // Find direction
            IntVector2 d = path[1].Position - s.Position;
            // Convert direction
            int dIndex = DirectionGuide.getDirectionIndex(d);
            if (dIndex == -1)
            {
                return;
            }
            // Means the antagonist is only one step closer to the protagonist
            if (path.Count == 2)
            {
                if (DirectionGuide.getDirection(this.faceDirection) + this.Position == target.Position)
                {
                    // Harm the player
                    target.TakeDamage(this.damage);
                }
                else
                {
                    // Just face the target for now
                    StartCoroutine(base.IFace(DirectionGuide.getRotation((Direction)dIndex, faceDirection)));
                }
            }
            // Move
            base.Move((Direction)dIndex);
        }
    }
Exemplo n.º 29
0
 public static void BlowBomb(FieldCell cell)
 {
     foreach (var fieldCell in GameState.GameField)
     {
         if ((cell.Row + 1 == fieldCell.Row && cell.Column == fieldCell.Column) ||
             (cell.Row - 1 == fieldCell.Row && cell.Column == fieldCell.Column) ||
             (cell.Column + 1 == fieldCell.Column && cell.Row == fieldCell.Row) ||
             (cell.Column - 1 == fieldCell.Column && cell.Row == fieldCell.Row) ||
             (cell.Row + 1 == fieldCell.Row && cell.Column + 1 == fieldCell.Column) ||
             (cell.Row - 1 == fieldCell.Row && cell.Column + 1 == fieldCell.Column) ||
             (cell.Row + 1 == fieldCell.Row && cell.Column - 1 == fieldCell.Column) ||
             (cell.Row - 1 == fieldCell.Row && cell.Column - 1 == fieldCell.Column))
         {
             ChangeGemInBlastRadius(fieldCell);
         }
     }
 }
Exemplo n.º 30
0
    // Shortcut for creating a cell
    protected FieldCell createCell(IntVector2 p)
    {
        // Instantiate
        FieldCell fc = GameObject.Instantiate(this.fieldCell, p.ToVector2(), Quaternion.identity) as FieldCell;

        fc.Position = p;
        // Rename the cell
        fc.name = "Cell X:(" + p.x + ") Y:(" + p.y + ")";
        // Append it to the parent
        fc.transform.SetParent(this.fieldContainer);
        // Save it to the cell list
        this.cells.Add(fc);
        // Mark it as walkable
        this.MarkCellAsWalkable(fc);
        // Return
        return(fc);
    }
Exemplo n.º 31
0
        //adding submarines to 0,2,4,6... rows
        public override FieldCell[,] Build()
        {
            FieldCell[,] field = new FieldCell[FieldHeight, FieldLength];

            for (var i = 0; i < FieldHeight; i++)
            {
                for (var j = 0; j < FieldLength; j++)
                {
                    field[i, j] = new FieldCell(j, i);
                    if (i % 2 == 0)
                    {
                        field[i, j].FieldUnit = new Ship(DeckType.OneDeck, new FieldCell[] { field[i, j] });
                    }
                }
            }

            return(field);
        }
Exemplo n.º 32
0
 public static int[,] GetAccordingExplosionType(FieldCell cellType)
 {
     switch (cellType)
     {
         case FieldCell.Mine1:
             return Explosion1;
         case FieldCell.Mine2:
             return Explosion2;
         case FieldCell.Mine3:
             return Explosion3;
         case FieldCell.Mine4:
             return Explosion4;
         case FieldCell.Mine5:
             return Explosion5;
         default:
             throw new InvalidOperationException("Cannot return explosion type " +
                 "for a non-mine field cell type.");
     }
 }