Пример #1
0
 public SetupMenu(LifeRuleset rulesetToModify, GameState currentGame)
 {
     InitializeComponent();
     helper = new SetupMenuHelper(rulesetToModify);
     helper.RecolorBoxes(LivingList, GrowingList, DyingList);
     backupEnteredTextString = "";
     currentLength           = currentGame.Length();
     EnteredLength.Text      = currentLength.ToString();
 }
Пример #2
0
        // Opens a LoadFile window, sets Rules to its results
        void LoadClick(object sender, RoutedEventArgs e)
        {
            PauseGameWhileMenuOpen();
            LoadFileWindow window = new LoadFileWindow(Rules);

            window.ShowDialog();
            Rules    = window.ReturnResult();
            MainGame = new GameState(MainGame.Length(), (int)LifeBoard.ActualWidth, (int)LifeBoard.ActualHeight, Rules);
            UnpauseGame();
        }
Пример #3
0
        // Opens a menu for setting the RuleSet and GameState
        void OpenSetupMenu(object sender, RoutedEventArgs e)
        {
            PauseGameWhileMenuOpen();

            SetupMenu setupPage = new SetupMenu(Rules, MainGame);

            setupPage.ShowDialog();
            Rules = setupPage.NewRuleset();
            int length = setupPage.NewGameStateLength();

            MainGame = new GameState(length, (int)LifeBoard.ActualWidth, (int)LifeBoard.ActualHeight, Rules);
            // creates new board, cannot reuse old rectangles
            DrawingHelper.DrawGameBoard(LifeBoard, MainGame);

            UnpauseGame();
        }
Пример #4
0
        // Initializes GameState with a length of the given gameWidth
        // Integer must be greater than 0, an ArgumentOutOfRangeException is thrown if it is less than 0
        public GameState(int gameWidth, int pixelsWidth, int pixelsHeight, LifeRuleset givenRules)
        {
            if (gameWidth <= 0 || pixelsWidth <= 0)
            {
                throw new ArgumentOutOfRangeException("Error creating new GameState: Given Integer less than or equal to 0");
            }

            if (pixelsWidth != pixelsHeight)
            {
                throw new ArgumentException("Error creating new GameState: Height and Width are not equal.");
            }

            LifeCellsHistory         = new Stack <bool[, ]>();
            CellLengthNum            = gameWidth;
            CellLengthPixels         = pixelsWidth;
            LifeCells                = new bool[gameWidth, gameWidth];
            CurrentRules             = givenRules;
            XIndexOfLastModifiedCell = -1;
            YIndexOfLastModifiedCell = -1;
        }