Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-16-2007, 12:02 AM
Member
 
Join Date: Nov 2007
Posts: 1
JFlash is on a distinguished road
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
Hello, I'm new to these forums, so I don't know if any of you are familiar with the Gridworld framework, which is required by the AP Computer Science curriculum. Basically, it is literally a grid where "actors" are placed, and coded to do various tasks.

Anyway, my Minesweeper project fills up the grid with Mine objects. These Mines are managed by the Minefield class. Finally, the game is executed by running the MineSweeper class.

Everything works fine, except there is no "game over". What I don't know how to do is two things:

1. The game becomes aware that a mine has been revealed
2. All mine objects reveal themselves

"Revealing" means making the mine object return the proper string from getImageSuffix(). Here is the source code:

Mine.java:

Code:
//import java.awt.Color; import info.gridworld.actor.ActorWorld; import info.gridworld.actor.Rock; import info.gridworld.actor.Actor; import info.gridworld.grid.Grid; import info.gridworld.grid.Location; public class Mine extends Rock { private boolean _hasBomb = true; private boolean _isFlagged = false; private boolean _isRevealed = false; private int _numberOfAdjacentBombCounter = 0; private int _numberOfAdjacentBombs = 0; private double rand = Math.random(); public Mine(MineField F) { if(rand >= .1) _hasBomb = false; } public void setNumberOfAdjacentBombs(int n) { _numberOfAdjacentBombs = n; } // access to private variables public int numberOfAdjacentBombs() { return _numberOfAdjacentBombs; } //public boolean gameOver() //{ // return _gameOver; //} public boolean hasBomb() { return _hasBomb; } public void Reveal() { _isRevealed = true; if(!_hasBomb && adjacentBombCounter() == 0) { for(Actor neighbor : getGrid().getNeighbors(getLocation())) { Mine neighborMine = ((Mine) neighbor); if(!neighborMine._isRevealed && !neighborMine._hasBomb) neighborMine.Reveal(); } } } public void flag() { _isFlagged = true; } public void unflag() { _isFlagged = false; } public int adjacentBombCounter() { _numberOfAdjacentBombCounter = 0; for(Actor neighbor : getGrid().getNeighbors(getLocation())) { Mine neighborMine = ((Mine) neighbor); if(neighborMine._hasBomb) _numberOfAdjacentBombCounter++; } return _numberOfAdjacentBombCounter; } public String getImageSuffix() { if(_isRevealed && _hasBomb) return "Explode"; if(_isRevealed && !_hasBomb) return "" + adjacentBombCounter(); if(_isFlagged) return "Flag"; return "NoClick"; } } MineField.java: //import java.awt.Color; import info.gridworld.actor.ActorWorld; import info.gridworld.actor.Actor; import info.gridworld.grid.Grid; import info.gridworld.grid.Location; public class MineField extends ActorWorld { public boolean _gameOver = false; public MineField() { //super(new BoundedGrid<Actor> (rows, columns)); Grid<Actor> gr = getGrid(); int row = gr.getNumRows(); int column = gr.getNumCols(); //fill the grid with mines for (int r = 0; r < row; r++) { for (int c = 0; c < column; c++) { Mine currentMine = new Mine(this); Location loc = new Location(r, c); add(loc, currentMine); currentMine.setNumberOfAdjacentBombs(currentMine.adjacentBombCounter()); } } } } MineSweeper.java: //import java.awt.Color; import info.gridworld.actor.Rock; import info.gridworld.actor.Actor; import info.gridworld.actor.ActorWorld; import info.gridworld.grid.Grid; import info.gridworld.grid.Location; public class MineSweeper { public static void main(String[] args) { ActorWorld world = new MineField(); //world.add(new MineField()); world.show(); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Roll 2-Dice "Pig" Game Help King8654 AWT / Swing 7 04-07-2008 07:58 PM
creating a text based game Phobos0001 New To Java 1 02-12-2008 05:35 PM
Hwlp with "Open", "Save", "Save as..." trill New To Java 1 07-31-2007 08:53 AM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-25-2007 11:55 PM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 07:32 AM


All times are GMT +3. The time now is 12:22 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org