public void LoadMap(string mapFile) { Array[] mapTiles = CnC.Helpers.CSVParser.getValues(mapFile, 1, 1); this.MapTiles = new List<MapTile>(); int x = 0; int y = 0; foreach (var col in mapTiles) { foreach (var row in col) { MapTile mapTile = new MapTile(); mapTile.CreatedAt = DateTime.Now; mapTile.UpdatedAt = DateTime.Now; mapTile.TerrainType = Convert.ToInt32(row); mapTile.Xpos = y; mapTile.Ypos = x; mapTile.IsAccessible = (mapTile.TerrainType < 10 || mapTile.TerrainType == 100); mapTile.IsSpawningPoint = (mapTile.TerrainType == 100); this.MapTiles.Add(mapTile); y++; } y = 0; x++; } this.VerticalTilesCount = y; this.HorizontalTilesCount = x; }
private void JoinGame(GameCommand cmdReceived, Player player, PlayerGame playerGame, Game game) { if (playerGame != null) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "User already joined game").Save(this.FAppPrivate); } else { if (game == null) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Game not found").Save(this.FAppPrivate); } else { if (game.PlayersInGame.Count >= game.MaxNumberOfPlayers) { new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Already too many players in the game").Save(this.FAppPrivate); } else { PlayerGame newPlayerGame = new PlayerGame(game, cmdReceived.UserId, player.NickName); foreach (MapTile tile in game.Map.MapTiles) { MapTile playerTile = new MapTile(); playerTile.TerrainType = -1;// tile.TerrainType; playerTile.UserId = newPlayerGame.UserId; playerTile.Xpos = tile.Xpos; playerTile.Ypos = tile.Ypos; newPlayerGame.Map.MapTiles.Add(playerTile); //set spawn, check if not occupied first if (newPlayerGame.Spawn == null && tile.IsSpawningPoint) { if (game.PlayersInGame.Where(c => c.Spawn.Xpos == tile.Xpos && c.Spawn.Ypos == tile.Ypos).Count() == 0) { //not used yet newPlayerGame.Spawn = playerTile; PlayerMapTile playerMapTile = new PlayerMapTile(game.Id, cmdReceived.UserId, playerTile); playerTile.TerrainType = 100; playerTile.IsSpawningPoint = true; playerTile.IsAccessible = true; playerMapTile.Save(this.FAppPrivate); } } } newPlayerGame.Save(this.FAppPrivate); game.PlayersInGame.Add(newPlayerGame); game.Save(this.FAppPublic); new CommandFeedback(cmdReceived, enCommandStatus.Accepted, "Joined the game").Save(this.FAppPrivate); } } } }
private void RedrawMapTile(MapTile tile) { PictureBox newBox; int tileSize = 20; if (mapTilePictures[tile.Xpos, tile.Ypos] == null) { newBox = new PictureBox(); mapTilePictures[tile.Xpos, tile.Ypos] = newBox; newBox.Left = tileSize * tile.Xpos; newBox.Top = tileSize * tile.Ypos; newBox.Width = tileSize; newBox.Height = tileSize; AddPictureBox(newBox); } else { newBox = mapTilePictures[tile.Xpos, tile.Ypos]; } if (tile.TerrainType == -1) { //unknown newBox.BackColor = Color.Black; } else { switch (tile.TerrainType) { case 30: //border newBox.BackColor = System.Drawing.ColorTranslator.FromHtml("#402121"); break; case 0: //grass newBox.BackColor = System.Drawing.ColorTranslator.FromHtml("#0df05d"); break; case 1: //sand newBox.BackColor = System.Drawing.ColorTranslator.FromHtml("#e1d11a"); break; case 100: //spawn newBox.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff"); break; case 20: //rocks newBox.BackColor = System.Drawing.ColorTranslator.FromHtml("#714148"); break; default: break; } if (tile.IsAccessible) { if (tile.IsSpawningPoint) { //green newBox.BackColor = Color.Orange; } newBox.ImageLocation = null; } } }