Exemplo n.º 1
0
        private void start(string gatewayAddress, string gameName, bool create)
        {
            int myCount = count++;
            var gateway = new Gateway(gatewayAddress, true);
            ClientSiteManager clientManager = new ClientSiteManager(gateway);
            ClientGameManager gameManager = new ClientGameManager(gateway);
            ClientChatManager chatManager = new ClientChatManager(gateway);
            ClientDebugManager debugManager = new ClientDebugManager(gateway);
            clientManager.Login(userName = randomString(10), "");
            clientManager.OnLogin += (user, response) => {
                Console.WriteLine("Success: " + response.Successful + "    " + user.UserName + myCount);
                                         if (create)
                                             clientManager.CreateRoom(new CreateRoomRequest("Sevens", gameName));
                                         else {
                                             Global.SetTimeout(() => { clientManager.JoinRoom(new RoomJoinRequest("Sevens", gameName)); },
                                                               3000);
                                         }
                                     };
            clientManager.OnGetRoomsReceived += (user, response) => {
                                                    /*     foreach (var room in response.Rooms) {
                    if (room.Players.Count < 6) {
                        clientManager.JoinRoom(new RoomJoinRequest("Sevens", room.RoomName));
                        return;
                    }
                }*/
                                                };

         
            clientManager.OnRoomJoined += (user, response) => {
                Console.WriteLine("joined " + response.Room.Players.Count + " Players");
 
                                                  if (response.Room.Players.Count == 6)
                                                      clientManager.StartGame(new StartGameRequest());
                                              
                                          };
            clientManager.OnGetRoomInfoReceived += (user, response) => {
                                                       
                                                   };
            gameManager.OnGameStarted += (user, model) => { Console.WriteLine("Game Started: " + model.RoomID + "  " + userName); };

            gameManager.OnGameOver += (user, model) => { 
                                          gateway.Close();
                if(create)
                                          runGame(); 
                                      };

            gameManager.OnAskQuestion += (user, model) => {
                Console.WriteLine("Question Asked: " + user.UserName + "   Num Of Answers: " + model.Answers.Length);
                                             gameManager.AnswerQuestion(new GameAnswerQuestionModel(1));
                                         };
            gameManager.OnUpdateState += (user, s) => {
                                             //Console.Log("state updated ");
                                         };
        }
Exemplo n.º 2
0
 public GatewayService(string serverUrl)
 {
     Gateway = new Gateway(serverUrl, false);
 }