public void updateStructureTile(Structure s, MapCoords coords) { Structure toAdd = s; if (s == null) { toAdd = new EmptyTile(); } Structure toRemove = mapData.getStructure(coords); if (!(toRemove is EmptyTile)) { if (toRemove is PowerPlant) { game.LoseGame(); } GameObject.Destroy(toRemove.gameObject); toRemove.gameObject = null; } if (toRemove is PowerCarrier || s is PowerCarrier || toRemove is PowerableStructure || s is PowerableStructure) { powerHandler.dirtyCache = true; } mapData.setTile(coords.x, coords.y, toAdd); InstantiateStructureObject(coords, toAdd); }
//Generates the tiles private void GenerateTiles(int dimension) { #if UNITY_EDITOR BoardState.GenerateTileArray(); #endif Debug.Log("Generating Tiles of Dimension: " + dimension); //get the position where to lay the first empty tile Vector3 currentPos = GetTileStartPos(dimension); //rows for (int i = 0; i < dimension; i++) { //columns for (int j = 0; j < dimension; j++) { //instantiate new tile as a child of this object and then reset position GameObject newObject = Instantiate(emptyTile, currentPos, Quaternion.identity, gameObject.transform); EmptyTile newTile = newObject.GetComponent <EmptyTile>(); newTile.TileValue = new Vector2Int(i, j); currentPos.x += tileBounds.x + tileSpacing; #if UNITY_EDITOR BoardState.AddToTileArray(newTile); #endif } //set x and y for a new row currentPos.x = GetTileStartPos(dimension).x; currentPos.y -= tileBounds.y + tileSpacing; } }
PickedUpItems FillWith(GameObject obj, int x, int y) { //print("Fill with landtile at " + x + ", " + y); Vector3 pos = new Vector3((-totalWidth / 2.0f) + (tileSize / 2.0f) + x * tileSize, (totalHeight / 2.0f) - (tileSize / 2.0f) - tileSize * y, 3); //Debug.Log(pos); GameObject newTile = Instantiate(obj); newTile.transform.SetParent(transform); newTile.transform.position = pos; LandBrick tile = newTile.GetComponent <LandBrick>(); EmptyTile EmptyTile = newTile.GetComponent <EmptyTile>(); if (tile != null) { tile.index = new Vector2Int(x, y); //Debug.Log("index: " + x + ", " + y); return(tile); } else if (EmptyTile != null) { EmptyTile.index = new Vector2Int(x, y); //Debug.Log("index: " + x + ", " + y); return(EmptyTile); } else { return(null); } }
private void ParseMap(string input) { var lines = input.SplitByNewline(); Width = lines.Max(l => l.Length); Height = lines.Length; Tiles = new MapTile[Width, Height]; var y = 0; foreach (var line in lines) { for (var x = 0; x < Width; x++) { if (line[x] == '.') { Tiles[x, y] = new EmptyTile(); } else if (line[x] == '#') { Tiles[x, y] = new TreeTile(); } } y++; } }
public static void Main(string[] args) { var playerInput = new PlayerInput(); var wallTile = new WallTile(); var emptyTile = new EmptyTile(); var pelletTile = new PelletTile(); var tileTypeFactory = new TileTypeFactory(wallTile, emptyTile, pelletTile); var ghostTile = new GhostTile(); var ghostBehaviour = new RandomGhostBehaviour(ghostTile); var pacmanTile = new PacmanTile(); var pacmanBehaviour = new PacmanBehaviour(pacmanTile); var fileReader = new FileReader(); var mazeFactory = new MazeFactory(fileReader, tileTypeFactory); var gameSettingLoader = new GameSettingLoader(fileReader); var gameLogicValidator = new GameLogicValidator(); var gameEngine = new GameEngine(gameLogicValidator); var display = new Display(); var spriteFactory = new SpriteFactory(); var levelFactory = new LevelFactory(tileTypeFactory, display, spriteFactory, gameLogicValidator, gameEngine, playerInput, pacmanBehaviour, ghostBehaviour); var game = new Game(levelFactory, gameSettingLoader, display, mazeFactory, playerInput); game.PlayGame(); }
// Creates a board with only transparent tiles. Adds tiles starting at coordinate (0,0) private void CreateEmptyBoard() { gameBoard = new Tileable[NUM_COLUMNS, NUM_ROWS]; emptyBoardTiles = new EmptyTile[NUM_COLUMNS, NUM_ROWS]; // Save an empty tile for each position on the board for easy reuse // Fill all grid spaces with transparent (Empty) tiles for (int row = 0; row < NUM_ROWS; row++) { for (int column = 0; column < NUM_COLUMNS; column++) { float xCoordinate = column * TILE_SIZE; float yCoordinate = row * -TILE_SIZE; float zCoordinate = -1.0f; // Create the tile objects GameObject gridSquare = Instantiate(Resources.Load("Prefabs/opaqueSquare") as GameObject); EmptyTile emptyTile = gridSquare.AddComponent <EmptyTile>(); emptyTile.Initialize(this, xCoordinate, yCoordinate, zCoordinate); // Save the objects to the board gameBoard[column, row] = emptyTile; emptyBoardTiles[column, row] = emptyTile; } } }
public MapData(int width, int height) { tiles = new Structure[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { tiles [i, j] = new EmptyTile(); } } int midX = width / 2; int midY = height / 2; setTile(midX, midY, new PowerPlant()); setTile(midX + 1, midY, new Conduit()); setTile(midX - 1, midY, new Conduit()); setTile(midX, midY + 1, new Conduit()); setTile(midX, midY - 1, new Conduit()); setTile(midX + 1, midY + 1, new Miner()); setTile(midX - 1, midY + 1, new Miner()); setTile(midX + 1, midY - 1, new HeatLaser()); setTile(midX - 1, midY - 1, new HeatLaser()); }
//Contains all of the methods and steps that occur when an empty tile is clicked private void TileOnClick(RaycastHit2D hit) { //Gets the tile value data from the tile that's been clicked EmptyTile emptyTile = hit.transform.GetComponent <EmptyTile>(); Vector2Int tileValue = emptyTile.TileValue; //try to add to board array - if error, then end the current match. try { BoardState.AddPosition(tileValue, (int)GameManager.CurrentPlayer); } catch (Exception e) { Debug.LogError(e); GameManager.instance.GameError(); } //Record the move to game data GameDataRecorder.instance.AddPlayerMove(tileValue); //Call the tiles spawn function emptyTile.SpawnTile(); //Goes back to Game Manager which uses BoardState to check if the game is over and then calls the corresponding win/draw animation GameManager.instance.CheckBoardPositions(tileValue); }
public Map() { int xPos = 0; int yPos = 0; for (int i = 0; i < StringMap.Length; i++) { if (StringMap[i] != ' ' && char.IsWhiteSpace(StringMap[i])) { xPos = 0; yPos++; continue; } Room room = Room.None; if (int.TryParse(StringMap[i].ToString(), out int _room)) { room = (Room)_room; } Tiles[xPos, yPos] = new EmptyTile(new Position(xPos, yPos), StringMap[i] == 'X' ? 'X' : ' ', room); double chance = Random.NextDouble(); if (chance >= TRAP_CHANCE) { Tiles[xPos, yPos].HiddenTile = new TrapTile(new Position(xPos, yPos), TRAP, room); } xPos++; } }
public override void LoadContent(GameWindow window) { player = new Player(window, PickUp); cursor = TextureManager.getTexture2D("cursor"); cursorOffset = new Vector2(16, 16); for (int i = 0; i < tiles.GetLength(0); i++) { for (int j = 0; j < tiles.GetLength(1); j++) { if ((i == tiles.GetLength(0) / 2) && (j == tiles.GetLength(0) / 2)) { tiles[i, j] = new CenterTile(); } else { Tile tempE = new EmptyTile(); Tile tempR = new RockFarm(); tiles[i, j] = rnd.Next(0, 3) == 2 ? tempR : tempE; } //else if (j % 2 == i % 2) //{ // tiles[i, j] = new EmptyTile(); //} //else //{ // tiles[i, j] = new RockFarm(); //} tiles[i, j].LoadContent(window); tiles[i, j].position = new Vector2(tiles[i, j].size.X * (j - (tiles.GetLength(0) / 2)), tiles[i, j].size.Y * (i - (tiles.GetLength(1) / 2))); } } currentTile = tiles[1, 1]; // player.Player(window); }
public TileStatesFactory(EmptyTile tile) { tileSelected = new TileSelected(tile, this); tileHighlighted = new TileHighlighted(tile, this); tileIdle = new TileIdle(tile, this); cursorOnHighlightedTile = new CursorOnHighlightedTile(tile, this); awaitingMove = new TileAwaitingMove(tile, this); }
public void ToString_should_return_empty_tile_message() { var tile = new EmptyTile { Location = new Location(0, 0) }; tile.ToString().Should().Be("Tile [0, 0]: Empty"); }
private static ITileTypeFactory SetUp() { var wallTile = new WallTile(); var emptyTile = new EmptyTile(); var pelletTile = new PelletTile(); return(new TileTypeFactory(wallTile, emptyTile, pelletTile)); }
private void MoveDigger(Direction moveTo) { DiggerPosition += Points[(int)moveTo]; if (TileMap[DiggerPosition].Type == TileType.Dirt) { TileMap[DiggerPosition] = new EmptyTile(); } }
public void Unflagging_an_untouched_tile_should_do_nothing() { var tile = new EmptyTile(); tile.GetStatus().Should().Be(TileStatus.Untouched); tile.UnFlag(); tile.GetStatus().Should().Be(TileStatus.Untouched); }
public void Flagging_an_untouched_tile_should_flag_it() { var tile = new EmptyTile(); tile.GetStatus().Should().Be(TileStatus.Untouched); tile.Flag(); tile.GetStatus().Should().Be(TileStatus.Flagged); }
public void Clicking_a_mine_tile_should_mark_it_clicked() { var tile = new EmptyTile(); tile.GetStatus().Should().Be(TileStatus.Untouched); tile.Click(); tile.GetStatus().Should().Be(TileStatus.Revealed); }
public void Revealing_an_untouched_tile_should_set_status_to_clicked() { var tile = new EmptyTile(); tile.GetStatus().Should().Be(TileStatus.Untouched); tile.Reveal(); tile.GetStatus().Should().Be(TileStatus.Revealed); }
public void Revealing_a_clicked_tile_should_do_nothing() { var tile = new EmptyTile(); tile.Click(); tile.GetStatus().Should().Be(TileStatus.Revealed); tile.Reveal(); tile.GetStatus().Should().Be(TileStatus.Revealed); }
public void Clicking_a_mine_tile_should_remove_the_flag() { var tile = new EmptyTile(); tile.Flag(); tile.GetStatus().Should().Be(TileStatus.Flagged); tile.Click(); tile.GetStatus().Should().Be(TileStatus.Untouched); }
public void Flagging_a_flagged_tile_should_do_nothing() { var tile = new EmptyTile(); tile.Flag(); tile.GetStatus().Should().Be(TileStatus.Flagged); tile.Flag(); tile.GetStatus().Should().Be(TileStatus.Flagged); }
public void Unflagging_a_clicked_tile_should_throw_an_error() { var tile = new EmptyTile(); tile.Click(); tile.GetStatus().Should().Be(TileStatus.Revealed); var ex = Assert.Throws <InvalidOperationException>(() => tile.UnFlag()); ex.Message.Should().Be("Cannot un-flag a clicked tile."); }
public void Revealing_a_flagged_tile_should_set_status_to_clicked() { var tile = new EmptyTile(); tile.Flag(); tile.GetStatus().Should().Be(TileStatus.Flagged); tile.Reveal(); tile.GetStatus().Should().Be(TileStatus.Revealed); }
private static Board GetStartingTiles() { var tiles = new ITile[8, 8]; tiles[0, 0] = new OccupiedTile(new Rook(Team.Black)); tiles[1, 0] = new OccupiedTile(new Knight(Team.Black)); tiles[2, 0] = new OccupiedTile(new Bishop(Team.Black)); tiles[3, 0] = new OccupiedTile(new Queen(Team.Black)); tiles[4, 0] = new OccupiedTile(new King(Team.Black)); tiles[5, 0] = new OccupiedTile(new Bishop(Team.Black)); tiles[6, 0] = new OccupiedTile(new Knight(Team.Black)); tiles[7, 0] = new OccupiedTile(new Rook(Team.Black)); //Pawns tiles[0, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[1, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[2, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[3, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[4, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[5, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[6, 1] = new OccupiedTile(new Pawn(Team.Black)); tiles[7, 1] = new OccupiedTile(new Pawn(Team.Black)); for (var x = 0; x < 8; x++) { for (var y = 2; y < 6; y++) { tiles[x, y] = new EmptyTile(); } } tiles[0, 7] = new OccupiedTile(new Rook(Team.White)); tiles[1, 7] = new OccupiedTile(new Knight(Team.White)); tiles[2, 7] = new OccupiedTile(new Bishop(Team.White)); tiles[3, 7] = new OccupiedTile(new King(Team.White)); tiles[4, 7] = new OccupiedTile(new Queen(Team.White)); tiles[5, 7] = new OccupiedTile(new Bishop(Team.White)); tiles[6, 7] = new OccupiedTile(new Knight(Team.White)); tiles[7, 7] = new OccupiedTile(new Rook(Team.White)); tiles[0, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[1, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[2, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[3, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[4, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[5, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[6, 6] = new OccupiedTile(new Pawn(Team.White)); tiles[7, 6] = new OccupiedTile(new Pawn(Team.White)); return(new Board(tiles)); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) || InfoPanel.activeSelf) //saves on computation if infopanel is closed, and mouse is not clicked { if (!EventSystem.current.IsPointerOverGameObject()) //Does not work over UI { Ray ray = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); //Casts ray to point on screen from cursor RaycastHit hit; if (Physics.Raycast(ray, out hit, 100.0f)) { GameObject hitObject = hit.transform.gameObject; if (InfoPanel.activeSelf) //If info panel is active { tileInfo.UpdateInfo(hitObject); } if (Input.GetMouseButtonDown(0)) //If clicked { switch (clickType) //Switch to detemine what to do with the click. Clicktype is changed by UI buttons { case 0: //Destroy if (hitObject.GetComponent <CityTile>() != null && hitObject.tag != "TEmpty") { CityTile temp = hitObject.GetComponent <CityTile>(); temp.destroying = !hitObject.GetComponent <CityTile>().destroying; temp.ConstructionToggle(); } break; case 1: //Build Home case 2: //Build Shop case 3: //Build Factory //case 4: //Build Destroyed - Not possible case 5: //Build Power case 6: //Build Water case 7: //Build Road if (hitObject.GetComponent <EmptyTile>() != null) { EmptyTile temp = hitObject.GetComponent <EmptyTile>(); temp.destroying = !temp.destroying; temp.typeToBecome = clickType; temp.ConstructionToggle(); } break; } ; } } } } }
private IWorldObject[,] GenerateRandomMap(int height, int width) { IWorldObject[,] result = new IWorldObject[height, width]; Random random = new Random(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { switch (random.Next(8)) { case 0: result[x, y] = new EmptyTile("", "", new Point(x, y)); break; case 1: result[x, y] = new EmptyTile("", "", new Point(x, y)); break; case 2: result[x, y] = new EmptyTile("", "", new Point(x, y)); break; case 3: result[x, y] = new EmptyTile("", "", new Point(x, y)); break; case 4: result[x, y] = new Town("Town", "Big Town", new Point(x, y)); break; case 5: result[x, y] = new Town("Town", "Big Town", new Point(x, y)); break; case 6: result[x, y] = new Dungeon("Dungeon", "Scary Dungeon", new Point(x, y)); break; case 7: result[x, y] = new Water("Water", "Deep scart Water", new Point(x, y)); break; } } } return(result); }
private void CreateEmptyTiles(SpellswordGame game, string[] mapFile) { for (int i = 0; i < thisWorld.ySize; i++) { for (int j = 0; j < thisWorld.xSize; j++) { if (mapFile[i][j] == '1') { Point newPoint = new Point(j, i); EmptyTile tile = new EmptyTile(game, thisWorld, newPoint); emptyTiles.Add(tile); thisWorld.RegisterEntity(tile, newPoint); } } } }
public Chunk(int height) { m_tiles = new Tile[height][][]; for (int i = 0; i < height; i++) { m_tiles[i] = new Tile[c_chunkHeight][]; for (int j = 0; j < c_chunkHeight; j++) { m_tiles[i][j] = new Tile[c_chunkWidth]; for (int k = 0; k < c_chunkWidth; k++) { m_tiles[i][j][k] = new EmptyTile(); } } } }
public static Tile GetStaticTile(int tileID) { if (staticTiles == null) { staticTiles = new Dictionary <int, Tile>(); } if (!staticTiles.ContainsKey(tileID)) { if (tileID == 0) { EmptyTile.NewFloor(staticTiles); } if (tileID == 1) { Wall.NewWall(staticTiles); } } return(staticTiles[tileID]); }
public static BaseTile BuildTile(int x, int y, TileType tileType) { BaseTile result = null; Vector2 canvas = GetCanvasCoords(x, y); int canvasX = (int)canvas.X; int canvasY = (int)canvas.Y; switch (tileType) { case TileType.Empty: result = new EmptyTile(x, y, canvasX, canvasY); break; case TileType.Ground: result = new GroundTile(x, y, canvasX, canvasY); break; } return(result); }