예제 #1
0
 private static Control TutorialsControl(OsState osState, GameManagementState state)
 {
     return(CombineControls(List(
                                ImageButton(Vec(-3, -3), AbcModule.battle.BitDecodePixels(), StartTutorialsEventId, 0),
                                FadedStatic(Vec(-2, -9), AbcModule.x.BitDecodePixels())
                                )));
 }
예제 #2
0
        private static Control BattlesHistoryControl(OsState osState, GameManagementState state)
        {
            var openedBattlesCount = osState.OpenedBattlesCount;
            var timeline           = TimelineControl(openedBattlesCount, pastBattles.Len(), state.CountdownTicks);
            var pastBattleCount    = pastBattles.Len();
            var ellipsis           =
                openedBattlesCount > 0
                    ? FadedStatic(GetManagementMenuCenterPosition(pastBattleCount).AddX(-3), BitEncodeSymbol("...").BitDecodePixels())
                    : new Control(null, null);

            var pastBattleControls =
                ellipsis.AppendTo(timeline.AppendTo(
                                      pastBattles
                                      .Filter(battle => battle.BattleIndex >= pastBattleCount - openedBattlesCount)
                                      .Map(b => BattlesItemControl(b.BattleIndex, b.PlayerKey, b.NewPlayerIndex == 0))));

            if (openedBattlesCount > pastBattleCount)
            {
                var futureBattle = FutureBattlesItemControl(pastBattles.Head().Race1);
                return(CombineControls(futureBattle.AppendTo(pastBattleControls)));
            }
            return(CombineControls(pastBattleControls));
        }
예제 #3
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));
        }
예제 #4
0
        private static Control AppControl(OsState osState, GameManagementState state)
        {
            var historyControl   = BattlesHistoryControl(osState, state);
            var galaxy           = ImageButton(Vec(-3, -3), AbcModule.os.BitDecodePixels(), OpenNextBattleEventId, 0);
            var tutorialsControl = TutorialsControl(osState, state);
            var battleControl    = BattleControl(osState, state);
            var status           = state.Status;

            if (status == GameManagementStatus.StartScreen)
            {
                if (osState.OpenedBattlesCount == pastBattles.Len() + 2)
                {
                    return(CombineControls3(
                               galaxy,
                               tutorialsControl.ShiftControl(GetManagementMenuCenterPosition(-2)),
                               historyControl));
                }
                if (osState.OpenedBattlesCount == pastBattles.Len() + 3)
                {
                    return(CombineControls4(
                               galaxy,
                               battleControl.ShiftControl(GetManagementMenuCenterPosition(-3)),
                               tutorialsControl.ShiftControl(GetManagementMenuCenterPosition(-2)),
                               historyControl));
                }
                return(CombineControls2(
                           galaxy,
                           historyControl));
            }
            var fadedHistory          = historyControl.FadeControl().FadeControl();
            var menuOrigin            = state.ManagementMenuPosition;
            var managementMenuControl = ManagementMenuControl(osState, state);

            if (status == GameManagementStatus.ManagementMenu)
            {
                return(CombineControls2(
                           fadedHistory,
                           managementMenuControl.ShiftControl(menuOrigin)));
            }
            if (status == GameManagementStatus.EditingPlayerKey)
            {
                return(CombineControls3(
                           PlayerKeyInputControl(osState, state).ShiftControl(menuOrigin),
                           fadedHistory,
                           managementMenuControl.FadeControl().ShiftControl(menuOrigin)));
            }
            if (status == GameManagementStatus.GameCreated)
            {
                return(CombineControls3(
                           CreatedGameControl(osState, state).ShiftControl(menuOrigin),
                           battleControl.ShiftControl(menuOrigin),
                           fadedHistory));
            }
            if (status == GameManagementStatus.ShowStartingGame)
            {
                return(CombineControls3(
                           StartGameControl(osState, state).ShiftControl(menuOrigin),
                           battleControl.ShiftControl(menuOrigin),
                           fadedHistory));
            }
            if (status == GameManagementStatus.ShowFinishedGame)
            {
                var playerKeyControl = EnteredPlayerKeyControl(state).ShiftControl(menuOrigin);
                var isPastGame       = IsPastGame(state.PlayerKey);
                return(CombineControls4(
                           ShowFinishedGameControl(state).ShiftControl(menuOrigin),
                           isPastGame ? playerKeyControl.FadeControl() : playerKeyControl,
                           battleControl.ShiftControl(menuOrigin),
                           fadedHistory));
            }
            return(Static(Vec(0, 0), AbcModule.x.BitDecodePixels()));
        }
예제 #5
0
 private static ComputerCommand <OsState> ReceiveCountdownResponse(OsState osState, GameManagementState state, ApiCountdownResponse response)
 {
     state.CountdownTicks = response.Ticks;
     state.Status         = GameManagementStatus.StartScreen;
     return(RenderUi(osState, state));
 }