Exemple #1
0
        public void Subscribe()
        {
            Player player = new Player()
            {
                id = Context.ClientId
            };

            //looking for room
            if (_GameManager.AnyOpenRooms())
            {
                //room found, joining room
                Caller.alertMsg("Room found, joining room...");

                GameRoom openRoom = _GameManager.JoinOpenRoom(player);

                // begin game
                Clients[openRoom.FirstUser.id].alertMsg("Game has begun, your 'X'");
                Clients[openRoom.FirstUser.id].beginGame('x');
                Clients[openRoom.SecondUser.id].alertMsg("Game has begun, your 'O'");
                Clients[openRoom.SecondUser.id].beginGame('o');
            }
            else
            {
                // no rooms found, waiting for another player
                Caller.alertMsg("No rooms found, creating room..");
                _GameManager.CreateRoom(player);
                Caller.alertMsg("Waiting for another player to join...");
            }
        }