Giter Site home page Giter Site logo

minesweeper's Introduction

Minesweeper

In this assignment you will be recreating the Microsoft Minesweeper game. If you are not familiar with minesweeper you should play the game until you are. You can find one version at http://minesweeperonline.com/. You can also try my slightly easier Minesweeper game. You may find the 2d Arrays PowerPoint slides helpful.

Install the Guido GUI Library

We'll be using a GUI library called Guido. To install it, start Processing and choose Sketch | Import Library | Add Library. Type Guido in the search box, the click on Guido by Florian Jenett and then click Install.

Program Requirements

  1. Your minesweeper game will be a two dimensional array of buttons. Use constants for the number of rows and columns.
  2. The number of bombs should also be specified by a constant.
  3. Make sure all class member variables and methods are labeled appropriately as either public, protected or private
  4. If you click on a button that contains a bomb, the game ends and all the bombs are displayed
  5. If you click on a button that does not contain a bomb, a number appears at that location indicating the number of neighbors that DO contain bombs. Recall that each position has at most 8 neighbors. Note that the buttons on the boundary have fewer than 8 neighbors. For example, a corner has only three neighbors.
  6. If the user clicks on a button and no number appears, then there are no bombs neighboring that button. Your program should then recursively keep pressing those surrounding buttons that are not next to a bomb.
  7. The game should end when all the buttons that do not contain bombs have been marked (assuming that you have not been blown up by then!)
  8. Your game should use Math.random() to randomly place the mines.

Suggested steps to completing this assignment:

  1. Fork and clone down this repository
  2. On line 4, create two integer constants NUM_ROWS and NUM_COLS and initialize them each with the value 20
  3. Go to line 18, use the constants to initialize the 2d array buttons to have 20 rows and 20 columns
  4. Use nested loops to create a new MSButton for each row column pair
  5. Uncomment lines 55 and 56, You should now see a grid of buttons. If you click on the button it should turn white.
  6. Now, got to line 7, and initialize bombs to be a new empty ArrayList of type MSButton
  7. Go to line 25 and write the setBombs() function. It should generate a random row and column number. Use the contains() function to check to see if buttons[row][col] is already in bombs. If it isn't then add it
  8. Uncomment lines 97 and 98 so that cells with a mine turn red when clicked. Test out your program to make sure it has the number of mines you expect.
  9. Now go to the MSButton class and finish these three member methods:
    • public boolean isValid(int row, int col) returns true if (row,col) is a valid location on the grid and false otherwise
    • public int countBombs(int row, int col) counts the bombs in the 8 neighbors--(remember to check to see if the neighboring button is valid before checking to see if it's a mine)
    • public void mousePressed() which:
      • sets click to true
      • if keyPressed is true, toggles marked to either either true or false. If marked is false set click to false
      • else if bombs contains this button display the losing message
      • else if countBombs returns a number of neighboring mines greater than zero, set the label to that number
      • else recursively call mousePressed with the valid, unclicked, neighboring buttons in all 8 directions
  10. Next, finish public boolean isWon() which determines if the player has won the game
  11. Then finish public void displayWinMessage() which uses setLabel to change the labels of the buttons to display a winning message
  12. Finally finish public void displayLosingMessage() to display the positions of all the bombs as well as a losing message

Alternative Assignment: The Game of Life

If you want an alternative to Minesweeper, you could write your own version of the The Game of Life. The Game of Life isn't what you think, it's a program that simulates how bacteria might grow. It's another program that is well suited to using a two dimensional array of buttons. You can find examples and descriptions at the following websites: http://www.bitstorm.org/gameoflife/
http://www.math.com/students/wonders/life/life.html

Game of Life sample work

Ethan


Minesweeper sample work

Thien
Melody
Jeremy
Helen
Xiao Qin
Charles
Jacky
Noah
Alex
Matthew
Rebecca
Winnie
Evan
Esther
Raymond
Aliya
Brian
Ka Ki
Alex
Elliott
Theo
Lin
Jimmy
Zachary
Erika
Thomas

minesweeper's People

Contributors

simart avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.