aboutsummaryrefslogtreecommitdiff
path: root/TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs
diff options
context:
space:
mode:
authorlempamo <[email protected]>2017-07-26 19:59:45 -0500
committerGitHub <[email protected]>2017-07-26 19:59:45 -0500
commitbd7604e6a8c13e9cee05614e64b8eadd68b1c8c9 (patch)
tree0437a338ff22d6458b0d87c8f323751eb36fb3f3 /TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs
parenta852b2c7f2bb372a89e78e805298c33c00ebe924 (diff)
parentcc5a8d36ceac1567eebe946c3c6cbd0813a854c1 (diff)
downloadhistacom2-bd7604e6a8c13e9cee05614e64b8eadd68b1c8c9.tar.gz
histacom2-bd7604e6a8c13e9cee05614e64b8eadd68b1c8c9.tar.bz2
histacom2-bd7604e6a8c13e9cee05614e64b8eadd68b1c8c9.zip
Merge pull request #138 from jtsshieh/master
VERY VERY VERY BASIC Minesweeper
Diffstat (limited to 'TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs')
-rw-r--r--TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs201
1 files changed, 201 insertions, 0 deletions
diff --git a/TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs b/TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs
new file mode 100644
index 0000000..e6f31dd
--- /dev/null
+++ b/TimeHACK.Main/OS/Win95/Win95Apps/MineSweeper/Game.cs
@@ -0,0 +1,201 @@
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+
+namespace TimeHACK.OS.Win95.Win95Apps.MineSweeper
+{
+ public class Game
+ {
+ public event EventHandler DismantledMinesChanged;
+ public event EventHandler Tick;
+
+ private int _dismantledMines;
+ private int _height;
+ private int _incorrectdismantledMines;
+ private int _mines;
+ private Panel _panel;
+ private Square[,] _squares;
+ private Timer _timer;
+ private int _width;
+
+ public int Time;
+
+ public Game(Panel panel, int width, int height, int mines)
+ {
+ _panel = panel;
+ _width = width;
+ _height = height;
+ _mines = mines;
+ }
+
+ private void Dismantle(object sender, EventArgs e)
+ {
+ Square s = (Square)sender;
+ if (s.Dismantled)
+ {
+ if (s.Minded)
+ {
+ _dismantledMines++;
+ }
+ else
+ {
+ _incorrectdismantledMines++;
+ }
+ }
+ else
+ {
+ if (s.Minded)
+ {
+ _dismantledMines--;
+ }
+ else
+ {
+ _incorrectdismantledMines--;
+ }
+ }
+
+ OnDismantledMinesChanged();
+
+ if (_dismantledMines == Mines)
+ {
+ _timer.Enabled = false;
+ Panel.Enabled = false;
+ }
+ }
+
+ public int DismantledMines
+ {
+ get { return _dismantledMines + _incorrectdismantledMines; }
+ }
+
+ private void Explode(object sender, EventArgs e)
+ {
+ _timer.Enabled = false;
+
+ foreach (Square s in _squares)
+ {
+ s.RemoveEvents();
+ if (s.Minded)
+ {
+ s.Button.Text = "*";
+ s.Button.Font = new System.Drawing.Font("Arial Black", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
+ s.Button.ForeColor = Color.Black;
+ }
+ }
+ }
+
+ public int Height
+ {
+ get { return (this._height); }
+ }
+
+ public bool IsBomb(int x, int y)
+ {
+ if (x >= 0 && x < Width)
+ {
+ if (y >= 0 && y < Height)
+ {
+ return _squares[x, y].Minded;
+ }
+ }
+ return false;
+ }
+
+ public int Mines
+ {
+ get { return (this._mines); }
+ }
+
+ protected void OnDismantledMinesChanged()
+ {
+ if (DismantledMinesChanged != null)
+ {
+ DismantledMinesChanged(this, new EventArgs());
+ }
+ }
+
+ protected void OnTick()
+ {
+ if (Tick != null)
+ {
+ Tick(this, new EventArgs());
+ }
+ }
+
+ public void OpenSpot(int x, int y)
+ {
+ if (x >= 0 && x < Width)
+ {
+ if (y >= 0 && y < Height)
+ {
+ _squares[x, y].Open();
+ }
+ }
+ }
+
+ public Panel Panel
+ {
+ get { return (this._panel); }
+ }
+
+ public void Start()
+ {
+
+ //Panel.SuspendLayout();
+ Time = 0;
+ _dismantledMines = 0;
+ _incorrectdismantledMines = 0;
+ OnTick();
+ Panel.Enabled = true;
+ Panel.Controls.Clear();
+
+ // Create Spots
+ _squares = new Square[Width, Height];
+ for (int x = 0; x < Width; x++)
+ {
+ for (int y = 0; y < Height; y++)
+ {
+ Square s = new Square(this, x, y);
+ s.Explode += new EventHandler(Explode);
+ s.Dismantle += new EventHandler(Dismantle);
+ _squares[x, y] = s;
+ }
+ }
+
+ // Place Mines
+ int b = 0;
+ Random r = new Random();
+ while (b < Mines)
+ {
+ int x = r.Next(Width);
+ int y = r.Next(Height);
+
+ Square s = _squares[x, y];
+ if (!s.Minded)
+ {
+ s.Minded = true;
+ b++;
+ }
+ }
+
+ OnDismantledMinesChanged();
+
+ _timer = new Timer();
+ _timer.Interval = 1000;
+ _timer.Tick += new EventHandler(TimerTick);
+ _timer.Enabled = true;
+ }
+
+ private void TimerTick(object sender, EventArgs e)
+ {
+ Time++;
+ OnTick();
+ }
+
+ public int Width
+ {
+ get { return (this._width); }
+ }
+ }
+}