public void Draw(MapInfo map, GameInfo info) { //DrawHUD(info); DrawMap(map, info); //DrawMessages(); WritePanels(); }
public void DrawMap(MapInfo map, GameInfo info) { int viewWidth = 30; int viewHeight = 10; int viewX = info.ExtendedPlayerInfo.X - viewWidth / 2; int viewY = info.ExtendedPlayerInfo.Y - viewHeight / 2; if (viewX < 0) viewX = 0; if (viewY < 0) viewY = 0; if (viewX + viewWidth > map.MapWidth) viewX = map.MapWidth - viewWidth; if (viewY + viewHeight > map.MapLength) viewY = map.MapLength - viewHeight; for (int j = 0; j < viewHeight; j++) { char[] line = new char[viewWidth]; for (int i = 0; i < line.Length; i++) { TileInfo tile = map.Tiles[viewY + j][viewX + i]; if (tile.Player != null) { if (tile.Player.IsKilled) { char symbol = 'X'; ConsoleColor colour = ConsoleColor.Red; //tile.Player.Colour; MainPanel.Write(symbol, colour); } else { char symbol = tile.Player.Symbol; ConsoleColor colour = tile.Player.Colour; //tile.Player.Colour; MainPanel.Write(symbol, colour); } } else if (tile.Bullet != null) { char symbol = '.'; ConsoleColor colour = ConsoleColor.Yellow; MainPanel.Write(symbol, colour); } else { char symbol = tile.Symbol; ConsoleColor colour = tile.Colour; MainPanel.Write(symbol, colour); } } MainPanel.Write('\n', ConsoleColor.Gray); } int p = 1; }
public void BroadcastGameState() { List<PlayerInfo> playerInfos = new List<PlayerInfo>(); Game.Players.ForEach(player => playerInfos.Add(player.GetInfo())); List<BulletInfo> bulletInfos = new List<BulletInfo>(); Game.BulletList.ForEach(player => bulletInfos.Add(player.GetInfo())); Game.Players.ForEach(player =>{ try { GameInfo gameInfo = new GameInfo(); gameInfo.Players = playerInfos; gameInfo.ExtendedPlayerInfo = new ExtendedPlayerInfo() { X = player.X, Y = player.Y }; gameInfo.Bullets = bulletInfos; Game.Messages.ForEach(m => gameInfo.Messages.Add(m)); Messages.ForEach(m => gameInfo.Messages.Add(m)); string jsonGameInfo = JsonConvert.SerializeObject(gameInfo); Server.SendMessage(player, jsonGameInfo); } catch(Exception e) { Console.WriteLine("Bug"); } }); Game.Messages.Clear(); Messages.Clear(); }
public void DrawHUD(GameInfo game) { foreach(PlayerInfo player in game.Players) HUDPanel.Write(String.Format("{0}:{1} ", player.Name, player.Frags), player.Colour); //String.Format("Time {0:hh:mm:ss}\n", game.GameTime), ConsoleColor.Gray); }