i am trying to work on a simple game that resmebles secretsquare. Where it promptst the user for the number of columns and rows he would like to have on the board then it takes that in and creates a two dimensional array based on that and then randomly assigns a secret square. Then it asks him for two coordinates a row and a column and based on that it would tell him how close he is. But, i keep on getting many errors. I will list the code and the errors i keep getting.
CODE:
import java.math.*;
public class SecretSquare{
static int[][] board;
static int a;
static int b;
public void board(int x, int y){ //creates a board
board = new int[x][y];
a = (int) (Math.random() *x); //assigns values to
b = (int) (Math.random() *y); //secret square
int secretsquare = board[a][b];//dont know
} //if syntacticly correct
public void howclose(int k, int l){ //method to check how
if(k==a && l==b) //close
System.out.println("You got it BABY!!!");
if (Math.abs((board[k]- board[a])) == 1&& Math.abs((board[l]- board[b]))== 1)
System.out.println("You are very close!!!");
if (Math.abs((board[k]- board[a])) == 2&& Math.abs((board[l]- board[b])) == 2)
System.out.println("You are close!!");
if (Math.abs((board[k] - board[a])) >= 3)
System.out.println("YOU ARE WAY OFF!!!");
}
public static void main(String[] args){
SecretSquare c = new SecretSquare();
EasyReader stdin = new EasyReader(System.in);
//EasyReader is a way to take input from the user.
System.out.println("SecretSquare is: " + c.secretsquare);
int x = stdin.intQuery("Please indicate the number of columns:");
//stdin.intQuery is a method inside EasyReader that takes asks //the user for an integer input and then uses it in the program.
int y = stdin.intQuery("Please indicate the number of rows: ");
c.board(x, y);
int z = stdin.intQuery("Please enter your guess column: ");
int q = stdin.intQuery("Please enter your guess row: ");
c.howclose(z, q);
}
}
ERRORS WHEN COMPILED:
SecretSquare.java:22: Incompatible type for -. Can't convert int[] to int.
if (Math.abs((board[k]- board[a])) == 1&& Math.abs((board[l]- board[b]))== 1)
^
SecretSquare.java:22: Incompatible type for -. Can't convert int[] to int.
if (Math.abs((board[k]- board[a])) == 1&& Math.abs((board[l]- board[b]))== 1)
^
SecretSquare.java:25: Incompatible type for -. Can't convert int[] to int.
if (Math.abs((board[k]- board[a])) == 2&& Math.abs((board[l]- board[b])) == 2)
^
SecretSquare.java:25: Incompatible type for -. Can't convert int[] to int.
if (Math.abs((board[k]- board[a])) == 2&& Math.abs((board[l]- board[b])) == 2)
^
SecretSquare.java:29: Incompatible type for -. Can't convert int[] to int.
if (Math.abs((board[k] - board[a])) >= 3)
^
SecretSquare.java:37: No variable secretsquare defined in class SecretSquare.
System.out.println("SecretSquare is: " + c.secretsquare);
^
6 errors
END OF ERRORS.
Now these are the errors that i get when i compile. Can somebody please help debug as i am baffeled by these errors. I have tried to fix them, to no avail. If you also have any suggestions on a modification in the code it would be greatly apprectiated.
Thank you in advance,
JavaDude