示例#1
0
        public async Task <Result <Player, JoinGameError> > JoinGameAsync(GameId gameId, string playerName)
        {
            var result = await _gameRepository.GetGameAndVersionAsync(gameId);

            return(await result.Map <Task <Result <Player, JoinGameError> > >(
                       async gameAndVersion =>
            {
                var(game, version) = gameAndVersion;

                if (game.Players.Count >= Models.Game.MaxNumberOfPlayers)
                {
                    return JoinGameError.GameFull;
                }

                var playerJoined = new PlayerJoined(playerName);
                await _eventRepository.AddEventAsync(gameId, playerJoined, version);

                var changedResources = playerJoined.ApplyAndGetModifiedResources(game);
                var changedResourceNames = ChangedResourcesResolver.GetResourceNames(changedResources);

                await _gameEventService.NotifyWorldUpdatedAsync(game.Id, changedResourceNames.ToArray());

                return Convert(game.Players.Last());
            },
                       readGameError =>
            {
                return readGameError switch
                {
                    ReadGameError.NotFound => Task.FromResult(new Result <Player, JoinGameError>(JoinGameError.GameNotFound)),
                    _ => throw new ArgumentOutOfRangeException(nameof(readGameError), readGameError, null)
                };
            }));
        public async void ConfirmAttendance(Event ev, string amName, string amDepartment, List <CredentialType> requestedCredentials)
        {
            // Show user event details
            var message = "Attendance Manager: " + amName + "\n Department: " + amDepartment + "\n Event Name: " + ev.Name + "\n Event Location: " + ev.Location + "\n Event Type: " + ev.EventType +
                          "\n Date: " + ev.Date + "\n Start Time: " + ev.StartTime + "\n End Time: " + ev.EndTime + "\n Description : " + ev.Description;
            var message2 = "Name \nEmail";

            await DisplayAlert("Event Details", message, "OK");

            bool answer = await DisplayAlert("Send Credentials?", message2, "Yes", "No");

            if (requestedCredentials != null && requestedCredentials.Count > 0)
            {
                foreach (CredentialType c in requestedCredentials)
                {
                    System.Diagnostics.Debug.WriteLine(c);
                }
            }
            else
            {
                await DisplayAlert("Required Credentials", "This Event does not require any credentials to attendance.", "OK");
            }

            // Add event to database if user chooses to attend
            if (answer)
            {
                //Add new attendace event to List and database and refresh ListView.
                await EventRepository.AddEventAsync(ev);

                attendanceEvents.Add(ev);
                AttendanceViewList.ItemsSource = attendanceEvents;

                // Send user Credentials to Web App
                SendCredentials(requestedCredentials);
            }
            else
            {
                await DisplayAlert("Declined Attendance", "You have decided not to attend this event", "OK");
            }
        }
示例#3
0
        public async Task <Result <Character, ExecuteActionError> > ExecuteActionAsync(GameId gameId, CharacterId characterId, Union <Move, UsePortal, ClearObstacle> action)
        {
            var result = await _gameRepository.GetGameAndVersionAsync(gameId);

            return(await result.Map(
                       async gameAndVersion =>
            {
                var(game, version) = gameAndVersion;

                var character = game.World.Characters.SingleOrDefault(characterCandidate => characterCandidate.Id == characterId);

                if (character == null)
                {
                    return ExecuteActionError.CharacterNotFound;
                }

                var createEventResult = action.Map(
                    move => Move(game, character, move.ActionName, move.NumberOfPathsToTravel),
                    usePortal => UsePortal(game, character, usePortal.PortalPath),
                    clearObstacle => ClearObstacle(game, character, clearObstacle.Obstacle));

                return await createEventResult.Map <Task <Result <Character, ExecuteActionError> > >(
                    async @event =>
                {
                    await _eventRepository.AddEventAsync(game.Id, @event, version);

                    var changedResources = @event.ApplyAndGetModifiedResources(game);

                    var changedResourceNames = ChangedResourcesResolver.GetResourceNames(changedResources);

                    await _gameEventService.NotifyWorldUpdatedAsync(game.Id, changedResourceNames.ToArray());

                    return CreateCharacter(character, game.World);
                },
                    error => Task.FromResult(new Result <Character, ExecuteActionError>(error)));
            },
                       readGameError => Task.FromResult(new Result <Character, ExecuteActionError>(ConvertToMoveCharacterError(readGameError)))));
        }