Exemple #1
0
        private static ComputerCommand <OsState> HandleUiEvent(OsState osState, MenuState state, V click)
        {
            var control     = AppControl(osState);
            var clickedArea = control.GetClickedArea(click);

            if (clickedArea == null)
            {
                return(RenderUI(osState));
            }
            if (clickedArea.EventId == RunTutorialEventId)
            {
                return(osState.SwitchToStage(OsModule.PlanetWarsStageId, PlanetWarsModule.Stage.InitialStageState));
            }
            if (clickedArea.EventId == RunTTTPuzzleEventId)
            {
                return(osState.SwitchToStage(OsModule.TicTacToeStageId, TicTacToeModule.Stage.InitialStageState));
            }
            if (clickedArea.EventId == RunMatchingPuzzleEventId)
            {
                return(osState.SwitchToStage(OsModule.MatchingPuzzleStageId, MatchingPuzzleModule.Stage.InitialStageState));
            }
            if (clickedArea.EventId == GameManagementEventId)
            {
                return(osState.SwitchToStage(OsModule.GamesManagementStageId, GameManagementModule.Stage.InitialStageState));
            }
            if (clickedArea.EventId == ShowGameEventId)
            {
                return(osState.SwitchToStage(OsModule.PlanetWarsStageId,
                                             new PlanetWarsState(0, PlanetWarsStatus.InitialForShowGame, clickedArea.Argument, ApiPlayerRole.Viewer, 0, ApiPlayerStatus.NotJoined, null, null, ApiCommandType.None, null, null, null, null)));
            }
            return(RenderUI(osState));
        }
        public static ComputerCommand <OsState> Update(OsState state, IEnumerable ev)
        {
            var(stageStep, _) = state.StageState.As <IEnumerable <long> >();
            var(x, y)         = ev.As <(long, long)>();
            var newStageStep = Vec(x, y).InsideRect(Rect(-3, -3, 7, 7)) ? stageStep + 1 : stageStep;

            if (newStageStep >= 4)
            {
                return(state.SwitchToStage(OsModule.RacesStageId, RacesModule.Stage.InitialStageState));
            }
            state.StageState = List(newStageStep);
            return(WaitClick(state, RenderGalaxyCounter(newStageStep)));
        }
        private static ComputerCommand <OsState> HandleUiEvent(OsState osState, V click, MatchingPuzzleState state)
        {
            var control     = AppControl(state);
            var clickedArea = control.GetClickedArea(click);

            if (clickedArea == null)
            {
                return(RenderUI(osState, state));
            }
            var eventId      = clickedArea.EventId;
            var clickedIndex = clickedArea.Argument;

            if (eventId == ClosePuzzleEventId)
            {
                return(osState.SwitchToStage(OsModule.RacesStageId, RacesModule.Stage.InitialStageState));
            }
            if (eventId == ClickNumberEventId)
            {
                if (state.SelectedIndex == -1)
                {
                    state.SelectedIndex = clickedIndex;
                    return(RenderUI(osState, state));
                }
                var selectedNumber = state.Numbers.GetByIndex(state.SelectedIndex);
                var clickedNumber  = state.Numbers.GetByIndex(clickedIndex);
                var a = Min2(selectedNumber, clickedNumber);
                var b = Max2(selectedNumber, clickedNumber);
                var t = TransformMatch(a, b);
                state.SelectedIndex = -1;
                if (t == -1)
                {
                    state.FoundNumbers = null;
                    state.Key          = 0;
                    return(RenderUI(osState, state));
                }
                state.FoundNumbers = selectedNumber.AppendTo(clickedNumber.AppendTo(state.FoundNumbers));
                state.Key          = state.Key + (selectedNumber + clickedNumber) * Power2(t * 4);
                if (state.FoundNumbers.Len() != 16)
                {
                    return(RenderUI(osState, state));
                }
                state.Status       = MatchingPuzzleStatus.Finished;
                osState.SecretKeys = state.Key.AppendTo(osState.SecretKeys);
                return(RenderUI(osState, state));
            }

            return(RenderUI(osState, state));
        }
        private static ComputerCommand <OsState> HandleUiEvent(OsState osState, RacesState state, V click)
        {
            var control     = AppControl(osState, state);
            var clickedArea = control.GetClickedArea(click);

            if (clickedArea == null)
            {
                return(RenderUI(osState, state));
            }
            if (clickedArea.EventId == NextStageEventId)
            {
                return(osState.SwitchToStage(OsModule.GamesManagementStageId, GameManagementModule.Stage.InitialStageState));
            }
            if (clickedArea.EventId == ShowRaceDetailsId)
            {
                state.SelectedRaceIndex = clickedArea.Argument;
                return(RenderUI(osState, state));
            }
            if (clickedArea.EventId == CloseRaceDetailsEventId)
            {
                state.Status            = RacesStatus.Galaxy;
                state.SelectedRaceIndex = -1;
                return(RenderUI(osState, state));
            }
            if (clickedArea.EventId == RunBonusPuzzleEventId)
            {
                return(RunBonusPuzzle(osState, state, clickedArea.Argument));
            }
            if (clickedArea.EventId == ShowLasersSpecEventId)
            {
                state.Status = RacesStatus.ShowLasersSpec;
                return(RenderUI(osState, state));
            }
            if (clickedArea.EventId == ShowDetonateSpecEventId)
            {
                state.Status = RacesStatus.ShowDetonateSpec;
                return(RenderUI(osState, state));
            }
            return(RenderUI(osState, state));
        }
