Esempio n. 1
0
 public static Control AppControl(PlanetWarsState state)
 {
     if (state.Status == PlanetWarsStatus.BeforeGameStartScreen)
     {
         return(StartScreenControl(state));
     }
     return(UniverseControl(state));
 }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 public static Control StartScreenControl(PlanetWarsState state)
 {
     if (state.Level == 0)
     {
         return(StepIconControl());
     }
     return(CombineControls2(
                StepIconControl(),
                UpperTutorialHintControl(state, null)));
 }
Esempio n. 4
0
        private static Control SplitMatterSelectionControl(PlanetWarsState state)
        {
            var ship        = state.SelectedShip;
            var cmd         = state.Commands.Filter(c => c.ShipId == ship.ShipId && c.CommandType == ApiCommandType.SplitShip).Head().As <ApiSplitCommand>();
            var matterMain  = ship.Matter;
            var matterSplit = cmd.NewShipMatter;
            var origin      = ship.Position.AddVec(right);

            return(CombineControls(List(
                                       ImageButton(Vec(-7, -2), split.BitDecodePixels(), ApiCommandType.SplitShip.As <long>() + 1, 0),
                                       MatterSelectorControl(Vec(0, 0), matterMain.Fuel, matterSplit.Fuel, 0),
                                       MatterSelectorControl(Vec(6, 0), matterMain.Lasers, matterSplit.Lasers, 1),
                                       MatterSelectorControl(Vec(12, 0), matterMain.Radiators, matterSplit.Radiators, 2),
                                       MatterSelectorControl(Vec(18, 0), matterMain.Engines, matterSplit.Engines, 3),
                                       ImageButton(Vec(26, -2), applySplit.BitDecodePixels(), ApplySplitEventId, 0)
                                       )).ShiftControl(origin.AddVec(Vec(5, 0))));
        }
Esempio n. 5
0
        public static Control UniverseControl(PlanetWarsState state)
        {
            var universeControlWithoutMenus = UniverseControlWithoutMenus(state, state.MyRole == ApiPlayerRole.Viewer);

            if (state.SelectedShip == null)
            {
                return(universeControlWithoutMenus);
            }

            var universeWithOpenCommandsMenu = CombineControls(List(
                                                                   ShipMenuControl(state),
                                                                   ShipControl(state.SelectedShip),
                                                                   universeControlWithoutMenus.FadeControl()
                                                                   ));

            if (state.EditingCommand == ApiCommandType.BurnFuel)
            {
                return(CombineControls(List(
                                           universeWithOpenCommandsMenu.FadeControl(),
                                           BurnVectorsControl(state)
                                           )));
            }
            if (state.EditingCommand == ApiCommandType.Shoot)
            {
                return(CombineControls(List(
                                           universeWithOpenCommandsMenu.FadeControl(),
                                           ShootTargetControl()
                                           )));
            }
            if (state.EditingCommand == ApiCommandType.SplitShip)
            {
                return(CombineControls(List(
                                           universeWithOpenCommandsMenu.FadeControl(),
                                           SplitMatterSelectionControl(state)
                                           )));
            }
            return(universeWithOpenCommandsMenu);
        }
Esempio n. 6
0
 private static ComputerCommand <OsState> HandleSplitMatterChange(OsState osState, PlanetWarsState state, in long matterType, Func <long, long> change)
Esempio n. 7
0
 private static ComputerCommand <OsState> HandleApplySplit(OsState osState, PlanetWarsState state)
 {
     return(RenderUI(osState, state.WithoutShipSelection()));
 }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
 private static ComputerCommand <OsState> ShowStartScreen(OsState osState, PlanetWarsState state)
 {
     return(CreateNewGame(osState, state));
     //state.Status = PlanetWarsStatus.BeforeGameStartScreen;
     //return RenderUI(osState, state.WithoutShipSelection());
 }
Esempio n. 10
0
        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));
        }