public void Jump(IUserRepository repository) { owner.Events.Add(new Event("jump", new string[] { })); // Clear connection with previous enemy or station if (owner.enemyShip != null) { owner.enemyShip.owner.enemyShip = null; owner.enemyShip = null; } else if (owner.spaceStation != null) { owner.spaceStation = null; } // Found another enemy, with some chance User nextEnemy; Random r = new Random(); if (r.NextDouble() <= 0.3) { nextEnemy = repository.Users.ToList()[r.Next(repository.Users.Count())]; if (nextEnemy.enemyShip == null && nextEnemy.spaceStation == null && nextEnemy != owner) { nextEnemy.enemyShip = this; this.owner.enemyShip = nextEnemy.ship; } } // Else, with some chance, jump to the space station else if (r.NextDouble() <= 0.3) { // TODD: delegate space station creation to something else SpaceStation station = new SpaceStation(); owner.spaceStation = station; } }
/// <summary> /// Makes one game step: executes all users code, updates all ships /// </summary> public void MakeStep() { foreach (User user in repository.Users) { if (!user.IsDead) { user.ship.makeStep(); try { user.engine.Execute(user.Code); if (user.consoleCommand != null) { user.engine.Execute(user.consoleCommand); user.consoleCommand = null; } } catch (Exception ex) { user.Log.Add("Exception while executing your code: " + ex.Message); user.consoleCommand = null; } } } foreach (User user in repository.Users) { if (user.ship.IsBroken()) { user.IsDead = true; if (user.enemyShip != null) { user.enemyShip.owner.enemyShip = null; user.enemyShip.owner.Credits += 10; } user.enemyShip = null; // TODD: delegate space station creation to something else SpaceStation station = new SpaceStation(); user.spaceStation = station; } } }