/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); var cnfg = new MinesweeperConfig();; if (!File.Exists("config.json")) { cnfg.Width = 9; cnfg.Height = 9; cnfg.MineCount = 10; File.WriteAllText("config.json", JsonConvert.SerializeObject(cnfg)); } else { string json = File.ReadAllText("config.json"); cnfg = JsonConvert.DeserializeObject <MinesweeperConfig>(json); } if (cnfg.MineCount > cnfg.Width * cnfg.Height) { //Exit(); Environment.Exit(0); } Resize(cnfg.Width * 32, cnfg.Height * 32 + 64); SetState(new State1(this, cnfg)); }
public void Setup(MinesweeperConfig config) { Config = config; var cellwidth = config.CellWidth ?? 10; Width = config.Width ?? 100; Height = config.Height ?? 100; if (config.Columns != null) { Columns = config.Columns ?? 0; } else { Columns = (int)(Width / cellwidth); } if (config.Rows != null) { Rows = config.Rows ?? 0; } else { Rows = (int)(Height / cellwidth); } Grid = new MinesweeperGrid(Rows, Columns, cellwidth); }
public State1(Game parent, MinesweeperConfig config) : base(parent, config.Width * 32, config.Height * 32 + 64, Color.White) { //Setup grid GridWidth = config.Width; GridHeight = config.Height; MineCount = config.MineCount; //Associate load and unload events OnLoad += State1_OnStateLoad; OnDraw += State1_OnStateDraw; OnUpdate += State1_OnStateUpdate; //Setup variables _tileStates = new int[Total]; _proximity = new int[Total]; _remainingMines = MineCount; SetMines(); }