I have to create a maze game in my class. I've created the maze, but I need to share the variables from the main class to the other classes (it is a requirement).
Here is my main code:
import java.io.*;
import java.util.Scanner;
public class MazeGame
{
public static void main(String[] args)
{
getVariables();
}
static void getVariables()
{
String fileName = "C:\\Users\\baileyjstewart\\Documents\\NetBeansProjects\\MazeGame\\src\\Maze.input";
int size;
int row;
int column;
String line = null;
try {
// FileReader reads text files in the default encoding.
FileReader fileReader = new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader = new BufferedReader(fileReader);
Scanner s = new Scanner(new File("C:\\Users\\baileyjstewart\\Documents\\NetBeansProjects\\MazeGame\\src\\Maze.input"));
int[][] array = new int[size = s.nextInt()][size];
for (row = 0; row < size; row++)
{
for(column = 0; column < size; column++)
{
array[row][column] = s.nextInt();
if(array[row][column] == 0)
{
System.out.print(" ");
//System.out.print(array [row][column] + " ");
}
else if(array[row][column] == 1)
{
System.out.print("X ");
}
else if(array[row][column] == 2)
{
System.out.print("E ");
}
}
System.out.println(" ");
}
// Always close files.
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '");
}
}
}
And I'm trying to share the variables row, column, and size into my Location class:
import java.io.*;
import java.util.Scanner;
public class Location
{
MazeGame Location = new MazeGame();
public Location()
{
String Wall;
String Space;
String Endpoint;
Boolean Visited;
Boolean hereNow;
}
public void getVariables()
{
Location.getVariables();
if(row == 0)
{
}
}
}
Thank you in advance for any help.