Edit: Since there is no command for clearing the console in java, this has to be implemented via GUI.
i am writing a small console based game and i want to ask how do i print my matrix at the same location in the console? I want to let it look like changes in the matrix appear in "realtime", which means the user does not see that a new matrix was drawn.
the function level creates a new matrix and display prints out the current matrix:
/**
* creates a new gameworld(matrix of size mxn)
* @param m
* @param n
* @return
*/
public int[][] level(int m, int n){
//initialize gameworld
int[][] lGW = new int[m][n];
//fill matrix with 0
for(int i = 0; i <= m-1; i++ ){
for(int j = 0; j <= n-1; j++ ){
lGW[i][j] = 0;
}
}
return lGW;
}
/**
* show the gameworld in the console
*/
public void displayGameWorld(){
for(int i = 0; i <= gameworld.length-1; i++){
for(int j = 0; j <= gameworld[0].length-1; j++){
System.out.printf("%3d", gameworld[i][j]);
}
System.out.println();
}
}