コード例 #1
0
 public static PlayGameState SetAvailableMovesAction(PlayGameState state, SetAvailableMovesAction action)
 {
     return(state with
     {
         AvailableMoves = action.MoveCount
     });
 }
コード例 #2
0
 protected override void OnInitialize(IGameContext context)
 {
     IntroductionState = new IntroductionGameState(this);
     QuestionState     = new QuestionGameState(this);
     PlayState         = new PlayGameState(this);
     ResultState       = new ResultGameState(this);
 }
コード例 #3
0
 public static PlayGameState OnSetShowPegNumbersAction(PlayGameState state, SetShowPegNumbersAction action)
 {
     return(state with
     {
         ShowPegNumbers = action.ShowNumbers
     });
 }
コード例 #4
0
        private void Awake()
        {
            var enemyPlacer = GetComponent <RandomEnemyPlacer>();

            enemyPlacer.PlaceRandomEnemies();

            _tileLayer = LayerMask.GetMask("Tiles");

            ReplayManager replayManager = new ReplayManager();

            _stateMachine = new StateMachine <GameStateBase>();

            var moveManager = new MoveManager <Piece>(Board);

            var playGameState = new PlayGameState(Board, moveManager);

            _stateMachine.RegisterState(GameStates.EnemyPhase1, new EnemyPhase1GameState(Board));
            _stateMachine.RegisterState(GameStates.EnemyPhase2, new EnemyPhase2GameState(Board));
            _stateMachine.RegisterState(GameStates.Play, playGameState);


            moveManager.Register(PlayerMoveCommandProvider.Name, new PlayerMoveCommandProvider(playGameState, replayManager));

            ConnectMoveCommandProviderView(moveManager);
            ConnectPieceViews(moveManager);
            ConnectTileViews(Board);
            ConnectBoardView(Board);

            _stateMachine.MoveTo(GameStates.EnemyPhase1);
        }
コード例 #5
0
        public void ShouldSpawnObjectsOnEntry()
        {
            var state = new PlayGameState(gameManagerMock.Object);

            state.OnEntry();
            gameManagerMock.Verify(foo => foo.SpawnMap());
            gameManagerMock.Verify(foo => foo.SpawnPlayer());
            gameManagerMock.Verify(foo => foo.FadeIn());
        }
コード例 #6
0
 public static PlayGameState OnRestart(PlayGameState state)
 {
     return(state with
     {
         Board = new Domain.PegBoard(),
         Moves = new Stack <PegMoveWithBoard>(),
         From = null,
         To = null,
         StartingHoleSelected = false
     });
 }
コード例 #7
0
        public static PlayGameState MoveMadeAction(PlayGameState state, MoveMadeAction action)
        {
            state.Moves.Push(action.MoveWithBoard);

            return(state with
            {
                Moves = state.Moves,
                Board = action.NewBoard,
                From = null,
                To = null
            });
        }
コード例 #8
0
        public void ShouldTransitionOnEvent()
        {
            var state = new PlayGameState(gameManagerMock.Object);

            state.OnEntry();
            for (int i = 0; i < 100; i++)
            {
                // Just run a bunch to show it's not transitioning
                Assert.IsNull(state.OnDuring());
            }
            state.HandleEvent(new PlayerReachedGoalEvent());
            Assert.IsTrue(state.OnDuring() is FadeOutState);
        }
コード例 #9
0
        public static PlayGameState SelectStartingHoleAction(PlayGameState state, SelectStartingHoleAction action)
        {
            var pegHole = state.Board.Holes.FirstOrDefault(x => x.Number == action.PegHole.Number);

            if (pegHole != null)
            {
                pegHole.Filled = false;
            }

            return(state with
            {
                Board = state.Board,
                StartingHoleSelected = true
            });
        }
コード例 #10
0
        public static PlayGameState UndoMoveAction(PlayGameState state)
        {
            if (state.Moves.Count > 0)
            {
                if (state.Moves.TryPop(out PegMoveWithBoard result))
                {
                    return(state with
                    {
                        From = null,
                        To = null,
                        Board = result.Board,
                        Moves = state.Moves
                    });
                }
            }

            return(state with
            {
                From = null,
                To = null
            });
        }
コード例 #11
0
        public static PlayGameState SelectPegAction(PlayGameState state, SelectPegAction action)
        {
            // Select Peg
            if (state.From == null)
            {
                return(state with
                {
                    From = action.PegHole
                });
            }

            // Deselect Peg
            if (state.From.Number == action.PegHole.Number)
            {
                return(state with
                {
                    From = null,
                    To = null
                });
            }

            // Change selected peg when already selected
            if (action.PegHole.Filled)
            {
                return(state with
                {
                    From = action.PegHole,
                    To = null
                });
            }

            // Selected hole is the To hole
            return(state with
            {
                To = action.PegHole
            });
        }
