Ejemplo n.º 1
0
        private async void Tick(object state)
        {
            _lock.AcquireReaderLock(-1);
            await Task.WhenAll(_games.Select(async game => {
                game.Tick();
                await _persister.TryStore(game);
                await _eventHub.DispatchAll(game);
            }));

            _lock.ReleaseReaderLock();
        }
Ejemplo n.º 2
0
        public async Task Handle(StartGame command)
        {
            var room = await _roomFetcher.Fetch(RoomId.Parse(command.RoomId));

            if (room != null)
            {
                room.StartGame(new PlayerId(command.PlayerId));
                await _persister.TryStore(room);

                await _eventHub.DispatchAll(room);
            }
        }
Ejemplo n.º 3
0
        public async Task Handle(CreateRoom command)
        {
            Room room;
            var  playerId = new PlayerId(command.HostPlayerId);

            do
            {
                room = Room.CreateRoom(playerId, command.HostPlayerName, CharacterKey.Parse(command.SelectedCharacter));
            }while (!(await _persister.TryStore(room)));

            await _eventHub.DispatchAll(room);
        }
Ejemplo n.º 4
0
        public async Task Handle(JoinRoom command)
        {
            if (RoomCode.TryParse(command.RoomCode, out RoomCode code, out string error))
            {
                var room = await _fetcher.Fetch(code);

                if (room == null)
                {
                    await _eventHub.Dispatch(new JoinRoomFailed()
                    {
                        PlayerId = command.PlayerId,
                        RoomCode = command.RoomCode,
                        UserName = command.UserName,
                        Reason   = "Room not found"
                    });
                }
                else
                {
                    room.AddGuest(new PlayerId(command.PlayerId), command.UserName, CharacterKey.Parse(command.SelectedCharacter));
                    await _persister.TryStore(room);

                    await _eventHub.DispatchAll(room);
                }
            }