예제 #1
0
파일: GameAPI.cs 프로젝트: cynic/HvZ
 public void Join(string gameName, IHumanAI ai)
 {
     if (g == null)
     {
         initializeGameWindow(gameName);
     }
     clientGame.AddHuman(ai);
     if (!CNG_called)
     {
         Join_called = true;
     }
 }
예제 #2
0
        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));
        }