MinesweeperGameImple..

hundredcarriageSoftware and s/w Development

Nov 3, 2013 (4 years and 10 days ago)

107 views

Nuria Clodius

Minesweeper Game Plan


How the Game is played:



Have a grid of set width and height



Click on individual tile



It turns over to reveal:

o

a number showing how many mines are in adjacent tiles

o

a blank



in

which case all surrounding blank tiles are revealed until tiles
are found containing numbers

o

a mine



the game is over (player loses)



all mines are revealed



Player loses if they click on a mine



Player wins if all non mine tiles have been revealed

Classes:

// Represents an individual minesweeper square

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import javax.swing.JComponent;


public class
MinesweeperSquare

extends JComponent

{


// mine square


public MineSquare mineSquare;




//
number square


public NumberSquare numberSquare;



// blank square


public BlankSquare blankSquare;



// checks to see if the card is face up


public boolean faceUp;



// Constructor: creates a new square of type mine, number, or blank


// finds a random n
umber, and based on number assigns instance of square


t
o be a mine, a number, or a blank


// also sets the card to start off face down


public MinesweeperSquare( )


{


}




// Get mine square type and return the mine


public MineSquare setToMine()


{


}



// Get blank square type and return the blank type


public BlankSquare setToBlank()


{


}



// Get number square type and return the number square type


public NumberSquare setToNumber()


{


}



// Test to see if square is face up


// Return true if
square is face up


public boolean isFaceUp()


{


}



// Flip square over


public void flip()


{


}



// Look at adjacent tiles for mines to set the number in a number square


// Return the correct number of mines


public int setNumberSquare()


{


}



// Us
ing JComponent to draw on this square/button if the card is face up

with the appropriate symbol (a mine, a number, or a blank )


// Otherwise it remains a light grey


public void paint( Graphics g)


{


}



// Utility method to paint description onto the
card


public void paintDescription( Graphics g )


{


}

}


// Sets the multidimensional array to be used as a grid by the minesweeper game

public class MinesweeperGrid

{


// Create a variable of type MinesweeperGrid to hold a 2D array


public MinesweeperGri
d minesweeperGrid;




// Decide on the minesweeper grid dimensions


int gridDimensions = 8;



// Constructor: creates a new instance of the minesweeperGrid


public MinesweeperGrid()


{


}



// fills the 2D minesweeperGrid with either
mines, blanks, or num
bers


public int[] fillGrid(
)


{


}


}


// wrapper for the MinesweeperPanel class

import javax.swing.JApplet;


public class MinesweeperApplet extends JApplet

{


// invoked when applet is initialized


// adds a MinesweeperPanel


public void int()


{


}



public void destroy()


{


}



public void start()


{


}



public void stop()


{


}

}


// wraps a MinesweeperPanel for the minesweeper game

import javax.swing.JFrame;


public class MinesweeperApplication

{


// creates a new JFrame with title


// create

a new MinesweeperPanel


// set the size of the panel, make it visible and set the default close operation


public static void main( String[] args )


{


}

}


// GUI panel for the minesweeper game

import java.awt.Color;

import java.awt.GridLayout;

import ja
va.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Timer;

import java.util.TimerTask;

import javax.swing.JPanel;


public class MinesweeperPanel extends JPanel implements MouseListener

{


// the tile that is clicked


public Mine
sweeperSquare clickedSquare;



// Constructor: Creates a minesweeper game with 64 squares with their

appropriate types (mine, number, blank)


// set each square to listen for mouse clicks through listenToSquares()


public MinesweeperPanel()


{


}



// Add

the mouse listener to each of these 64 specific squares


public void listenToSquares( )


{


}



// invoked when mouse botton clicked on a component


public void mouseClicked( MouseEvent e )


{



// flip card if not already face up


}


// invoked when mous
e enters a component


public void mouseEntered( MouseEvent e ) {}



// invoked when mouse exits component


public void mouseExited( MouseEvent e ) {}



// invoked when mouse button has been pressed on a component


public void mousePressed( MouseEvent e ) {
}



// invoked when mouse button released on component


public void mouseReleased( MouseEvent e ) {}

}


// Defines a mine square

public class MineSquare

{



// number referring to all mine squares


int typeMineSquare;



// Constructor: Sets a mineSquare

type to a number 3


public MineSquare()


{


}

}


// Defines a number square or blank square

public class NumberAndBlankSquare

{


// number referring to all number squares


int typeNumberSquare;



// number referring to all blank squares


int typeBlankSqu
are;



// number referring to number of mines in the vicinity of number square


// range from 0
-
8


int minesAdjacentToSquare;



// Constructor: Sets a numberSquare type to a number 2 if

minesAdjacentToSquare is 1
-
8, or set a blankSquare type to 1 if

mine
sAdjacentToSquare is 0


public NumberSquare()


{


}



// sets the minesAdjacentToSquare number using the array given to walk

through it looking for mine squares


public int searchForAdjacentMines ( int[] array )


{


}

}