/// <summary> /// Creates a user's first cell /// </summary> /// <param name="owner"></param> /// <returns></returns> public PlayerCell GenerateNewPlayerCell(User owner) { int ok = 0; int x, y, id; do { ok = 0; x = Helper.NextInt32(300, WorldValues.MapWidth - 300); y = Helper.NextInt32(300, WorldValues.MapHeight - 300); id = Helper.NextInt32(0, 150 * 1000); foreach (var pair in this.PlayerCells) { if (pair.Key != id) { // id is free ok++; } var otherCell = pair.Value; if (otherCell.GetDistanceToPoint(new Point(x, y)) > 125) { ok++; } } } while (ok != 2); return new PlayerCell(x, y, WorldValues.StartingMass, id, owner); }
public PlayerCell(int x, int y, int mass, int id, User owner) { this.x = x; this.y = y; this.Mass = mass; this.CID = id; this.Owner = owner; }
private void OnSuccessfulClientConnect(Client client) { client.Socket.Send(new byte[] { 1, 1 }); User tracker = new User(client); tracker.Thread = new Thread(tracker.HandleUser); tracker.Thread.IsBackground = true; tracker.Thread.Start(); }