public override void Update(GameTime gameTime) { if (MouseHoverEnabled) { MouseState ms = Mouse.GetState(); // BattleshipsGame.GameWindow.Title = ms.Position.ToString(); if (_previousMouseTile != null) { _previousMouseTile.Highlight = false; } // Tile index if (AreaF.Contains(new Vector2(ms.X, ms.Y))) { Vector2 relativePos = new Vector2(ms.X - AreaF.X, ms.Y - AreaF.Y); Vector2 tileSize = new Vector2(Size.X / 10, Size.Y / 10); int yCount = Convert.ToInt32(relativePos.Y) / Convert.ToInt32(tileSize.Y); yCount = yCount * 10; int xCount = Convert.ToInt32(relativePos.X) / Convert.ToInt32(tileSize.X); int mouseTileIndex = xCount + yCount; if (mouseTileIndex <= 10 * 10 - 1) { _previousMouseTile = Tiles[mouseTileIndex]; _previousMouseTile.Highlight = true; } } } }
public override void Initialize() { Vector2 tileSize = new Vector2(Size.X / 10, Size.Y / 10); Tiles = new BoardTiles.BoardTile[10 * 10]; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { BoardTiles.WaterTile wt = new BoardTiles.WaterTile(new Vector2(x, y), tileSize, Position); Tiles[(y * 10) + x] = wt; } } }