public Bumpership(IInputHandler input, World world, object shape, string name, Vector spawnPosition) { this.input = input; this.world = world; Shape = shape; Name = name; this.spawnPosition = spawnPosition; Radius = 0.5; factor1 = 0.05; factor2 = 0.1; Spawn(); }
public static string Create(Bumpership player, World world, int iteration) { StringBuilder builder = new StringBuilder(); builder.AppendLine(BeginStateLine(iteration)); builder.AppendLine(YouIndexLine(world, player)); foreach (Bumpership bumpership in world.Bumperships) builder.AppendLine(BumpershipLine(bumpership)); foreach (Cell cell in world.Map.Grid) { if (cell.CellType != CellType.Attractor) continue; builder.AppendLine("STAR " + ConvertToString(cell.Position)); } builder.AppendLine(EndStateLine()); return builder.ToString(); }
public GameManager( GameSettings gameSettings, IInputHandler keyboardHandler, SocketManager socketManager, IGraphicsHandler graphics) { this.gameSettings = gameSettings; this.graphics = graphics; const int ticksPerSecond = 30; gameLoop = new GameLoop(5, ticksPerSecond); gameLoop.Update += Update; gameLoop.Render += Render; Map map = new Map(gameSettings.Map); world = new World(map); int countShip = 0; List<Bumpership> bumperships = gameSettings.Players.Take(world.Map.StartPositions.Count) .Select(p => CreateBumpership(p, keyboardHandler, socketManager, ref countShip)) .ToList(); world.AddShips(bumperships); }
private void SendMap(StringBuilder message, World world) { message.AppendFormat("BEGIN_MAP {0} {1}\n", world.Map.Width, world.Map.Height); for (int r = 0; r < world.Map.Height; r++) { for (int c = 0; c < world.Map.Width; c++) message.Append(GetCellAsChar(world.Map.Grid[c, r].CellType)); message.AppendLine(); } message.AppendLine("END_MAP"); SendMessage(message.ToString()); }
public void Update(int iteration, World world, Bumpership bumpership) { if (!IsConnected()) { Dispose(); return; } bumpership.Name = playerName; state = new { player = bumpership, world, iteration }; string messageReceived; while (commandQueue.TryDequeue(out messageReceived)) { if(messageReceived == null) continue; ParseMessage(messageReceived, bumpership); } }
public void Start(World world) { StringBuilder message = new StringBuilder(); SendMap(message, world); SendMessage("START\n"); }
private static string YouIndexLine(World world, Bumpership bumpership) { return "YOU {0}".Format(world.Bumperships.IndexOf(bumpership)); }