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); }
// Constructors public PathGenerator(int width, int length, int fillRate, FieldCell cellPrefab) { this.fieldWidth = width; this.fieldLength = length; this.fieldFillRate = fillRate; this.fieldCell = cellPrefab; }
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); }
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); }
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; } } } } }
// 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))); } } }
// Retrieve the list of walkable cells public void MarkCellAsWalkable(FieldCell cell) { if (!this.walkable.Contains(cell)) { this.walkable.Add(cell); } cell.IsWalkable = true; }
public static void DeleteGem(FieldCell cell) { if (cell.Gem != null) { GameState.Score += cell.Gem.ScorePrice; cell.Gem = null; } }
public void MarkCellAsUnwalkable(FieldCell cell) { if (this.walkable.Contains(cell)) { this.walkable.Remove(cell); } cell.IsWalkable = false; }
////////////////////////////////////////////////////////////////////////////// #region Collider public virtual bool HandleCollision(FieldCell cell) { if (cell.IsMovable()) { return(HandleCollision(cell.AsMovable())); } return(HandleStaticCollision(cell)); }
////////////////////////////////////////////////////////////////////////////// #region Collisions public override bool HandleCollision(FieldCell cell) { if (IsAlive) { return(base.HandleCollision(cell)); } return(false); }
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); } }
public void MoveFromOverlap(FieldCell other) { Debug.Assert(IsMoving()); float dx = OverlapX(other); float dy = OverlapY(other); MoveBackX(dx); MoveBackY(dy); }
/* Not movable cell */ protected virtual bool HandleStaticCollision(FieldCell other) { if (other.IsObstacle()) { MoveFromOverlap(other); return(true); } return(false); }
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); }
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); }
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); } }
protected override bool HandleStaticCollision(FieldCell other) { if (other.IsFlame()) { return(HandleCollision(other.AsFlame())); } if (other.IsPowerup()) { return(HandleCollision(other.AsPowerup())); } return(base.HandleStaticCollision(other)); }
public FieldCellView MapCell(FieldCell cell) { switch (cell.Entity) { case Creature _: return(Creature); case Entity _: return(Entity); default: return(Empty); } }
/* 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; } }
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; } }
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; } }
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; } } }
internal bool HandleObstacleCollistion(FieldCell other) { Debug.Assert(isActive); Debug.Assert(IsMoving()); MoveOutOfCell(other); if (TryJellyOnObstacle()) { return(true); } StopMoving(); return(true); }
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; } }
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); }
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); } }
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); } } }
// 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); }
//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); }
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."); } }