Exemple #5
0
        private static ComputerCommand <OsState> HandleUiEvent(OsState osState, GameManagementState state, V click)
        {
            var clickedArea = AppControl(osState, state).GetClickedArea(click);

            if (clickedArea == null)
            {
                return(RenderUi(osState, state));
            }
            if (clickedArea.EventId == OpenNextBattleEventId)
            {
                osState.OpenedBattlesCount = Min2(osState.OpenedBattlesCount + 1, Max2(osState.OpenedBattlesCount, pastBattles.Len() + 2));
                return(SendCountdownRequest(osState, state));
            }
            if (clickedArea.EventId == OpenGameManagementMenuEventId)
            {
                state.Status = GameManagementStatus.ManagementMenu;
                state.ManagementMenuPosition = GetManagementMenuCenterPosition(-3);
                return(RenderUi(osState, state));
            }
            if (clickedArea.EventId == StartTutorialsEventId)
            {
                return(osState.SwitchToStage(OsModule.PlanetWarsStageId, PlanetWarsModule.Stage.InitialStageState));
            }
            if (clickedArea.EventId == CloseEventId)
            {
                state.PlayerKey = 0;
                return(SendCountdownRequest(osState, state));
            }
            if (clickedArea.EventId == CreateGameEventId)
            {
                return(SendCreateGameRequest(osState, state));
            }
            if (clickedArea.EventId == StartEditingPlayerKeyEventId)
            {
                state.PlayerKey = 0;
                state.Status    = GameManagementStatus.EditingPlayerKey;
                return(RenderUi(osState, state));
            }
            if (clickedArea.EventId == EditingPlayerKeyEventId)
            {
                state.PlayerKey = clickedArea.Argument;
                return(RenderUi(osState, state));
            }
            if (clickedArea.EventId == ShowGameInfoEventId)
            {
                state.PlayerKey = clickedArea.Argument;
                return(SendGameInfoRequest(osState, state));
            }
            if (clickedArea.EventId == ShowPastGameInfoEventId)
            {
                var pastBattleIndex = clickedArea.Argument;
                state.PlayerKey = pastBattles.GetByIndex(pastBattleIndex).PlayerKey;
                state.ManagementMenuPosition = GetManagementMenuCenterPosition(pastBattleIndex);
                return(SendGameInfoRequest(osState, state));
            }
            if (clickedArea.EventId == StartReplayEventId)
            {
                var pwState = PlanetWarsModule.InitialForShowGame(state.PlayerKey, state.InfoResponse.Log);
                return(osState.SwitchToStage(OsModule.PlanetWarsStageId, pwState));
            }
            if (clickedArea.EventId == JoinGameEventId)
            {
                state.PlayerKey = clickedArea.Argument;
                return(SendJoinGameRequest(osState, state));
            }
            if (clickedArea.EventId == IncShipMatterEventId)
            {
                return(ChangeShipMatter(osState, state, clickedArea.Argument, x => x == 0 ? 1 : 2 * x));
            }
            if (clickedArea.EventId == DecShipMatterEventId)
            {
                return(ChangeShipMatter(osState, state, clickedArea.Argument, x => x / 2));
            }
            if (clickedArea.EventId == StartGameEventId)
            {
                state.PlayerKey = clickedArea.Argument;
                var pwState = PlanetWarsModule.InitialForStartGame(state.PlayerKey, state.GameResponse.GameInfo, state.ShipMatter);
                return(osState.SwitchToStage(OsModule.PlanetWarsStageId, pwState));
            }
            return(osState.RenderUi(AppControl, state));
        }