示例#1
0
        private void Initalize()
        {
            // Initalize game variables
            Config        config;
            XmlSerializer xs = new XmlSerializer(typeof(Config));

            using (Stream s = File.OpenRead(configFilePath))
                config = (Config)xs.Deserialize(s);

            tableColumnCount = config.TableColumnCount;
            tableRowCount    = config.TableRowCount;
            mineCount        = config.MineCount;
            playerWon        = false;
            isFirstClick     = true;

            //System.Diagnostics.Process.Start("Config.txt");
            InitializeComponent();
            gameTable = this.tableLayoutPanel1;
            InitalizeTable(gameTable, tableColumnCount, tableRowCount);

            gameMap            = new MineMap(tableColumnCount, tableRowCount, mineCount);
            spawnedLabels      = new List <Label>();
            spawnedMineButtons = new List <MineButton>();
            explosiveButtons   = new List <MineButton>();

            MineButton.ClearFlagCount();

            // Make the first row a little thicker than the last row
            gameTable.RowStyles[0].Height = 100f / (float)tableRowCount * 2;
            gameTable.RowStyles[tableRowCount - 1].Height = 100f / (float)tableRowCount / 2;

            AddMineButtons(gameTable);
            int restartButtonColumnSpan = tableColumnCount % 2 == 0 ? 2 : 3;             //If even columns then two else three

            restartButton  = AddRestartButton(restartButtonColumnSpan, 0);
            flagCountLabel = AddFlagCountLabel(); flagCountLabel.ScaleFont();
        }