コード例 #12
0
 public PlayerMoveCommandProvider(PlayGameState playGameState, ReplayManager replayManager) : base(playGameState, new PlayerSwipeMoveCommand(replayManager), new PlayerTeleportMoveCommand(replayManager), new PlayerPushbackMoveCommand(replayManager), new PlayerLineAttackMoveCommand(replayManager))
 {
 }
コード例 #13
0
ファイル: Game1.cs プロジェクト: xingped/BomberBall
        /// <summary>
        /// 
        /// </summary>
        protected void UpdatePlayGameFirstPerson(GameTime gameTime)
        {
            UpdateKeyboardPlayGameFirstPerson();
            if (m_CurrentPlayGameState == PlayGameState.Running)
            {
                //update agent input
                ((Agent)m_World.Player).Update(m_CurrentKeyboardState, m_PreviousKeyboardState, m_World.Walls, m_World.Blocks);

                //update camera
                m_World.WorldCamera.Update(((Agent)m_World.Player).Heading, m_World.Player.Position, GraphicsDevice.Viewport.AspectRatio);
                m_World.ViewMatrix = m_World.WorldCamera.viewMatrix;
                m_World.ProjectionMatrix = m_World.WorldCamera.projectionMatrix;

                //game time is 2 minutes just like presentation allots
                if (gameTime.TotalGameTime.Minutes > 2)
                {
                    m_GameOverFlag = true;
                    m_WinFlag = false;
                    m_CurrentPlayGameState = PlayGameState.Paused;
                }

                //only win condidtion, all agents are dead
                if (m_World.Agents.Count == 0)
                {
                    m_GameOverFlag = true;
                    m_WinFlag = true;
                    m_CurrentPlayGameState = PlayGameState.Paused;
                }

                foreach(Agent agent in m_World.Agents)
                {
                    agent.Update();
                }
                //bombs stuff
                for (int i = 0; i < m_World.Bombs.Count; i++)
                {
                    ((Bomb)m_World.Bombs[i]).update(gameTime);

                    if (((Bomb)m_World.Bombs[i]).LifeTime <= 0)
                    {
                        // bombRemovalList.Add(i);
                        List<GameEntity> affectedByExplosion = m_World.explosion(((Bomb)m_World.Bombs[i]));
                        m_World.Bombs.RemoveAt(i);

                        foreach(GameEntity gameEntity in affectedByExplosion)
                        {

                            //if player gets hit by bomb game ends
                            if (m_World.Player.Equals(gameEntity))
                            {
                                m_GameOverFlag = true;
                                m_WinFlag = false;
                                m_CurrentPlayGameState = PlayGameState.Paused;
                            }

                            if (m_World.Bombs.Contains(gameEntity))
                            {

                                int bombIndex = m_World.Bombs.IndexOf((Bomb)gameEntity);
                                if (bombIndex != -1)
                                    ((Bomb)m_World.Bombs[bombIndex]).LifeTime = 0;

                            }

                            if (m_World.Blocks.Contains(gameEntity))
                            {
                                m_World.Blocks.Remove((Block)gameEntity);
                            }

                            if (m_World.Agents.Contains(gameEntity) && ((Agent)gameEntity).Invuln == false)
                            {
                                m_World.Agents.Remove((Agent)gameEntity);
                            }
                        }

                    }
                }
            }
        }
コード例 #14
0
ファイル: Game1.cs プロジェクト: xingped/BomberBall
        /// <summary>
        /// 
        /// </summary>
        protected void InitializePlayGamePerson()
        {
            //create the new map
            LevelGenerator LG = new LevelGenerator();
            LG.genLevel();
            m_World = new Map(Content, "Maps\\MapRand.ini");

            m_CurrentPlayGameState = PlayGameState.Running;

            //init game over flag
            m_GameOverFlag = false;
            m_WinFlag = false;
        }
コード例 #15
0
ファイル: Game1.cs プロジェクト: xingped/BomberBall
        /// <summary>
        /// 
        /// </summary>
        protected void InitializePlayGameTraining()
        {
            //instantiate a new map
            m_World = new Map(Content, "Maps//Map1.ini");

            //set the state to running
            m_CurrentPlayGameState = PlayGameState.Running;

            m_World.AverageFitness = new List<double>();
            m_World.BestFitness = new List<double>();
            int numWeights = ((Agent)m_World.Agents[0]).Brain.GetNumberWeights();
            List<int> splitPoints = ((Agent)m_World.Agents[m_World.NumAgents - 1]).Brain.CalculateSplitPoints();
            m_World.GeneticAlgorithm = new AgentGA(Params.POP_SIZE, Params.MUTATION_RATE, Params.CROSSOVER_RATE, numWeights, splitPoints);
            m_World.GenomePopulation = m_World.GeneticAlgorithm.Population;
            for (int i = 0; i < m_World.Agents.Count; i++)
            {
                ((Agent)m_World.Agents[i]).Brain.PutWeights(m_World.GenomePopulation[i].Weights);
            }

            ResetTrainingStrings();
        }
