Hi all. So after an illness and other things i had enough time to think about my project. I decided i was going about it a more complicated way than what was needed. So now i've began work again. I felt lik i was getting along nicely until i had trouble printing my Snake array into my Grid 2D array.
If anyone can help me with the error and why i cannot print the snake onto the grid that would be great?
Thanks.
Grid Class:
import java.lang.*;
public class Grid
{
public static void main(String[] args)
{
//Final int of ROWS and COLS for the grid size
final int ROWS = 33;
final int COLS = 33;
// int counter will be used to display the grid
int counter = 0;
//Create new String array called Grid
String[][] Grid = new String[ROWS][COLS];
//new Food, Snake and Catcher
Food Fd = new Food();
Snake Sn = new Snake();
Catcher cat = new Catcher();
//Nested for loops to display the grid
for (int i =0; i < Grid.length; i++)
{
for (int j = 0; j < Grid[0].length; j++)
{
Grid[i][j] = " ";
Grid[0] = "|";
Grid[i][32] = "|";
Grid[0][j] = "-";
Grid[32][j] = "-";
Grid[12][12] = Fd.food;//Print food F onto grid
Grid[15][15] = Sn.snake;//Print snake onto grid (NOT WORKING YET!!)
Grid[5][10] = cat.catcher;//print catcher on grid
System.out.print(Grid[i][j]);//Prints grid
counter = counter + 1;
if(counter == 33)
{
counter = 0;
System.out.println("");
}
}
}
}
}
Snake Class:
import java.lang.*;
public class Snake
{
public static void main(String[] args)
{
final int Snake = 20;
String[] snake = new String[Snake];
for (int h =0; h < snake.length; h++)
{
snake[0] = "+";
snake[1] = "*";
snake[2] = "*";
snake[3] = "*";
System.out.println(snake[h]);
}
}
}Error:
Grid.java:28: cannot find symbol
symbol : variable snake
location: class Snake
Grid[15][15] = Sn.snake;
^
1 error