Esempio n. 1
0
 public Game(GameDifficulty d)
 {
     rand = new Random();
     Global.gameOver = false;
     currentDifficulty = d;
     grid = new CellElement[currentDifficulty.sideX, currentDifficulty.sideY];
     lost = true;
     first = true;
     amountOfFlags = currentDifficulty.Bombs;
     for (int i = 0; i < currentDifficulty.sideX; i++)
     {
         for (int j = 0; j < currentDifficulty.sideY; j++)
         {
             grid[i, j] = new CellElement(Global.startingX + i * Global.constMultiplier, Global.startingY + j * Global.constMultiplier);
             grid[i, j].cellClicked += new CellClickedHandler(openCell);
             grid[i, j].gameEnd += new EndGameHandler(gameOver);
             grid[i, j].gameStart += new OpenedCellHandler(cellHasBeenOpened);
             grid[i, j].flagEdit += new FlagHandler(changeFlagValue);
             grid[i, j].firstClick += new PlaceTheBombsHandler(firstClick);
             grid[i, j].CurrentCell.X = i;
             grid[i, j].CurrentCell.Y = j;
         }
     }
 }
Esempio n. 2
0
        private void newGame()
        {
            timer.Stop();
            time = 0;
            this.labelTime.Text = "0";
            settings = new Settings();

            if (!first)
            {
                foreach (CellElement cell in currentGame.Grid)
                {
                    this.Controls.Remove(cell);
                }
            }
            else
            {
                first = false;
            }

            RW.getDifficulty();
            GameDifficulty currentGameDifficulty = new GameDifficulty(RW.Difficulty);
            this.Height = Global.bottomPanel + (currentGameDifficulty.sideY + 1) * Global.constMultiplier + Global.startingY;
            this.Width = (currentGameDifficulty.sideX + 1) * Global.constMultiplier + Global.startingX;
            settings.difficultyLevelChanged += new NewGameHandler(newGame);
            this.labelBombs.Location = new Point(Global.bombsLocConst, currentGameDifficulty.sideY * Global.constMultiplier + Global.startingY + Global.locConst);
            this.labelTime.Location = new Point(Global.timeLocConst, currentGameDifficulty.sideY * Global.constMultiplier + Global.startingY + Global.locConst);
            currentGame = new Game(currentGameDifficulty);

            foreach (CellElement cell in currentGame.Grid)
            {
                this.Controls.Add(cell);
            }

            if (RW.Difficulty == 0)
                labelBombs.Text = "10";

            else if (RW.Difficulty == 1)
                labelBombs.Text = "40";

            else
                labelBombs.Text = "99";
        }