コード例 #16
0
ファイル: Game1.cs プロジェクト: xingped/BomberBall
 protected void UpdateKeyboardPlayGameFirstPerson()
 {
     if (m_CurrentPlayGameState == PlayGameState.Running)
     {
         if (!m_PreviousKeyboardState.IsKeyDown(Keys.Escape) && m_CurrentKeyboardState.IsKeyDown(Keys.Escape))
         {
             m_CurrentPlayGameState = PlayGameState.Paused;
         }
     }
     else if (m_CurrentPlayGameState == PlayGameState.Paused)
     {
         if (!m_PreviousKeyboardState.IsKeyDown(Keys.Enter) && m_CurrentKeyboardState.IsKeyDown(Keys.Enter))
         {
             if(!m_GameOverFlag)
                 m_CurrentPlayGameState = PlayGameState.Running;
             else
                 m_CurrentGameState = GameState.TeamMapSelection;
         }
         if (!m_PreviousKeyboardState.IsKeyDown(Keys.Escape) && m_CurrentKeyboardState.IsKeyDown(Keys.Escape))
         {
             m_CurrentGameState = GameState.TeamMapSelection;
         }
     }
 }
コード例 #17
0
 public EnemyMoveCommandProvider(PlayGameState playGameState, ReplayManager replayManager) : base(playGameState)
 {
 }
コード例 #18
0
ファイル: Game1.cs プロジェクト: xingped/BomberBall
        /// <summary>
        /// 
        /// </summary>
        protected void UpdateKeyboardPlayGameTraining()
        {
            if (!m_CurrentKeyboardState.IsKeyDown(Keys.LeftControl))
            {
                if (m_CurrentPlayGameState == PlayGameState.Running)
                {
                    if (!m_PreviousKeyboardState.IsKeyDown(Keys.Escape) && m_CurrentKeyboardState.IsKeyDown(Keys.Escape))
                    {
                        m_CurrentPlayGameState = PlayGameState.Paused;
                    }
                    if (KeyDownTwoInput(Keys.F1))
                    {
                        m_World.LoadNewMap("Maps//Map1.ini");
                    }
                    else if (KeyDownTwoInput(Keys.F2))
                    {
                        m_World.LoadNewMap("Maps//Map2.ini");
                    }
                    else if (KeyDownTwoInput(Keys.F3))
                    {
                        m_World.LoadNewMap("Maps//Map3.ini");
                    }
                    else if (KeyDownTwoInput(Keys.F5))
                    {
                        m_World.LoadNewMap("Maps//Map5.ini");
                    }
                    else if (KeyDownTwoInput(Keys.F6))
                    {
                        m_World.LoadNewMap("Maps//Map6.ini");
                    }
                    else if (KeyDownTwoInput(Keys.F7))
                    {
                        m_World.LoadNewMap("Maps//Map7.ini");
                    }
                    else if (KeyDownTwoInput(Keys.F12))
                    {
                        LevelGenerator LG = new LevelGenerator();
                        LG.genLevel();
                        m_World.LoadNewMap("Maps//MapRand.ini");
                    }

                }
                else if (m_CurrentPlayGameState == PlayGameState.Paused)
                {
                    if (!m_PreviousKeyboardState.IsKeyDown(Keys.Enter) && m_CurrentKeyboardState.IsKeyDown(Keys.Enter))
                    {
                        m_CurrentPlayGameState = PlayGameState.Running;
                    }
                    if (!m_PreviousKeyboardState.IsKeyDown(Keys.Escape) && m_CurrentKeyboardState.IsKeyDown(Keys.Escape))
                    {
                        m_CurrentGameState = GameState.ModeSelect;
                        m_CurrentPlayGameState = PlayGameState.None;
                    }
                }
            }
            else
            {
                if (KeyDownTwoInput(Keys.F1))
                {
                    m_World.ToggleSenseBombs();
                }
                else if(KeyDownTwoInput(Keys.F2))
                {
                    m_World.ToggleSenseAgents();
                }
            }
        }
コード例 #19
0
 public AbstractMoveCommandProvider(PlayGameState playGameState, params IMoveCommand <Piece>[] commands)
 {
     _commands      = commands.ToList();
     _playGameState = playGameState;
 }