public MainWindow(Tile[][] tileset, int numMines) : base() { this.Title = "Yet Another Minesweeper Clone"; this.ClientSize = new System.Drawing.Size(512, 512); mines = numMines; this.tileset = tileset; hoveringTile = new Tile(); Mouse.ButtonDown += Mouse_ButtonDown; Mouse.ButtonUp += Mouse_ButtonUp; }
public void GenerateNumbers(Point location, Tile[][] tileset) { if (this != tileset[location.Y][location.X]) throw new ArgumentException("Location does not represent the current tile."); else if (Type != TileType.MINE) { int mines = 0; for (int i = location.Y - 1; i <= location.Y + 1; i++) { for (int j = location.X - 1; j <= location.X + 1; j++) { if (i >= 0 && i < tileset.Length && j >= 0 && j < tileset[0].Length && tileset[i][j].Type == TileType.MINE) mines++; } } if (mines > 0) this.Type = TileType.NUMBER; switch (mines) { case 1: this.tex = Resources.Textures["num1"]; break; case 2: this.tex = Resources.Textures["num2"]; break; case 3: this.tex = Resources.Textures["num3"]; break; case 4: this.tex = Resources.Textures["num4"]; break; case 5: this.tex = Resources.Textures["num5"]; break; case 6: this.tex = Resources.Textures["num6"]; break; case 7: this.tex = Resources.Textures["num7"]; break; case 8: this.tex = Resources.Textures["num8"]; break; } } }
public static void Main(string[] args) { int numMines = 10, tilesetX = 10, tilesetY = 10; foreach (string arg in args) { if (!string.IsNullOrEmpty(arg)) { if (arg[0] == '-') { switch (arg.Substring(1, 1)) { case "m": if (!int.TryParse(arg.Substring(2), out numMines)) numMines = 10; break; case "t": int xIndex = arg.IndexOf('x'); if (arg.IndexOf('x') != -1) { if (!int.TryParse(arg.Substring(2, xIndex - 2), out tilesetX)) tilesetX = 10; if (!int.TryParse(arg.Substring(2, xIndex - 2), out tilesetY)) tilesetY = 10; } break; case "h": if (arg.Substring(1) == "help") { Console.WriteLine("Proper usage for non-default mines/tileset size:"); Console.WriteLine("\tYetAnotherMinesweeper.exe -t10x10 -m20\n"); Console.WriteLine("Where -t__x__ is the size of the tileset and -m__ is the number of mines"); } break; } } } } Tile[][] tileset = new Tile[tilesetY][]; for (int i = 0; i < tileset.Length; i++) { tileset[i] = new Tile[tilesetX]; for (int j = 0; j < tileset[0].Length; j++) { tileset[i][j] = new Tile(); } } MainWindow window = new MainWindow(tileset, numMines); window.Run(); }
private void ShowAllBorderingEmpties(Tile startingTile) { Point pt = new Point(0, 0); bool found = false; //search for the starting tile for (int i = 0; i < tileset.Length && !found; i++) { for (int j = 0; j < tileset[0].Length && !found; j++) { if (tileset[i][j] == startingTile) { found = true; pt = new Point(j, i); break; } } } ShowAllBorderingEmpties(pt); }
protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); //TODO put up win/lose banners if (gameWon && !gameCleaned) { Mouse.ButtonUp -= Mouse_ButtonUp; Mouse.ButtonDown -= Mouse_ButtonDown; gameCleaned = true; } else if (gameOver && !gameCleaned) { foreach (Tile[] ta in tileset) { foreach (Tile t in ta) { t.MouseUp(); } } Mouse.ButtonUp -= Mouse_ButtonUp; Mouse.ButtonDown -= Mouse_ButtonDown; gameCleaned = true; } else if (!gameOver) { //mouse tracking code Point tileCoords = new Point((int)Math.Floor((float)Mouse.X * (float)tileset[0].Length / (float)ClientSize.Width), (int)Math.Floor((float)(ClientSize.Height - Mouse.Y) * (float)tileset.Length / (float)ClientSize.Height)); if (tileCoords.X < tileset[0].Length && tileCoords.Y < tileset.Length) { if (hoveringTile != tileset[tileCoords.Y][tileCoords.X]) { hoveringTile.Unhover(); hoveringTile = tileset[tileCoords.Y][tileCoords.X]; hoveringTile.Hover(); } } } }