PDA

View Full Version : my program doesnt work pls look at my program and show me a way


KeReM
01-05-2007, 12:06 PM
my progam is this(minesweper game) and ı dont know what ı should write at the beginning and
there are some mistakes pls help me thank alot


code:


class Mines {
public static void main(String args[]) throws Exception
{
java.util.Random generator = new
java.util.Random(System.currentTimeMillis());

int pcBoard[][] = new int[10][10];

int plBoard[][] = new int[10][10];

int i, j, row, col, count, isGameOver, r, c;

row = 10;
col = 10;

//Mayınlar yerleştiriliyor.
count = 0;
while (count != 25) {
r = generator.nextInt(10);
c = generator.nextInt(10);
if (pcBoard[r][c] != -1) {
pcBoard[r][c] = -1;
count = count + 1;
}
}

for (i = 0; i < row; i = i + 1) {
for (j = 0; j < col; j = j + 1) {
if (pcBoard[i][j] != -1)
System.out.print(" ");
System.out.print(pcBoard[i][j] + " ");
}
System.out.println();
}

//Mayın olmayan hücrelerin etrafındaki mayınlar sayılıyor.
for (i = 0; i < row; i = i + 1)
for (j = 0; j < col; j = j + 1)
if (pcBoard[i][j] == 9) {
count = 0;
for (r = i - 1; r <= i + 1; r = r + 1)
for (c = j - 1; c <= j + 1; c = c + 1)
if (r >= 0)
if (r < row)
if (c >= 0)
if (c < col)
if (pcBoard[r][c] == -1)
count =count + 1;

pcBoard[i][j] = count;
}

//Oyun oynanıyor.
count = 0;
isGameOver = 0;
while (isGameOver == 0) {
count = count + 1;
System.out.print("Satiri giriniz : ");
r = Keyboard.readInt();
System.out.print("Sutunu giriniz : ");
c = Keyboard.readInt();

plBoard[r][c] = pcBoard[r][c];

if (pcBoard[r][c] == -1) {
isGameOver = 1;
System.out.println("Mayina bastiniz...");
}
else if (count == 75) {
isGameOver = 1;
System.out.println("Tebrikler...");
}

for (i = 0; i < row; i = i + 1) {
for (j = 0; j < col; j = j + 1) {
if (pcBoard[i][j] != -1)
System.out.print(" ");
System.out.print(pcBoard[i][j] + " ");
}
System.out.println();
}
System.out.println();
for (i = 0; i < row; i = i + 1) {
for (j = 0; j < col; j = j + 1) {
if (plBoard[i][j] != -1)
System.out.print(" ");
System.out.print(plBoard[i][j] + " ");
}
System.out.println();
}
}
}
}

vinyl-junkie
01-05-2007, 01:10 PM
You need to narrow your problem down a bit. What do you mean by "what ı should write at the beginning?" You say there are some mistakes. What are they? Also, I hope this isn't a homework assignment. Asking for help with that is against the forum rules (http://www.codingforums.com/rules.htm).

Aradon
01-08-2007, 05:14 AM
What is Keyboard ? Is that a static class you are provided? If you want to use something that will do IO for you I suggest that you use the Scanner Class

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html