Exemplo n.º 1
0
        public async Task <IActionResult> WaitingLobby(string login, Guid linkOfGuid)
        {
            var waitingRoom = _rooms.SelectRoom(linkOfGuid);

            if (waitingRoom == Guid.Empty)
            {
                return(NotFound());
            }

            var newElem = await _session.Get(linkOfGuid);

            if (newElem != null)
            {
                return(Ok());
            }

            var newSessionRoom = await _rooms.Get(waitingRoom);

            if (newSessionRoom.Player1 == login)
            {
                return(NotFound());
            }

            newSessionRoom.Player2 = login;
            await _session.AddWithGuidAsync(newSessionRoom.Guid, newSessionRoom);

            _logger.LogInformation($"{login} join into private game with {linkOfGuid}");
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Guid> > StartGame(string login)
        {
            _logger.LogInformation($"{login} try to find a room for random play ");

            var room = _rooms.TakeLastRoom();

            if (room.Value == null)
            {
                var newRoom = new Room()
                {
                    Guid    = Guid.NewGuid(),
                    Player1 = login,
                    Player2 = null
                };
                await _rooms.AddWithGuidAsync(newRoom.Guid, newRoom);

                _logger.LogInformation($"new room created by {login} he is waiting for player ");
                return(newRoom.Guid);
            }

            room.Value.Player2 = login;
            await _session.AddWithGuidAsync(room.Value.Guid, room.Value);

            _logger.LogInformation($" {login} joined to {room.Value.Player1} , and they created a session ");

            await _rooms.DeleteAsync(room.Key);

            return(room.Value.Guid);
        }