84 lines
2 KiB
C#
84 lines
2 KiB
C#
using System;
|
|
|
|
namespace Minesweeper {
|
|
class Game {
|
|
Board board;
|
|
|
|
public Game(string[] args) {
|
|
board = new Board(Board.Difficulty.Easy);
|
|
}
|
|
|
|
public void Run() {
|
|
board.Generate();
|
|
board.Print();
|
|
}
|
|
}
|
|
|
|
class Board {
|
|
public enum Difficulty {
|
|
Easy,
|
|
Medium,
|
|
Hard
|
|
}
|
|
|
|
private char[,] board;
|
|
private int width;
|
|
private int height;
|
|
private int mineRNG;
|
|
|
|
private Random rng = new Random();
|
|
|
|
// For Difficulty-scaled Boards
|
|
public Board(Difficulty difficulty) {
|
|
switch(difficulty) {
|
|
case Difficulty.Easy:
|
|
mineRNG = 10;
|
|
|
|
width = 25;
|
|
height = 25;
|
|
break;
|
|
|
|
case Difficulty.Medium:
|
|
mineRNG = 7;
|
|
|
|
width = 35;
|
|
height = 35;
|
|
break;
|
|
case Difficulty.Hard:
|
|
mineRNG = 5;
|
|
|
|
width = 50;
|
|
height = 50;
|
|
break;
|
|
}
|
|
|
|
board = new char[width, height];
|
|
}
|
|
// For Custom Boards
|
|
public Board(int width, int height) {
|
|
board = new char[width, height];
|
|
this.width = width;
|
|
this.height = height;
|
|
}
|
|
|
|
public void Generate() {
|
|
for (int y = 0; y < width; y++) {
|
|
for (int x = 0; x < height; x++) {
|
|
if (rng.Next(mineRNG) == 0)
|
|
board[x, y] = 'b';
|
|
else
|
|
board[x, y] = ' ';
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Print() {
|
|
for (int y = 0; y < width; y++) {
|
|
for (int x = 0; x < height; x++)
|
|
Console.Write(board[x, y]);
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
}
|
|
}
|