I'm trying to create the "cat finds mouse" thing myself but I have troubles doing it because the way I print the field is pretty complicated / inefficient.
So I have the field:
String[][]field = {
{"+", "+", "+", "+", "+", "+", "+", "+", "+"},
{"+", " ", " ", " ", " ", " ", " ", "M", "+"},
{"+", " ", "+", "+", "+", "+", "+", " ", "+"},
{"+", " ", "+", "+", " ", " ", "+", " ", "+"},
{"+", " ", " ", " ", " ", "+", "+", " ", "+"},
{"+", " ", " ", "+", "+", "+", "+", " ", "+"},
{"+", "C", " ", " ", " ", " ", " ", " ", "+"},
{"+", "+", "+", "+", "+", "+", "+", "+", "+"},
};
And it is supposed to be printed like this:
+++++++++
+ M+
+ +++++ +
+ ++ + +
+ ++ +
+ ++++ +
+C +
+++++++++
Here is my code how I print it like that. The print is very fine as desired but the way it is coded and done is very inefficient... Isn't there a way to do all that with just few lines of code? Please note that it must look exactly as I posted.
Here is my way:
public class CatMouseCheap {
public static void main(String[] args){
String[][]field = {
{"+", "+", "+", "+", "+", "+", "+", "+", "+"},
{"+", " ", " ", " ", " ", " ", " ", "M", "+"},
{"+", " ", "+", "+", "+", "+", "+", " ", "+"},
{"+", " ", "+", "+", " ", " ", "+", " ", "+"},
{"+", " ", " ", " ", " ", "+", "+", " ", "+"},
{"+", " ", " ", "+", "+", "+", "+", " ", "+"},
{"+", "C", " ", " ", " ", " ", " ", " ", "+"},
{"+", "+", "+", "+", "+", "+", "+", "+", "+"},
};
for(int i=0; i<field.length; i++){
for(int j=0; j<field[i].length; j++){
System.out.print(field[i][j]);
}
System.out.println("");
}
}
}