Example #1
0
    void OnGameStateChanged(object sender, GameOfLife.GameState oldState, GameOfLife.GameState newState)
    {
        if (PlayPauseButton == null)
        {
            return;
        }

        if ((GameOfLife)sender == m_GameOfLife)
        {
            switch (newState)
            {
            case GameOfLife.GameState.PLAY:
                PlayPauseButton.GetComponentInChildren <UnityEngine.UI.Text>().text = "Pause";
                break;

            case GameOfLife.GameState.PAUSE:
                PlayPauseButton.GetComponentInChildren <UnityEngine.UI.Text>().text = "Play";
                break;

            default:
                break;
            }
        }
    }
		public GameOfLife (GameSize size, GameState state)
			this._gameBoard = new GameBoard(size, state);
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime, InputState inputState)
        {
            Ticks++;

            if (this.Game.IsActive)
            {
                GUI.Update(inputState);

                UserInterfaceMessage guiMessage;
                while (GUI.GetMessage(out guiMessage))
                {
                    switch (guiMessage)
                    {
                        case UserInterfaceMessage.Play:
                            this.State = GameState.Playing;
                            break;
                        case UserInterfaceMessage.Pause:
                            this.State = GameState.Paused;
                            break;
                        case UserInterfaceMessage.Step:
                            this.State = GameState.Paused;
                            Map.Tick();
                            Ticks = 0;
                            break;
                        default:
                            string message = "Unrecognized GUI Message '" + guiMessage.ToString() + "'.";
                            throw new InvalidOperationException(message);
                    }
                }

                if (inputState.KeyDown(Keys.Space))
                {
                    if (this.State == GameState.Paused)
                    {
                        this.State = GameState.Playing;
                    }
                    else
                    {
                        this.State = GameState.Paused;
                    }
                }

                if (inputState.KeyDown(Keys.Escape))
                {
                    SetupMap();
                }

                Camera.Update(gameTime, inputState);

                if (!inputState.MouseInputHandled && inputState.LeftMouseUp())
                {
                    Point clickedCell = Camera.GetCellCoordinatesOfClick(inputState.MousePosition);
                    Map.FlipCell(clickedCell.X, clickedCell.Y);
                }
            }

            if (this.State == GameState.Playing && Ticks >= TickRate)
            {
                Map.Tick();
                Ticks = 0;
            }
        }
 private void SetupMap()
 {
     GameRules rules = GameRules.Standard();
     this.Map = new InfiniteMap(rules);
     this.State = GameState.Paused;
     this.Map.FlipCell(14, 12);
     this.Map.FlipCell(15, 12);
     this.Map.FlipCell(13, 13);
     this.Map.FlipCell(14, 13);
     this.Map.FlipCell(14, 14);
 }