public bool IsCellInsideGameField(GameFieldCell cell) { var fieldSize = Settings.GameFieldSize; return(cell.X >= 0 && cell.X < fieldSize && cell.Y >= 0 && cell.Y < fieldSize && cell.Z >= 0 && cell.Z < fieldSize); }
public override void Move() { if (_die) { return; } var newStartCell = _decisionMove(_cells[0]); _cells.Insert(0, newStartCell); _gameManager.AssignGameEntityToGameFieldCell(this, newStartCell); _prevLastCell = _cells[_cells.Count - 1]; _cells.RemoveAt(_cells.Count - 1); _gameManager.UnassignGameEntityToGameFieldCell(this, _prevLastCell); }
public override void Spawn(IGameManager gameManager) { base.Spawn(gameManager); var snakeLength = _gameManager.Settings.SnakeStartLength; while (true) { var startCell = _gameManager.GetRandomEmptyCell(); var fit = true; for (var dX = 1; dX < snakeLength; dX++) { if (startCell.X + dX >= _gameManager.Settings.GameFieldSize || _gameManager.GetGameFieldCellEntities(startCell.X + dX, startCell.Y, startCell.Z).Count != 0) { fit = false; break; } } if (fit) { for (var dX = 0; dX < snakeLength; dX++) { var cell = new GameFieldCell { X = startCell.X + dX, Y = startCell.Y, Z = startCell.Z }; _gameManager.AssignGameEntityToGameFieldCell(this, cell); var snakePart = Instantiate(_gameManager.Settings.SnakePartPrefab, _gameManager.GameCellToWorldCoords(cell), Quaternion.identity, transform); _snakeParts.Add(snakePart.transform); _cells.Add(cell); } break; } } }
public HashSet <IGameEntity> GetGameFieldCellEntities(GameFieldCell cell) => _gameField[cell.X, cell.Y, cell.Z];
public void UnassignGameEntityToGameFieldCell(IGameEntity gameEntity, GameFieldCell cell) { _gameField[cell.X, cell.Y, cell.Z].Remove(gameEntity); }
public void AssignGameEntityToGameFieldCell(IGameEntity gameEntity, GameFieldCell cell) { _gameField[cell.X, cell.Y, cell.Z].Add(gameEntity); }
public Vector3 GameCellToWorldCoords(GameFieldCell cell) => GameCellToWorldCoords(cell.X, cell.Y, cell.Z);