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()) ))); }
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> StageEntryPoint(OsState osState, IEnumerable ev) { var state = osState.StageState.As <GameManagementState>(); if (state.Status == GameManagementStatus.Initial) { return(SendCountdownRequest(osState, state)); } if (state.Status == GameManagementStatus.WaitCountdown) { return(ReceiveCountdownResponse(osState, state, ev.As <ApiCountdownResponse>())); } if (state.Status == GameManagementStatus.WaitCreate) { return(ReceiveCreateGameResponse(osState, state, ev.As <ApiCreateGameResponse>())); } if (state.Status == GameManagementStatus.WaitJoin) { return(ReceiveJoinGameResponse(osState, state, ev.As <ApiGameResponse>())); } if (state.Status == GameManagementStatus.WaitGameInfo) { return(ReceiveGameInfoResponse(osState, state, ev.As <ApiInfoResponse>())); } return(HandleUiEvent(osState, state, ev.As <V>())); }
public static ComputerCommand <OsState> RenderUi <TStageState>(this OsState osState, Func <OsState, TStageState, Control> createControl, TStageState state) where TStageState : IEnumerable { osState.StageState = state; var control = createControl(osState, state); return(WaitClick(osState, control.Screen)); }
private static ComputerCommand <OsState> RenderUI(OsState osState) { IEnumerable screen = AppControl(osState).Screen; osState.StageState = List(1); return(WaitClick(osState, screen)); }
private static ComputerCommand <OsState> StartReplay(OsState osState, PlanetWarsState state) { state.Status = PlanetWarsStatus.ReplayStarted; var log = state.GameLog; var tick = log.Ticks.Head(); state.Universe = new ApiUniverse(0, state.GameLog.Planet, tick.Ships); return(RenderUI(osState, state)); }
public static ComputerCommand <OsState> StageEntryPoint(OsState osState, IEnumerable ev) { var state = osState.StageState.As <MenuState>(); if (state.Status == MenuStatus.Initial) { return(RenderUI(osState)); } return(HandleUiEvent(osState, state, ev.As <V>())); }
private static ComputerCommand <OsState> ProcessEvent(OsState state, IEnumerable ev, IEnumerable <OsStage> stages) { var stageId = state.StageId; var stage = stages.GetByIndex(stageId); var stageUpdate = stage.Update; var stageResult = stageUpdate(state, ev); var state2 = stageResult.Memory; return(state2.StageId != stageId?ProcessEvent(state2, ev, stages) : stageResult); }
public static ComputerCommand <OsState> Update(OsState osState, IEnumerable ev) { var state = osState.StageState.As <RacesState>(); if (state.Status == RacesStatus.Initial) { state.Status = RacesStatus.Galaxy; return(RenderUI(osState, state)); } return(HandleUiEvent(osState, state, ev.As <V>())); }
public static ComputerCommand <OsState> StageEntryPoint(OsState osState, IEnumerable ev) { var state = osState.StageState.As <MatchingPuzzleState>(); if (state.Status == MatchingPuzzleStatus.Start) { state.Status = MatchingPuzzleStatus.InProgress; return(RenderUI(osState, state)); } return(HandleUiEvent(osState, ev.As <V>(), state)); }
private static Control AppControl(OsState osState) { return(CombineControls(List( ImageButton(Vec(-2, -2), AbcModule.os.BitDecodePixels(), RunTutorialEventId, 0), ImageButton(Vec(8, 0), AbcModule.burn.BitDecodePixels(), RunTTTPuzzleEventId, 0), ImageButton(Vec(16, 0), AbcModule.shoot.BitDecodePixels(), RunMatchingPuzzleEventId, 0), ImageButton(Vec(24, 0), AbcModule.attackShip3.BitDecodePixels(), GameManagementEventId, 0), ImageButton(Vec(32, 0), AbcModule.detonate.BitDecodePixels(), ShowGameEventId, 5505453539124369762) //, new Control(null, List(null, galaxy1.BitDecodePixels(), galaxy0.BitDecodePixels(), galaxy_1.BitDecodePixels())) //, new Control(null, List(null, galaxy1, galaxy0, galaxy_1)).ShiftControl(Vec(-128, -128)) ))); }
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)); }
public static ComputerCommand <OsState> EntryPoint(OsState osState, IEnumerable ev) { var state = osState.StageState.As <PlanetWarsState>(); if (state.Status == PlanetWarsStatus.Initial) { return(ShowStartScreen(osState, state)); } if (state.Status == PlanetWarsStatus.InitialForShowGame) { return(StartReplay(osState, state)); } if (state.Status == PlanetWarsStatus.InitialForStartGame) { return(StartGameWithSelectedShipMatter(osState, state)); } if (state.Status == PlanetWarsStatus.InitialForContinueGame) { state.Status = PlanetWarsStatus.UniverseShowed; return(RenderUI(osState, state)); } if (state.Status == PlanetWarsStatus.TutorialGameCreated) { return(ReceiveCreateResponse(osState, ev.As <ApiCreateGameResponse>(), state)); } if (state.Status == PlanetWarsStatus.TutorialGameJoined) { return(ReceiveJoinResponse(osState, ev.As <ApiGameResponse>(), state)); } if (state.Status == PlanetWarsStatus.GameStarted || state.Status == PlanetWarsStatus.CommandsSent) { return(ReceiveGameResponse(osState, ev.As <ApiGameResponse>(), state)); } if (state.Status == PlanetWarsStatus.GameInfoRequested) { return(ReceiveGameInfo(osState, ev.As <ApiInfoResponse>(), state)); } return(HandleUiEvent(osState, ev.As <V>(), state)); }
private static ComputerCommand <OsState> ReceiveGameInfo(OsState osState, ApiInfoResponse response, PlanetWarsState state) { if (response.SuccessFlag == 0) { return(osState.Error()); } state.GameLog = response.Log; if (state.Universe != null) { var players = response.Players; var me = players.Filter(p => p.Role == state.MyRole).Head(); state.TotalScore = me.Score + state.TotalScore; state.GameResultStatus = me.Status; state.Status = PlanetWarsStatus.FinalUniverseShowed; return(RenderUI(osState, state)); } state.Status = PlanetWarsStatus.ReplayStarted; var log = state.GameLog; var tick = log.Ticks.Head(); state.Universe = new ApiUniverse(0, state.GameLog.Planet, tick.Ships); return(RenderUI(osState, state)); }
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)); }
private static ComputerCommand <OsState> HandleApplySplit(OsState osState, PlanetWarsState state) { return(RenderUI(osState, state.WithoutShipSelection())); }
public static ComputerCommand <OsState> Error(this OsState osState) { osState.StageId = ErrorStageId; osState.StageState = EmptyList; return(WaitClickNoScreen(osState)); }
private static ComputerCommand <OsState> RunBonusPuzzle(OsState osState, RacesState state, in long bonusId)
private static ComputerCommand <OsState> ShowStartScreen(OsState osState, PlanetWarsState state) { return(CreateNewGame(osState, state)); //state.Status = PlanetWarsStatus.BeforeGameStartScreen; //return RenderUI(osState, state.WithoutShipSelection()); }
private static ComputerCommand <OsState> HandleUiEvent(OsState osState, V click, PlanetWarsState state) { var control = PlanetWarsUiModule.AppControl(state); var clickedArea = control.GetClickedArea(click); if (clickedArea == null) { return(RenderUI(osState, state)); } var eventId = clickedArea.EventId; if (eventId == PlanetWarsUiModule.StepEventId) { return(HandleClickOnPlay(osState, state)); } if (eventId == ApiCommandType.None.As <long>() + 1) { return(RemoveShipSelection(osState, state)); } if (eventId == ApiCommandType.Detonate.As <long>() + 1) { return(HandleDetonate(osState, state)); } if (eventId == ApiCommandType.BurnFuel.As <long>() + 1) { return(HandleShipCommand(osState, state, ApiCommandType.BurnFuel)); } if (eventId == ApiCommandType.Shoot.As <long>() + 1) { return(HandleShipCommand(osState, state, ApiCommandType.Shoot)); } if (eventId == ApiCommandType.SplitShip.As <long>() + 1) { return(HandleSplit(osState, state)); } if (eventId == PlanetWarsUiModule.SelectShipEventId) { return(HandleClickOnShip(osState, state, click)); } if (eventId == PlanetWarsUiModule.SelectBurnVectorEventId) { return(HandleBurnVectorSelected(osState, state, clickedArea.Argument)); } if (eventId == PlanetWarsUiModule.SelectShootTargetEventId) { return(HandleShootTargetSelected(osState, state, click)); } if (eventId == PlanetWarsUiModule.DecSplitMatterEventId) { return(HandleSplitMatterChange(osState, state, clickedArea.Argument, x => x / 2)); } if (eventId == PlanetWarsUiModule.IncSplitMatterEventId) { return(HandleSplitMatterChange(osState, state, clickedArea.Argument, x => x == 0 ? 1 : 2 * x)); } if (eventId == PlanetWarsUiModule.ApplySplitEventId) { return(HandleApplySplit(osState, state)); } if (eventId == PlanetWarsUiModule.StartGameEventId) { return(StartGameWithSelectedShipMatter(osState, state)); } return(RenderUI(osState, state)); }
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())); }
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)); }
private static ComputerCommand <OsState> ReceiveCountdownResponse(OsState osState, GameManagementState state, ApiCountdownResponse response) { state.CountdownTicks = response.Ticks; state.Status = GameManagementStatus.StartScreen; return(RenderUi(osState, state)); }
public static ComputerCommand <OsState> SwitchToStage(this OsState osState, long stageId, IEnumerable stageState) { osState.StageId = stageId; osState.StageState = stageState; return(WaitClickNoScreen(osState)); }
public static ComputerCommand <OsState> EntryPoint(OsState osState, IEnumerable ev) { return(OsModule.GenericEntryPoint(osState, ev, 0, new[] { Stage })); }
private static ComputerCommand <OsState> HandleSplitMatterChange(OsState osState, PlanetWarsState state, in long matterType, Func <long, long> change)
private static ComputerCommand <OsState> ErrorStage(OsState state, IEnumerable ev) { return(WaitClick(state, List(DrawSymbolByName("x")))); }