Unable To Fill Blank Squares On Minesweeper Game

Nov 12, 2014

I'm having trouble filling in the blank squares on a Minesweeper game. What I am trying to is, if a user clicks a square and that square(s) does not have a bomb in it, or adjacent to it, should be set to an empty square.

Here's my recursive method below:

public void revealZeros(){
for(int x = -1; x <= 1; x++)
for (int y = -1; y <= 1; y++){
Square zeroSquare = (Square)board.getSquareAt(xLocation+x, yLocation+y);
if (!(zeroSquare.SquareHasBomb)){
setImage("images/empty.jpg");
}
}
revealZeros();
}

I am traversing around the square that the user clicks on with the use of two for-loops. Getting the square at that location and then applying an empty square image. On that square.

The function should then recurse itself and go onto the next square, if the next square does not have a bomb or does not have an adjacent bomb.

I keep on getting an infinite recursion problem

View Replies


ADVERTISEMENT

Print Writer Won't Fill Output File / Blank Every Time

Apr 10, 2014

I am trying to write to an output file that the user names. I have flushed and closed the printwriter, so now I am at a loss. The console output works fine with the formatting, and the file is created, but I cannot get the file to populate. I have the following:

public static void main(String[] args) {

try
{
Scanner kb = new Scanner(System.in);
System.out.print("Input file: ");
String inputFileName = kb.next();
System.out.print("Output file: ");
String outputFileName = kb.next();
// Construct the Scanner and PrintWriter objects for reading and writing
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter(outputFileName);

[code]....

View Replies View Related

Java Recursion In Minesweeper Game

Nov 16, 2014

Recursion in a MineSweeper game. So far, when a user clicks on a square and it has a bomb on it, I reveal the bomb to the user - see clicked(). I also have the ability to show the user if the squares surrounding them have any adjacent bombs - see countAdjacentSquares().

However, I am having trouble with my fillZeros() recursive method. When a user clicks on a square that has zero bombs in its surrounding squares, it not only reveals that square, but also any adjacent squares (horizontally, vertically or diagonally adjacent) that also have zero bombs in its surrounding squares.

I don't have any recursion, if I click on a square with no bombs all it does it set the square to 0, but doesn't continue to check for other empty squares.

Java Code:

import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Square extends GameSquare
{
private boolean revealed = false;
private boolean squareHasBomb = false;
public static final int MINE_PROBABILITY = 10;
public int mineCount = 0;

[Code] ....

View Replies View Related

Minesweeper - Print Out MxN Game And Neighboring Bomb Counts

Jan 17, 2015

/*****************************************************************
* Creates an MxN minesweeper game where each cell is a bomb with probability p.
* Prints out the MxN game and the neighboring bomb counts.
*
* Sample execution:
*
* % java Minesweeper 5 10 0.3
* * . . . . . . . . *
* . . . . . . * . . .
* . . . . . . . . * *
* . . . * * * . . * .
* . . . * . . . . . .
*
* * 1 0 0 0 1 1 1 1 *
* 1 1 0 0 0 1 * 2 3 3
* 0 0 1 2 3 3 2 3 * *
* 0 0 2 * * * 1 2 * 3
* 0 0 2 * 4 2 1 1 1 1
*
*
*************************************************************************/
  
public class MineSweeper
{
 public static void main(String[] args)
{
int n = Integer.parseInt(args[0]); //columns
int s = Integer.parseInt(args[1]); //rows
int p = Integer.parseInt(args[2]); //max number of bombs
 
[Code] .....

Console:

. . * . *
. * . . .
. . * . *
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Stefan.Minesweeper.main(Minesweeper.java:85)

Every time the compiler shows me this Array Index Out Of Bounds and shows me in the witch line i have error but i just don't get it how to fixed it and why compiler printing me this mistake because there is enough space in array field[][] because i provided a n+2 X s+2 fields in array and i am using just 1 to n ,including and 1 to s ,including m, so i have not used fields from field[0][0] to field[0][s+1] and field[0][0] to field[n+1][0], field[n+1][0] to field[n+1][s+1] ,field[n+1][s+1] to field[0][s+1] ,so i suppose i can check their values and do not get out of array bounds,but compiler claims otherwise!!!

View Replies View Related

Swing/AWT/SWT :: Hangman Game - No Graphics Show Up On Eighth Guess (Blank Frame)

Feb 5, 2015

I'm having some problems with the graphics of my hangman game. The graphic that's supposed to show up on the first guess (the hangman pole) doesn't show up until guess number 2. And on the eighth guess, no graphics show up (I just get a blank frame).

import java.awt.*;
import javax.swing.*;
public class HangmanFigure extends JPanel {
private int guesses;
private Image background;
public HangmanFigure() {
super();

[Code] .....

View Replies View Related

Making Squares Of Numbers Without Multiplication?

Oct 22, 2014

so for my computer science class, we have the following problem:

In your documentation be sure to say which loop you thought was easier to implement for this program and why Write a program that produces the following outputs. The first line of output must be written using a For-Loop. The second, using a While-Loop and the third using a Do-Loop.

You look at the program and smile because you see that the series is just the numbers 1-10 squared...just one line is in reverse order. No problem! As you start typing you discover that the number 8 key on your keyboard is not working. For this program you are unable to use the multiplication key

So, back to the drawing board. By staring at the sequence a light comes on and you are able to quickly finish this program WITHOUT using mulitiplication (or the Math class/ solve with arithmetic operators +, - or / ) .

Sample output:

For Loop
1 4 9 16 25 36 49 64 81 100

While Loop
100 81 64 49 36 25 16 9 4 1

Do While Loop
1 4 9 16 25 36 49 64 81 100

I have the "for" done, but I did it with a "for" in the beginning but then had a multitude of nested "if" loops so that I could do 7*7=7+7+7+7+7+7+7

View Replies View Related

Determine All Of Perfect Squares Between 1 And 100 - Precision Error?

Mar 26, 2015

I am teaching myself Java and am trying to write a function that will determine all of the perfect squares between 1 and 100 but am running into a problem...

Here's my code:

package sqrroot;

public class SqrRoot {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double sroot, rerr;
int count = 0;
for(double num = 1.0; num <= 100.0; num++){

[Code] ....

and here is the output:

run:
0.0
1.0 is a perfect square.
0.0
4.0 is a perfect square.

[Code] ....

There are 49 perfect squares between 1 and 100.
BUILD SUCCESSFUL (total time: 6 seconds)

Which is clearly wrong. Is there something wrong with my code or is this due to inherent imprecision in the double type or the Math.sqrt function?

View Replies View Related

10x10 Grid Java - How To Add Numbers To Squares

Mar 12, 2015

So I need to create a 10x10 grid for a snakes and ladders board, the board loads but i cant figure out how to add numbers to the squares. Here is my code :

import java.awt.*;
import javax.swing.*;
public class Board
{
//Creating the array
int[][] numbers=new int[10][10];
public static int rows = 10;
public static int columns = 10;
public static Color col1 = Color.green;

[Code] .....

View Replies View Related

Calculate Sum Of Two Squares - Java And Exception Handling

Jun 19, 2014

I know I can calculate the sum of squares as such:

// SumSquares.java: calculate the sum of two squares
class SumSquares {
static int sumSquares(int a, int B)/>/> {
int asquare;
int bsquare;

[Code] ....

But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.

View Replies View Related

Fleet Of Ships - Drawing Squares In Graphic Context

Feb 20, 2014

Square:

package assignment1;
  
import java.awt.*;
public class Square
{
private double x,y; // Current position of the square.
private Color color; // The color of the square. 
private int side; // The side of the square
public Square() // constructor

[Code] .....

This is the square class, it draws an orange square that moves around in the applet viewer, works fine and as it supposed to do.

Ship:

package assignment1;
 
import java.awt.*;
 public class Ship
{
private Square[] fleetMembers; // declare fleetMembers as an array of Square
private int total = 5; // Max number of squares in fleet
private double x,y;
Ship() // Constructor

[Code] ....

This is my FleetOfShips code. It is supposed to be a set of ships moving around together, but for unknown to me reasons it doesn't work. It does compile without any problems but when I run the applet it doesn't do anything.

View Replies View Related

Java And Exception Handling - Calculate Sum Of Squares (Input Values)

Jun 19, 2014

I know I can calculate the sum of squares as such:

// SumSquares.java: calculate the sum of two squares
class SumSquares {
static int sumSquares(int a, int B)/>/> {
int asquare;
int bsquare;

[Code] .....

But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.

View Replies View Related

Blank Value In Float Array?

May 11, 2015

I am getting the blank value in the array and this code is passed in IVR for playing the values since the first value is blank the prompts arrangements is disturbed. I want to replace the blank space or value by zero.

I have pasted the log and below is the code.

DEBUG - 7053CFEF4819D884638A42F088B507C3:/EntryPoint_1000 : session id:IVREPMSUAT2-2015083130037-4 |
Comm_DBinteraction-trcITELOutput | V_COUNTERTYPE:: | v_counterType : 1,2,3,4,5,6,7,8,9,10
DEBUG - 7053CFEF4819D884638A42F088B507C3:/EntryPoint_1000 : session id:IVREPMSUAT2-2015083130037-4 | Consult_IVR_3000:Comm_DBinteraction-trcITELOutput | V_SPENDINGLIMIT:: | v_spendingLimit :,500.0,59.5,0.0,1101.0,581.5,393.0,0.0,0.0,0.0

[code]....

View Replies View Related

JSF :: Blank Page Displayed With Facelet

Jun 11, 2014

I am getting blank page only. I created sample JSF project with Facelet in Eclipse. The source code contains basic page with header, content & footer. I refer the site Support-Eclipse . I deployed war into Tomcat. I am unable to find the problem.

Project Name: JSF-Facelet-Startup
Project coding structure
JSF-Facelet-Startup
|-->JAX-WS Web SErvices
|-->Deployment Descriptor
|-->Java Resources
|-->JavaScript Resources

[Code] .....

View Replies View Related

Why Sub Class Object Just Gives Blank When It Comes To String

Oct 22, 2014

why my sub class object just gives me a blank when it comes to the String. It works just fine for the super class but when I get to the sub class the program just gives me a blank. I won't let me input anything for the String. On line 24 of the client I attempt to input a new String but it doesn't ever let me enter one so then any call to getName is just a blank.

I have altered my super and sub class as well as the client to try to get it to work. I tried a local variable in the client, I tried using protected in the super class, I tried a handful of other things.

import java.util.*;
public class TryingItOutClient {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

Printing A Character - Output Blank

Mar 6, 2014

Why the output is coming out to be blank in the following code.

public class A {
public void call() {
char d = 10 ;
System.out.println(d); // why it is not printing ?
System.out.println((int)d);
}

public static void main(String[] args) {
A a = new A();
a.call();
}
}

View Replies View Related

Swing/AWT/SWT :: Java Frame Is Showing Blank?

Jul 5, 2014

i have problem with the following two java classes, driver class Reservations and Room class. When i run, it just show blank frame, tell me where i gone wrong.

import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Reservations extends Frame implements ActionListener {
Color lightRed=new Color(255,90,90);
Color lightGreen=new Color(140,215,40);
Rooms room=new Rooms(5,3);

[code]...

View Replies View Related

JavaFX 2.0 :: Blank White Screen While Starting App?

Jun 24, 2015

This screen appears for a second and after this, it shows up normal app screen. How I can solve this issue? When I open app: after this

View Replies View Related

I/O / Streams :: Create Blank Xml File On Program Startup

Oct 23, 2014

When my app starts up is it possible to create a blank xml file in the c drive? so I can use it later on down the line

View Replies View Related

Print A Blank Line After Certain Specific Points In Iterator

Feb 17, 2015

I have the following HashMap:

// 2009
nobelPrizeWinners.put("2009 Physics",
new PrizeWinner[] {new PrizeWinner("Charles K.", "Kao"),
new PrizeWinner("Willard S.", "Boyle"), new PrizeWinner("George S.", "Smith")});
nobelPrizeWinners.put("2009 Chemistry",
new PrizeWinner[] {new PrizeWinner("Venkatraman", "Ramakrishnan"),

[Code] .....

At the moment, my output is:

2008: Chemistry: Osamu Shimomura, Martin Chalfie, Roger Y. Tsien
2008: Economics: Paul Krugman
2008: Literature: Jean-Marie Gustave Le Clézio
2008: Medicine: Harald zur Hausen, Françoise Barré-Sinoussi, Luc Montagnier
2008: Peace: Martti Ahtisaari

[Code] .....

However, I need a blank line between the final entry of 2008 and the first entry of 2009.

View Replies View Related

Char Program - Output Printed As Blank Space Instead Of 0

Nov 12, 2014

I am aware that the default value of char is 0. But in this program I am getting some unexpected output

public class TestClass12{
static int[] ia = new int[1];
static char ch;
public static void main(String args[]) throws Exception{
System.out.println("ch:"+ch+" ia[ch]:"+ia[ch]);
}
}

Output:
ch: ia[ch]:0

If you see the above output ch is printed as a blank space instead of 0, while the array default value is correctly printed by taking the char default value as index. Why is ch printed as blank space?

View Replies View Related

JSP :: PDF In Browser - Showing Only Blank Screen In Its Status Bar As Connecting

Jul 22, 2014

.
.
.

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/MyServletPDF?username=TEST");
response.setContentType("application/pdf");
dispatcher.include(request,response);
%>

While debugging everything is going through... even it passes through the last line. But the pdf is not launching... showing only a blank screen in its status bar as "Connecting"... Earlier it was launching.. but suddenly this issue is raising up. Is there any IE settings need to be checked?

View Replies View Related

Reading Contents Of Several TXT Files - Output File Is Blank

May 4, 2015

In the program below I'm trying to read the contents of several .txt files in the same diretory and create a new .txt file containing all of the data from each file. My output is generated in the console however my .text file is blank.

public static void main(String[] args) throws IOException {
  String target_dir = "C:Files";
  String output = "C:Filesoutput.txt";
  File dir = new File(target_dir);
  File[] files = dir.listFiles();
 
[Code] .....

View Replies View Related

Accept Array Of Ints And Squares Each Element Of Array

May 13, 2014

I need to write a method that accepts an array of ints and squares each element of the array. No creating new arrays and no returning any values.

public void squareInts(int[] ints) {
for(int i = 0; i < ints.length; i++) {
ints[i] = (ints[i] * ints[i]);
}
}

View Replies View Related

Applet Open But Stay Blank And Error Message Appear In Terminal

Jul 29, 2014

What's wrong with my Java program? When I open it using appletviewer, the applet opens but stays blank and an error message appears in Terminal.

Java Code:

import java.applet.*;
import java.awt.*;
public class DemoColor extends Applet
{
Font littleFont = new Font("Helvetica", Font.ITALIC, 6);
public void paint(Graphics gr)

[Code] ....

Error Message:

Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue

at java.awt.Color.testColorValueRange(Color.java:310)
at java.awt.Color.<init>(Color.java:395)
at java.awt.Color.<init>(Color.java:369)
at DemoColor.paint(DemoColor.java:24)

[Code] ....

HTML file:

<HTML>
<APPLET CODE="DemoColor.class" WIDTH = 420 HEIGHT = 300>
</APPLET>
</HTML>

View Replies View Related

How To Remove Focus From JTextfield By Clicking Blank Area In JPanel

May 20, 2013

How to remove focus from jtextfield by click the blank area in a jpanel?

When I click the blank area in a jpanel. i want the cursor in the jtextfiled lost focus

View Replies View Related

How To Fill Array Of Points

Oct 10, 2014

I need to write a program but I am having hard time filling an array of triangles...we are suppose to have 3 different classes..1 class of points..1 class of triangles and 1 main method which apply all those..here what I have been come up so far for the point class which I believe is good..

public class Point {
private float x;
private float y;
//Making x equal to the x coordinate and y equal to the y coordinate like on a graph
public Point(float xCoordinate, float yCoordinate) {
x = xCoordinate;
y = yCoordinate;

[Code] ....

Now here is my question how I am suppose in the main method fill an array of triangles for 100 triangles or less?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved