aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications/ShiftSweeper.cs
diff options
context:
space:
mode:
authorpfg <[email protected]>2017-03-05 14:27:00 -0800
committerpfg <[email protected]>2017-03-05 14:27:00 -0800
commitca19c496ded9f4080ce99d927e9f1abf351fbaf0 (patch)
tree9df0ea12a44b6787b2a702bed942198263c077cf /ShiftOS.WinForms/Applications/ShiftSweeper.cs
parent1d8e6dfcd5fe853df47a5403e52239f6c83a43f1 (diff)
downloadshiftos_thereturn-ca19c496ded9f4080ce99d927e9f1abf351fbaf0.tar.gz
shiftos_thereturn-ca19c496ded9f4080ce99d927e9f1abf351fbaf0.tar.bz2
shiftos_thereturn-ca19c496ded9f4080ce99d927e9f1abf351fbaf0.zip
Mineswapper complete
Diffstat (limited to 'ShiftOS.WinForms/Applications/ShiftSweeper.cs')
-rw-r--r--ShiftOS.WinForms/Applications/ShiftSweeper.cs85
1 files changed, 84 insertions, 1 deletions
diff --git a/ShiftOS.WinForms/Applications/ShiftSweeper.cs b/ShiftOS.WinForms/Applications/ShiftSweeper.cs
index a39bf41..477bd87 100644
--- a/ShiftOS.WinForms/Applications/ShiftSweeper.cs
+++ b/ShiftOS.WinForms/Applications/ShiftSweeper.cs
@@ -46,6 +46,9 @@ namespace ShiftOS.WinForms.Applications {
int currentGameWidth;
int currentGameHeight;
+ private Timer ticking = new Timer();
+ private int minetimer;
+
private static readonly Random random = new Random();
Size tileSize;
@@ -75,10 +78,21 @@ namespace ShiftOS.WinForms.Applications {
InitializeComponent();
}
+ private void Ticking_Tick(object sender, EventArgs e) {
+ minetimer++;
+ lbltime.Text = "Time: " + minetimer.ToString();
+ /*lbltime.Text = Localization.Parse("{SHIFTSWEEPER_TIME}", new Dictionary<string, string>{
+ {"%time", minetimer.ToString()}
+ });*/
+ }
+
public void OnLoad() {
buttonEasy.Visible = true;
buttonMedium.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_medium");
buttonHard.Visible = ShiftoriumFrontend.UpgradeInstalled("shiftsweeper_hard");
+
+ ticking.Interval = 1000;
+ ticking.Tick += Ticking_Tick;
}
public void OnSkinLoad() {
@@ -93,6 +107,8 @@ namespace ShiftOS.WinForms.Applications {
}
public void startGame(int w, int h, int b) {
+ panelGameStatus.Image = Properties.Resources.SweeperNormalFace;
+
if (gamePanel.RowCount > w || gamePanel.ColumnCount > h) {
for (int y = 0; y < gamePanel.ColumnCount; y++) {
for (int x = 0; x < gamePanel.RowCount; x++) {
@@ -128,6 +144,7 @@ namespace ShiftOS.WinForms.Applications {
if (type == REMOVE) {
} else {
tile.Text = buttonImages[type];
+ tile.MouseDown += new MouseEventHandler(tile_ClickDown);
tile.MouseUp += new MouseEventHandler(tile_Click);
tile.Size = tileSize;
@@ -145,6 +162,8 @@ namespace ShiftOS.WinForms.Applications {
}
private void tile_Click(object sender, EventArgs ee) {
+ panelGameStatus.Image = Properties.Resources.SweeperNormalFace;
+
MouseEventArgs e = (MouseEventArgs)ee;
Control sen = (Control)sender;
TableLayoutPanelCellPosition tilePos = gamePanel.GetPositionFromControl(sen);
@@ -158,6 +177,10 @@ namespace ShiftOS.WinForms.Applications {
}
}
+ private void tile_ClickDown(object sender, EventArgs e) {
+ panelGameStatus.Image = Properties.Resources.SweeperClickFace;
+ }
+
private void createGameIfNotExists(int x, int y) {
createGameIfNotExists();
@@ -225,6 +248,9 @@ namespace ShiftOS.WinForms.Applications {
if (x < w && y > 0) revealTile(x + 1, y - 1);
if (x > 0 && y < h) revealTile(x - 1, y + 1);
}
+
+ if (bombs != 0) checkWinGame();
+ if (bombs == 9) loseGame();
}
private void toggleTileFlag(int x, int y) {
@@ -233,6 +259,8 @@ namespace ShiftOS.WinForms.Applications {
} else if(currentGame[x, y] == FLAGGED) {
updateTile(x, y, UNDISCOVERED);
}
+
+ checkWinGame();
}
private void toggleTileQuestionMark(int x, int y) {
@@ -241,10 +269,12 @@ namespace ShiftOS.WinForms.Applications {
} else if (currentGame[x, y] == QUESTIONED) {
updateTile(x, y, UNDISCOVERED);
}
+
+ checkWinGame();
}
private void buttonEasy_Click(object sender, EventArgs e) {
- startGame(10, 10, 10);
+ startGame(9, 9, 10);
}
private void buttonMedium_Click(object sender, EventArgs e) {
@@ -255,6 +285,59 @@ namespace ShiftOS.WinForms.Applications {
startGame(12, 12, 12);
}
+ public void winGame() {
+ int cp = 0;
+ int origminecount = gameBombCount * 10;
+ if (minetimer < 31) cp = (origminecount * 3);
+ else if (minetimer < 61) cp = (Int32)(origminecount * 2.5);
+ else if (minetimer < 91) cp = (origminecount * 2);
+ else if (minetimer < 121) cp = (Int32)(origminecount * 1.5);
+ else if (minetimer > 120) cp = (origminecount * 1);
+ SaveSystem.TransferCodepointsFrom("shiftsweeper", cp);
+ panelGameStatus.Image = Properties.Resources.SweeperWinFace;
+ disableAllTiles(false);
+ }
+
+ public void loseGame() {
+ disableAllTiles(true);
+ panelGameStatus.Image = Properties.Resources.SweeperLoseFace;
+ }
+
+ public void disableAllTiles(bool showBombs) {
+ for (int yy = 0; yy < gamePanel.ColumnCount; yy++) {
+ for (int xx = 0; xx < gamePanel.RowCount; xx++) {
+ gamePanel.GetControlFromPosition(xx, yy).Enabled = false;
+ if (game[xx, yy] == 9 && showBombs) {
+ gamePanel.GetControlFromPosition(xx, yy).BackgroundImage = Properties.Resources.SweeperTileBomb;
+ }
+
+ }
+ }
+ }
+
+ public void checkWinGame() {
+ for(int y = 0; y < currentGameHeight; y++) {
+ for(int x = 0; x < currentGameWidth; x++) {
+ int tile = currentGame[x, y];
+ if(tile == UNDISCOVERED || tile == QUESTIONED) {
+ return;
+ }
+ if(tile == FLAGGED) {
+ if(game[x,y] != 9) {
+ // looks like you flagged the wrong thing...
+ return;
+ }
+ }
+ if(tile == 9) {
+ loseGame();
+ return;
+ }
+
+ }
+ }
+ winGame();
+ }
+
private void panelGameStatus_Click(object sender, EventArgs e) {
}