diff options
| author | lempamo <[email protected]> | 2017-08-23 13:38:40 -0400 |
|---|---|---|
| committer | lempamo <[email protected]> | 2017-08-23 13:38:40 -0400 |
| commit | 3306d36ecbc024775972e5cf7971b2a7a70671d0 (patch) | |
| tree | 0a79e67b6723a8c75ffd66c7828bdd0ebb1bf74d /Histacom2/OS/Win95/Win95Apps/MineSweeper/Game.cs | |
| parent | 99fef5c57360f07259fc86f433bed8a9ab59c48e (diff) | |
| download | histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.tar.gz histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.tar.bz2 histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.zip | |
Renaming the game!
Diffstat (limited to 'Histacom2/OS/Win95/Win95Apps/MineSweeper/Game.cs')
| -rw-r--r-- | Histacom2/OS/Win95/Win95Apps/MineSweeper/Game.cs | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/Histacom2/OS/Win95/Win95Apps/MineSweeper/Game.cs b/Histacom2/OS/Win95/Win95Apps/MineSweeper/Game.cs new file mode 100644 index 0000000..8f8d7e7 --- /dev/null +++ b/Histacom2/OS/Win95/Win95Apps/MineSweeper/Game.cs @@ -0,0 +1,208 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + + +namespace Histacom2.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; + public Timer _timer; + private int _width; + public bool ftime = true; + public int Time; + public bool win = false; + private WinClassicMinesweeper _window; + + public Game(WinClassicMinesweeper window, Panel panel, int width, int height, int mines) + { + _panel = panel; + _width = width; + _height = height; + _mines = mines; + _window = window; + win = false; + } + + 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; + win = true; + } + } + + public int DismantledMines + { + get { return _dismantledMines + _incorrectdismantledMines; } + } + + private void Explode(object sender, EventArgs e) + { + _panel.Enabled = false; + _window.button1.BackgroundImage = Properties.Resources.WinClassicMinesweeperSad; + if (_timer != null) _timer.Enabled = false; + foreach (Square s in _squares) + { + s.RemoveEvents(); + if (s.Minded && !s.Exploded && !s.Dismantled) + { + s.Button.BackgroundImage = Properties.Resources.minesweepSquareMine; + } + if (s.Dismantled && !s.Minded) + { + s.Button.BackgroundImage = Properties.Resources.minesweepSquareWrong; + } + } + _window.button1.BackgroundImage = Properties.Resources.WinClassicMinesweeperSad; + } + + 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 bool IsDismantled(int x, int y) + { + if (x >= 0 && x < Width) + { + if (y >= 0 && y < Height) + { + return _squares[x, y].Dismantled; + } + } + 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; + 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); + s.Button.MouseDown += (send, args) => { if (_panel.Enabled) _window.button1.BackgroundImage = Properties.Resources.WinClassicMinesweeperGasp; }; + s.Button.MouseUp += (send, args) => { if (_panel.Enabled) _window.button1.BackgroundImage = Properties.Resources.WinClassicMinesweeperSmile; }; + _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(); + } + + public void TimerTick(object sender, EventArgs e) + { + Time++; + OnTick(); + } + + public int Width + { + get { return (this._width); } + } + } +} |
