Skip to content

Commit

Permalink
adds minesweeper
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipNelson5 committed Oct 1, 2019
1 parent f75df71 commit 05fddd1
Show file tree
Hide file tree
Showing 37 changed files with 1,155 additions and 0 deletions.
29 changes: 29 additions & 0 deletions CS2420_CS3/8-Minesweeper/Resources/FieldButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#cell_unclicked
{
-fx-background-color: darkgrey;
-fx-border-color: black;
}

#cell_clicked
{
-fx-background-color: lightsteelblue;
-fx-border-color: black;
}

#bomb_flagged
{
-fx-background-color: springgreen;
-fx-border-color: black;
}

#bomb_unflagged
{
-fx-background-color: red;
-fx-border-color: black;
}

#wrong_flag
{
-fx-background-color: yellow;
-fx-border-color: black;
}
Binary file added CS2420_CS3/8-Minesweeper/Resources/bomb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/click.wav
Binary file not shown.
Binary file added CS2420_CS3/8-Minesweeper/Resources/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/eight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/exit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/explosion.wav
Binary file not shown.
Binary file added CS2420_CS3/8-Minesweeper/Resources/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/five.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/flag.wav
Binary file not shown.
Binary file added CS2420_CS3/8-Minesweeper/Resources/four.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/internet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/lose.wav
Binary file not shown.
Binary file added CS2420_CS3/8-Minesweeper/Resources/loseVoice.wav
Binary file not shown.
Binary file added CS2420_CS3/8-Minesweeper/Resources/mine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/question.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/seven.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/six.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/three.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/two.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/unchecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CS2420_CS3/8-Minesweeper/Resources/win.wav
Binary file not shown.
2 changes: 2 additions & 0 deletions CS2420_CS3/8-Minesweeper/data/highScore.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Philip 6 easy
philip 31 hard
199 changes: 199 additions & 0 deletions CS2420_CS3/8-Minesweeper/src/cs2410/assn8/control/Control.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package cs2410.assn8.control;

import javafx.beans.property.SimpleIntegerProperty;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by philip_nelson on 4/25/17.
*/
public class Control {

/**
* game mode
*/
public enum Mode{NORMAL, SPEED_DEAMON, TIME_UP}

/**
* max values
*/
public int maxRows, maxCols, maxBombs, maxTime, timeInterval;

/**
* easy, medium or hard
*/
public ScoreBoard.Type type;

/**
* game mode
*/
public Mode mode;

/**
* bomb info
*/
public SimpleIntegerProperty bombsRemain, cellsCleared;
public double percentBombs;
public boolean bombMatrix[][];

/**
* constructor, defaults to small, easy, normal
*/
public Control() {
maxRows = 0;
maxCols = 0;
maxBombs = 0;
bombsRemain = new SimpleIntegerProperty(0);
cellsCleared = new SimpleIntegerProperty(0);
setDiffEasy();
setSizeSmall();
setModeNormal();
}

/**
* returns the number of bombs around a give cell
* @param row row of cell
* @param col col of cell
* @return number of adjacent bombs
*/
public int getBombs(int row, int col) {
int bombs = 0;
for (int i = row - 1; i <= row + 1; ++i)
for (int j = col - 1; j <= col + 1; ++j)
if (i >= 0 && j >= 0 && i < maxRows && j < maxCols && bombMatrix[i][j])
++bombs;
return bombs;

}

/**
* handles decrementing the bomb count
*/
public void decBombsRemain() {
if (bombsRemain.get() == 0)
return;
bombsRemain.set(bombsRemain.get() - 1);
}

/**
* handles incrementing the bomb count
*/
public void incBombsRemain() {
if (bombsRemain.get() == maxBombs)
return;
bombsRemain.set(bombsRemain.get() + 1);
}

/**
* initializes the cells with current params
*/
public void initGrid() {
bombsRemain.set((int) (maxRows * maxCols * percentBombs));
cellsCleared.set(0);
maxBombs = (int) (maxRows * maxCols * percentBombs);
bombMatrix = new boolean[maxRows][maxCols];
ArrayList<Boolean> bombList = new ArrayList<>();

int bombs = 0;
for (int i = 0; i < maxRows; ++i) {
for (int j = 0; j < maxCols; ++j) {
if (bombs++ < maxBombs)
bombList.add(true);
else
bombList.add(false);
}
}
Collections.shuffle(bombList);

for (int i = 0, b = 0; i < maxRows; ++i) {
for (int j = 0; j < maxCols; ++j, ++b) {
bombMatrix[i][j] = (bombList.get(b));
}
}
}

/**
* checcks win condition
* @return true if the player has won
*/
public boolean hasWon() {
return (cellsCleared.get() + maxBombs) == (maxRows * maxCols);
}


/**
* sets difficulty to easy
*/
public void setDiffEasy() {
type = ScoreBoard.Type.EASY;
maxTime = 10000;
timeInterval = 100;
percentBombs = 0.1;
}

/**
* sets difficulty to medium
*/
public void setDiffMedium() {
percentBombs = 0.25;
type = ScoreBoard.Type.MEDIUM;
maxTime = 1000;
timeInterval = 25;
}

/**
* sets difficulty to hard
*/
public void setDiffHard() {
percentBombs = 0.4;
type = ScoreBoard.Type.HARD;
maxTime = 100;
timeInterval = 10;
}

/**
* sets size to small
*/
public void setSizeSmall() {
maxRows = 10;
maxCols = 10;
}

/**
* sets size to medium
*/
public void setSizeMedium() {
maxRows = 25;
maxCols = 25;
}

/**
* sets size to large
*/
public void setSizeLarge() {
maxRows = 25;
maxCols = 50;
}

/**
* sets mode to normal
*/
public void setModeNormal(){
mode = Mode.NORMAL;
}

/**
* sets mode to speed deamon
*/
public void setModeSpeedDeamon(){
mode = Mode.SPEED_DEAMON;
}

/**
* sets mode to times up
*/
public void setModeTimeUp(){
mode=Mode.TIME_UP;
}
}
Loading

0 comments on commit 05fddd1

Please sign in to comment.