public void Join(string gameName, IHumanAI ai) { if (g == null) { initializeGameWindow(gameName); } clientGame.AddHuman(ai); if (!CNG_called) { Join_called = true; } }
public void AddHuman(IHumanAI ai) { var guid = Guid.NewGuid().ToString(); playerAdded += new Action <uint, string>((playerId, corr) => { if (corr != guid) { return; // not the human we're looking for! } var player = new HumanPlayer(connection, playerId, map); var askAI = new Action(() => { if (map.humans.ContainsKey(playerId)) { ai.DoSomething(player, new List <IWalker>(map.Zombies), new List <IWalker>(map.Humans.Where(x => x.Id != playerId)), new List <ITakeSpace>(map.Obstacles), new List <ResupplyPoint>(map.ResupplyPoints)); } }); requestDecision += askAI; world.OnPlayerRemoved += (_, args) => { if (args.PlayerId != playerId) { return; } requestDecision -= askAI; scoreboard[playerId] = Tuple.Create(scoreboard[playerId].Item1, (DateTime.Now - DateTime.FromBinary(scoreboard[playerId].Item2)).Ticks); }; noAction += (id, s) => { if (id == playerId) { ai.Failure(s); } }; world.OnEntityCollision += (_, e) => { if (e.PlayerId == playerId) { ai.Collision(player, e.CollidedWith); } }; world.OnEdgeCollision += (_, e) => { if (e.PlayerId == playerId) { ai.Collision(player, e.Edge); } }; }); connection.Send(Command.NewHumanJoin(gameName, guid, ai.Name)); }