Recursive maze game

hi, i am trying to develop a recursive maze game. i am able to traversal the maze bt i get an array index out of bound exception. the code which i have develped is (wall of maze is denoted by # n way is denoted as O, path with X )
public void mazeTraversal(int a , int b)
print();
if(a < 0 || b < 0 || a > maze.length || b > maze.length)//to check for boundaries of the maze.
return;
}//end if
maze[a]='X';// assumes that starting location has a path
print();
//east direction from the current location
if(a>=0&&b>=0&&a<=maze.length&&b<=maze.length&&maze[a][b+1]=='0')
maze[a][b+1]='X';
mazeTraversal(a,b+1);
}//end if
//south direction from the current location
else if(a>=0&&b>=0&&a<=maze.length&&b<=maze.length&&maze[a+1][b]=='0')
maze[a+1][b]='X';
mazeTraversal(a+1,b);
} //end else if
//north direction from the current location
else if(a>=0&&b>=0&&a<=maze.length&&b<=maze.length&&maze[a-1][b]=='0')
maze[a-1][b]='X';
mazeTraversal(a-1,b);
}//end else if
//west direction from the current location
else if(a>=0&&b>=0&&a<=maze.length&&b<=maze.length&&maze[a][b-1]=='0')
maze[a][b-1]='X';
mazeTraversal(a,b-1);
}//end else if
else
System.out.println("Sorry... no way out");
}//end method
thks in advance

public void mazeTraversal(int a , int b)
       maze[a]='X';
print();
if(a < 0 || b < 0 || a > maze.length-1 || b > maze.length-1)//to check for boundaries of the maze.
return;
}//end if
// assumes that starting location has a path
//print();
//east direction from the current location
else if(maze[a][b+1]=='0')//ERROR
maze[a][b+1]='X';
mazeTraversal(a,b+1);//ERROR
}//end if
//south direction from the current location
else if(maze[a+1][b]=='0')//ERROR
maze[a+1][b]='X';
mazeTraversal(a+1,b);//ERROR
} //end else if
//north direction from the current location
else if(maze[a-1][b]=='0')//ERROR
maze[a-1][b]='X';
mazeTraversal(a-1,b);//ERROR
}//end else if
//west direction from the current location
else if(maze[a][b-1]=='0')//ERROR
maze[a][b-1]='X';
mazeTraversal(a,b-1);//ERROR
}//end else if
else
System.out.println("Sorry... no way out");
}//end method
giving error at line mazeTraversal()
First Maze:
#000#000000#
00#0#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
First Maze Traversal :
#000#000000#
X0#0#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#000#000000#
XX#0#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#X00#000000#
XX#0#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XX0#000000#
XX#0#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#0#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XX#000000#
XX#X#0####0#
###0#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#0000###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00X0###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####0#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#0#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#0#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#0#0#
#00000000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#0#0#
#000X0000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#0#0#
#000XX000#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#0#0#
#000XXX00#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#0#0#
#000XXXX0#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#0#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#0#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#0#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###0#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0000#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#000X#0#
#00XX###X#00
####X#0#X#0#
##0#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#00XX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#0XXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#0####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#000000#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#X00000#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XX0000#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XXX000#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XXXX00#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0X
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XXXXX0#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XXXXXX#
XX#X#X####0#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XXXXXX#
XX#X#X####X#
###X#XXXX#0#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#XXXXXX#
XX#X#X####X#
###X#XXXX#X#
#00XX###X#00
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
------------------------Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
     at Maze.mazeTraversal(Maze.java:46)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
#XXX#XXXXXX#
XX#X#X####X#
###X#XXXX#X#
#00XX###X#X0
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
#XXX#     at Maze.mazeTraversal(Maze.java:62)
at Maze.mazeTraversal(Maze.java:62)
     at Maze.mazeTraversal(Maze.java:68)
     at Maze.mazeTraversal(Maze.java:68)
     at Maze.mazeTraversal(Maze.java:68)
     at Maze.mazeTraversal(Maze.java:62)
     at Maze.mazeTraversal(Maze.java:62)
     at Maze.mazeTraversal(Maze.java:62)
     at Maze.mazeTraversal(Maze.java:62)
     at Maze.mazeTraversal(Maze.java:62)
     at MazXXXXXX#
XX#X#X####X#
###X#XXXX#X#
#00XX###X#XX
####X#0#X#0#
#00#X#0#X#0#
##0#X#0#X#0#
#000XXXXX#0#
######0###0#
#000000#000#
e.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:55)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:49)
     at Maze.mazeTraversal(Maze.java:62)
     at Maze.mazeTraversal(Maze.java:49)
     at TestMaze.main(TestMaze.java:51)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Simple Maze Game (Pac Man Style) Best Practice

    Hi
    I wanting to create a really basic pac man style maze game, its actually for some marketing materials and it will be really used as means of navigation rather than as a game, I want pac mac to eat certain words and when that happens it will tell the user about that topic.
    I don't need ghosts or anything like that.
    Just wondering the best way for pac man to work his way around the maze?
    Would I be best using hit detection?
    Also what would be the best way to remove the pellets as he eats them? visibility or remove child?
    Thanks in advance..

    Congrats to Noah and Mr. X!
     System Center Technical Guru - March 2015  
    Noah Stahl
    Make System Center Orchestrator Text Faster than a Teenager using PowerShell
    and Twilio
    Ed Price: "Wow, I love the breakdown of sections. As Alan wrote in the comments, "Wow! Great article!""
    Mr X
    How to educate your users to regularly reboot their Windows computers
    Ed Price: "I love the table and use of code snippets and images! Great article!"
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • I need help on a maze game...

    I need to create a maze game, consist of a 14x18 grid that contains various obstacles. At the beginning of the game, the player is positioned at the upper left-hand corner of the grid. Each space of the board may have one of the following items in it: an immovable block, a moveable block, a bomb, or nothing. The items in the game have the following behavior:
    1. The player is controlled by the user. The player may move up, down, left, or right.
    2. An empty space is empty. Anything may move into an empty space.
    3. An immovable block cannot move. Nothing may move the grid space that an immovable block occupies.
    4. A moveable block can be pushed by the user. It cannot be pushed off of the grid. It cannot be pushed onto a space that an immovable block occupies. A movable block can be pushed into a space that is occupied by another moveable block provided that the second moveable block can move in turn.
    5. A bomb space looks just like an empty space, however it's behavior is quite different. Only when something moves into its space does it become visible. If a player moves into the space, the bomb explodes, killing the player. If a moveable piece is moved into a bomb space, the bomb becomes visible. The bomb will still be active, meaning a player will still want to avoid this grid location.
    The goal of the game is for the player to move from the upper left-hand corner to any grid location in the rightmost column. The player is moved by the input entered by the user.
    So far, I have succesfully made the Simple console input for this game. The source code is as following.
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    public class SimpleConsoleInput
    * Get a single character from the user
    * @return value entered by the user
    public char getChar()
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
    System.out.print(":");
    // Declare and initialize the char
    char character = ' ';
    // Get the character from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    character = (char) br.read();
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter a character: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    // Return the character obtained from the keyboard
    return character;
    * Get a single character from the user
    * @return value entered by the user
    * @param prompt - String to prompt the user with
    public char getChar(String prompt)
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
    System.out.print(prompt + ":");
    // Declare and initialize the char
    char character = ' ';
    // Get the character from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    character = (char) br.read();
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter a character: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    // Return the character obtained from the keyboard
    return character;
    * Get a double from the user
    * @return value entered by the user
    public double getDouble()
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print(":");
    // Declare and initialize the double
    double number = 0.0;
    // Get the number from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    String line = br.readLine();
    number = Double.parseDouble(line);
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter a double: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    // Return the number obtained from the keyboard
    return number;
    * Get a double from the user
    * @return value entered by the user
    * @param prompt - String to prompt the user with
    public double getDouble(String prompt)
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
    System.out.print(prompt + ":");
    // Declare and initialize the double
    double number = 0.0;
    // Get the number from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    String line = br.readLine();
    number = Double.parseDouble(line);
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter a double: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    // Return the number obtained from the keyboard
    return number;
    * Get an int from the user
    * @return value entered by the user
    public int getInt()
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
    System.out.print(":");
    // Declare and initialize the int
    int number = 0;
    // Get the number from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    String line = br.readLine();
    number = Integer.parseInt(line);
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter an integer: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    // Return the number obtained from the keyboard
    return number;
    * Get an int from the user
    * @return value entered by the user
    * @param prompt - String to prompt the user with
    public int getInt(String prompt)
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
    System.out.print(prompt + ":");
    // Declare and initialize the int
    int number = 0;
    // Get the number from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    String line = br.readLine();
    number = Integer.parseInt(line);
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter an integer: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    // Return the number obtained from the keyboard
    return number;
    * Get a String from the user
    * @return value entered by the user
    public String getString()
    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
    System.out.print(":");
    String name = null;
    // Get the string from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    name = console.readLine();
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter a string: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    return name;
    * Get a String from the user
    * @return value entered by the user
    * @param prompt - String to prompt the user with
    public String getString(java.lang.String prompt)
    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
    System.out.print(prompt + ":");
    String name = null;
    // Get the string from the keyboard
    boolean successfulInput = false;
    while( !successfulInput )
    try
    name = console.readLine();
    successfulInput = true;
    catch (NumberFormatException ex)
    System.out.println("Please enter a string: ");
    catch(Exception ex)
    System.out.println(ex);
    System.exit(0);
    return name;
    * The main program for the SimpleInput class
    * @param args - The command line arguments
    public static void main(java.lang.String[] args)
    SimpleConsoleInput i = new SimpleConsoleInput();
    i.getString("Please Enter an Integer for me");
    Now is the bard part for me...
    I need to generate a random maze wioth those items. So far I can only make the maze using a template. The part of maze generator is given below...
    public class Maze extends Applet {
    String levels[] = {
    "M^^^^#####" +
    "M^^^^# #" +
    "M^^^^#$ #" +
    "M^^### $##" +
    "M^^# $ $ #" +
    "M### # ## #^^^######" +
    "M# # ## ##### ..#" +
    "M# $ $ ..#" +
    "M##### ### #@## ..#" +
    "M^^^^# #########" +
    "M^^^^#######",
    "M############" +
    "M#.. # ###" +
    "M#.. # $ $ #" +
    "M#.. #$#### #" +
    "M#.. @ ## #" +
    "M#.. # # $ ##" +
    "M###### ##$ $ #" +
    "M^^# $ $ $ $ #" +
    "M^^# # #" +
    "M^^############",
    "M^^^^^^^^########" +
    "M^^^^^^^^# @#" +
    "M^^^^^^^^# $#$ ##" +
    "M^^^^^^^^# $ $#" +
    "M^^^^^^^^##$ $ #" +
    "M######### $ # ###" +
    "M#.... ## $ $ #" +
    "M##... $ $ #" +
    "M#.... ##########" +
    "M########M",
    "M^^^^^^^^^^^########" +
    "M^^^^^^^^^^^# ....#" +
    "M############ ....#" +
    "M# # $ $ ....#" +
    "M# $$$#$ $ # ....#" +
    "M# $ $ # ....#" +
    "M# $$ #$ $ $########" +
    "M# $ # #" +
    "M## #########" +
    "M# # ##" +
    "M# $ ##" +
    "M# $$#$$ @#" +
    "M# # ##" +
    "M###########",
    "M^^^^^^^^#####" +
    "M^^^^^^^^# #####" +
    "M^^^^^^^^# #$## #" +
    "M^^^^^^^^# $ #" +
    "M######### ### #" +
    "M#.... ## $ $###" +
    "M#.... $ $$ ##" +
    "M#.... ##$ $ @#" +
    "M######### $ ##" +
    "M^^^^^^^^# $ $ #" +
    "M^^^^^^^^### ## #" +
    "M^^^^^^^^^^# #" +
    "M^^^^^^^^^^######",
    "M######^^###" +
    "M#.. #^##@##" +
    "M#.. ### #" +
    "M#.. $$ #" +
    "M#.. # # $ #" +
    "M#..### # $ #" +
    "M#### $ #$ #" +
    "M^^^# $# $ #" +
    "M^^^# $ $ #" +
    "M^^^# ## #" +
    "M^^^#########",
    "M^^^^^^^#####" +
    "M^####### ##" +
    "M## # @## $$ #" +
    "M# $ #" +
    "M# $ ### #" +
    "M### #####$###" +
    "M# $ ### ..#" +
    "M# $ $ $ ...#" +
    "M# ###...#" +
    "M# $$ #^#...#" +
    "M# ###^#####" +
    "M####",
    "M^^^^^^^^^^#######" +
    "M^^^^^^^^^^# ...#" +
    "M^^^^^^##### ...#" +
    "M^^^^^^# . .#" +
    "M^^^^^^# ## ...#" +
    "M^^^^^^## ## ...#" +
    "M^^^^^### ########" +
    "M^^^^^# $$$ ##" +
    "M^##### $ $ #####" +
    "M## #$ $ # #" +
    "M#@ $ $ $ $ #" +
    "M###### $$ $ #####" +
    "M^^^^^# #" +
    "M^^^^^########",
    "M^###^^#############" +
    "M##@#### # #" +
    "M# $$ $$ $ $ ...#" +
    "M# $$$# $ #...#" +
    "M# $ # $$ $$ #...#" +
    "M### # $ #...#" +
    "M# # $ $ $ #...#" +
    "M# ###### ###...#" +
    "M## # # $ $ #...#" +
    "M# ## # $$ $ $##..#" +
    "M# ..# # $ #.#" +
    "M# ..# # $$$ $$$ #.#" +
    "M##### # # #.#" +
    "M^^^^# ######### #.#" +
    "M^^^^# #.#" +
    "M^^^^###############",
    "M^^^^^^^^^^####" +
    "M^^^^^####^# #" +
    "M^^^### @###$ #" +
    "M^^## $ #" +
    "M^## $ $$## ##" +
    "M^# #$## #" +
    "M^# # $ $$ # ###" +
    "M^# $ # # $ #####" +
    "M#### # $$ # #" +
    "M#### ## $ #" +
    "M#. ### ########" +
    "M#.. ..#^####" +
    "M#...#.#" +
    "M#.....#" +
    "M#######",
    "M^^####" +
    "M^^# ###########" +
    "M^^# $ $ $ #" +
    "M^^# $# $ # $ #" +
    "M^^# $ $ # #" +
    "M### $# # #### #" +
    "M#@#$ $ $ ## #" +
    "M# $ #$# # #" +
    "M# $ $ $ $ #" +
    "M^#### #########" +
    "M^^# #" +
    "M^^# #" +
    "M^^#......#" +
    "M^^#......#" +
    "M^^#......#" +
    "M^^########",
    "M################" +
    "M# #" +
    "M# # ###### #" +
    "M# # $ $ $ $# #" +
    "M# # $@$ ## ##" +
    "M# # $ $ $###...#" +
    "M# # $ $ ##...#" +
    "M# ###$$$ $ ##...#" +
    "M# # ## ##...#" +
    "M##### ## ##...#" +
    "M^^^^##### ###" +
    "M^^^^^^^^# #" +
    "M^^^^^^^^#######",
    "M^^^#########" +
    "M^^## ## #####" +
    "M### # # ###" +
    "M# $ #$ # # ... #" +
    "M# # $#@$## # #.#. #" +
    "M# # #$ # . . #" +
    "M# $ $ # # #.#. #" +
    "M# ## ##$ $ . . #" +
    "M# $ # # #$#.#. #" +
    "M## $ $ $ $... #" +
    "M^#$ ###### ## #" +
    "M^# #^^^^##########" +
    "M^####",
    "M^^^^^^^#######" +
    "M^####### #" +
    "M^# # $@$ #" +
    "M^#$$ # #########" +
    "M^# ###......## #" +
    "M^# $......## # #" +
    "M^# ###...... #" +
    "M## #### ### #$##" +
    "M# #$ # $ # #" +
    "M# $ $$$ # $## #" +
    "M# $ $ ###$$ # #" +
    "M##### $ # #" +
    "M^^^^### ### # #" +
    "M^^^^^^# # #" +
    "M^^^^^^######## #" +
    "M^^^^^^^^^^^^^####",
    "M^^^^#######" +
    "M^^^# # #" +
    "M^^^# $ #" +
    "M^### #$ ####" +
    "M^# $ ##$ #" +
    "M^# # @ $ # $#" +
    "M^# # $ ####" +
    "M^## ####$## #" +
    "M^# $#.....# # #" +
    "M^# $..**. $# ###" +
    "M## #.....# #" +
    "M# ### #######" +
    "M# $$ # #" +
    "M# # #" +
    "M###### #" +
    "M^^^^^#####",
    "M#####" +
    "M# ##" +
    "M# #^^####" +
    "M# $ #### #" +
    "M# $$ $ $#" +
    "M###@ #$ ##" +
    "M^# ## $ $ ##" +
    "M^# $ ## ## .#" +
    "M^# #$##$ #.#" +
    "M^### $..##.#" +
    "M^^# #.*...#" +
    "M^^# $$ #.....#" +
    "M^^# #########" +
    "M^^# #" +
    "M^^####",
    "M^^^##########" +
    "M^^^#.. # #" +
    "M^^^#.. #" +
    "M^^^#.. # ####" +
    "M^^####### # ##" +
    "M^^# #" +
    "M^^# # ## # #" +
    "M#### ## #### ##" +
    "M# $ ##### # #" +
    "M# # $ $ # $ #" +
    "M# @$ $ # ##" +
    "M#### ## #######" +
    "M^^^# #" +
    "M^^^######",
    "M^^^^^###########" +
    "M^^^^^# . # #" +
    "M^^^^^# #. @ #" +
    "M^##### ##..# ####" +
    "M## # ..### ###" +
    "M# $ #... $ # $ #" +
    "M# .. ## ## ## #" +
    "M####$##$# $ # # #" +
    "M^^## # #$ $$ # #" +
    "M^^# $ # # # $## #" +
    "M^^# #" +
    "M^^# ########### #" +
    "M^^####^^^^^^^^^####",
    "M^^######" +
    "M^^# @####" +
    "M##### $ #" +
    "M# ## ####" +
    "M# $ # ## #" +
    "M# $ # ##### #" +
    "M## $ $ # #" +
    "M## $ $ ### # #" +
    "M## # $ # # #" +
    "M## # #$# # #" +
    "M## ### # # ######" +
    "M# $ #### # #....#" +
    "M# $ $ ..#.#" +
    "M####$ $# $ ....#" +
    "M# # ## ....#" +
    "M###################",
    "M^^^^##########" +
    "M##### ####" +
    "M# # $ #@ #" +
    "M# #######$#### ###" +
    "M# # ## # #$ ..#" +
    "M# # $ # # #.#" +
    "M# # $ # #$ ..#" +
    "M# # ### ## #.#" +
    "M# ### # # #$ ..#" +
    "M# # # #### #.#" +
    "M# #$ $ $ #$ ..#" +
    "M# $ # $ $ # #.#" +
    "M#### $### #$ ..#" +
    "M^^^# $$ ###....#" +
    "M^^^# ##^######" +
    "M^^^########"
    final static char wall = '#';
    final static char floor = ' ';
    final static char me = '@';
    final static char bomb = '&';
    final static char movableBlock = '*';
    final static char goal = '.';
    Would someone please help me on this game...

    More information about this game:
    The game should generate a random obstacle course for the player. The first column of the grid, however, should consist of all empty pieces, with the exception of the upper left-hand corner, which is the grid location where the player initially resides.
    Enter a loop in which the following things happen (not necessarily in this order):
    Print the current board configuration. Additionally, a key should be printed describing what each piece is.
    Get an action from the user. The player can move up, down, left, or right. Use the following controls: up = 'i', down = 'm', left = 'j', right = 'k'. The player can move at most one block at a time. Of course, if the player tries to move into a spot occupied by an immovable block, the player will not move.
    Inform the player whether they have won, or if they have lost (a player loses if they step on a bomb piece).
    If the player types 'q', the game should terminate.
    I am still stuck on this maze generator stuff.... Please help me....

  • Can I get the ipod nano maze game on my iphone?

    My son loves the maze game that comes on the ipod nano (4th or 5th generation).   Can I get this for my iphone 3G ?  
    I can't find it it in the app store fopr iphones.

    j_chapel_hill wrote:
    My son loves the maze game that comes on the ipod nano (4th or 5th generation).   Can I get this for my iphone 3G ?  
    I can't find it it in the app store fopr iphones.
    You didn't look hard enough. Nano Maze

  • I am being charged for mouse maze games that were supposed to be free, why an i getting billed? see below

    Billed To:
    KATHY ARENA
    USA
    Order Total: $50.70
    Billed To: Visa
    Item
    Seller
    Type
    Unit Price
    Mouse Maze Free Game - by Top Free Games - Best Apps, Dog
    Report a Problem
    Top Free Games
    In-App Purchase
    $6.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Two Freezing Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $0.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Five Nuclear Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $5.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Five Super Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $2.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Twenty Super Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $9.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Twenty Nuclear Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $19.99
    Subtotal:
    $46.94
    Tax:
    $3.76
    Order Total:
    $50.70
    Please retain for your records.
    Please See Below For Terms And Conditions Pertaining To This Order.
    Apple Inc.
    You can find the iTunes Store Terms of Sale and Sales Policies by launching your iTunes application and clicking on Terms of Sale or Sales Policies
    Answers to frequently asked questions regarding the iTunes Store can be found at http://www.apple.com/support/itunes/store/
    <Personal Information Edited by Host>

    You are getting charged for "In-App" purchases. And yes, those trinkets you purchase within the game are with real $$$$$
    Stedman

  • I am being charged for mouse maze games that were supposed to be free, why am i getting billed for original free games? see below.

    Item
    Seller
    Type
    Unit Price
    Mouse Maze Free Game - by Top Free Games - Best Apps, Dog
    Report a Problem
    Top Free Games
    In-App Purchase
    $6.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Two Freezing Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $0.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Five Nuclear Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $5.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Five Super Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $2.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Twenty Super Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $9.99
    Mouse Maze Free Game - by Top Free Games - Best Apps, Twenty Nuclear Potions
    Report a Problem
    Top Free Games
    In-App Purchase
    $19.99
    Subtotal:
    $46.94
    Tax:
    $3.76
    Order Total:
    $50.70
    Please retain for your records.
    Please See Below For Terms And Conditions Pertaining To This Order.
    Apple Inc.
    You can find the iTunes Store Terms of Sale and Sales Policies by launching your iTunes application and clicking on Terms of Sale or Sales Policies
    Answers to frequently asked questions regarding the iTunes Store can be found at http://www.apple.com/support/itunes/store/

    See your previous post of the same title.

  • Help on a Recursive Maze

    Java Maze is already a recursive program. (I think-if not please let me know if my program is not recusive.) It prints a 3 wherever it moves and wherever it is possible to have that spot as part of the exit path for the Maze. It prints a 7 if the spot is part of the final pathway to the exit. The program supposedly stores the value of the spots it encounters and then backtracks to find the exit strategy. I need help with the following addition:
    Modify the maze class so that it prints out the
    path of the final solution as it is discovered, without
    storing it. If you can help me know what i need to change that would be good too.
    Here is the code I have for now with the runner first and the Maze class second. Thanks in advance.
    public class MazeSearch
       //  Creates a new maze, prints its original form, tries to
       //  solve it, and prints out its final form.
       public static void main (String[] args)
          Maze labyrinth = new Maze();
          System.out.println (labyrinth);
          if (labyrinth.traverse (0, 0))
             System.out.println ("The maze was successfully solved!");
          else
             System.out.println ("There is no possible path.");
          System.out.println (labyrinth);
    public class Maze
       private final int TRIED = 3;
       private final int PATH = 7;
       private int[][] grid = { {1,1,1,0,1,1,0,0,0,1,1,1,1},
                                {1,0,1,1,1,0,1,1,1,1,0,0,1},
                                {0,0,0,0,1,0,1,0,1,0,1,0,0},
                                {1,1,1,0,1,1,1,0,1,0,1,1,1},
                                {1,0,1,0,0,0,0,1,1,1,0,0,1},
                                {1,0,1,1,1,1,1,1,0,1,1,1,1},
                                {1,0,0,0,0,0,0,0,0,0,0,0,0},
                                {1,1,1,1,1,1,1,1,1,1,1,1,1} };
       //  Tries to recursively follow the maze. Inserts special
       //  characters for locations that have been tried and that
       //  eventually become part of the solution.
       public boolean traverse (int row, int column)
          boolean done = false;
          if (valid (row, column))
             grid[row][column] = TRIED;  // this cell has been tried
             if (row == grid.length-1 && column == grid[0].length-1)
                done = true;  // the maze is solved
             else
                done = traverse (row+1, column);     // down
                if (!done)
                   done = traverse (row, column+1);  // right
                if (!done)
                   done = traverse (row-1, column);  // up
                if (!done)
                   done = traverse (row, column-1);  // left
             if (done)  // this location is part of the final path
                grid[row][column] = PATH;
          return done;
       //  Determines if a specific location is valid.
       private boolean valid (int row, int column)
          boolean result = false;
          // check if cell is in the bounds of the matrix
          if (row >= 0 && row < grid.length &&
              column >= 0 && column < grid[row].length)
             //  check if cell is not blocked and not previously tried
             if (grid[row][column] == 1)
                result = true;
          return result;
       //  Returns the maze as a string.
       public String toString ()
          String result = "\n";
          for (int row=0; row < grid.length; row++)
             for (int column=0; column < grid[row].length; column++)
                result += grid[row][column] + "";
             result += "\n";
          return result;
    }

    Well okay you've posted this a second time in the same forum...
    http://forum.java.sun.com/thread.jspa?threadID=5263177&tstart=0
    Now go ahead and explain in your own words what it is you think you are supposed to do.

  • Help! How to Create Wall Barrier for Maze Game

    Hi - I'm working on a simple maze program that has ball which is controlled by the up, down. left, right arrow keys.  I made a maze image in Photoshop and brought it into the Flash CS6 and CC (AS3). I made one wall barrier called wallDet1_mc to test before creating other wall barriers. It doesn't work. The ball goes through the wall everytime I test it.  Any help on this would be greatly appreciated.  If anyone has a basic maze with arrow keys control where their object do not cross over the wall please let me know how to do this. Thanks.

    Still doesn't work, and I was working on it and I cannot get the object (carP_mc) to not go through the wall. There has to be a code or math equation to stop it from doing this.  If the wall detection picks up the car at the wall then it should keep it away by the same amount of pixels.  What do you think?  Below is a revamped program and thanks again for your help:
    import flash.events.KeyboardEvent;
    stop();
    /* Move with Keyboard Arrows
    Allows the specified symbol instance to be moved with the keyboard arrows.
    Instructions:
    1. To increase or decrease the amount of movement, replace the number 5 below with the number of pixels you want the symbol instance to move with each key press.
    Note the number 5 appears four times in the code below.
    wallDet1_mc.enabled= false;
    var upPressed:Boolean = false;
    var downPressed:Boolean = false;
    var leftPressed:Boolean = false;
    var rightPressed:Boolean = false;
    carP_mc.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_3);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);
    stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);
    stage.addEventListener(Event.ENTER_FRAME, everyFrame);
    function fl_MoveInDirectionOfKey_3(event:Event)
        if (upPressed)
            carP_mc.y -= 5;
        if (downPressed)
            carP_mc.y += 5;
        if (leftPressed)
            carP_mc.x -= 5;
        if (rightPressed)
            carP_mc.x += 5;
    function fl_SetKeyPressed_3(event:KeyboardEvent):void
        switch (event.keyCode)
            case Keyboard.UP:
                upPressed = true;
                break;
            case Keyboard.DOWN:
                downPressed = true;
                break;
            case Keyboard.LEFT:
                leftPressed = true;
                break;
            case Keyboard.RIGHT:
                rightPressed = true;
                break;
    function fl_UnsetKeyPressed_3(event:KeyboardEvent):void
        switch (event.keyCode)
            case Keyboard.UP:
                upPressed = false;
                break;
            case Keyboard.DOWN:
                downPressed = false;
                break;
            case Keyboard.LEFT:
                leftPressed = false;
                break;
            case Keyboard.RIGHT:
                rightPressed = false;
                break;
    function everyFrame(event:Event):void {
    var mazehit:Boolean = false;
    if (upPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc)) {
    carP_mc.y -= 5;
    mazehit = true;
    //break;
    if (downPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc)) {
    carP_mc.y += 5;
    mazehit = true;
    //break;
    if (leftPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc)) {
    carP_mc.x -= 5;
    mazehit = true;
    //break;
    if (rightPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc)) {
    carP_mc.x += 5;
    mazehit = true;
    //break;
    //End of program. Not using the codes below
    /**onClipEvent(enterFrame){
        if(this.hitArea(carP_mc._x,carP_mc._y, true)){                   
            carP_mc._x=carP_mc._x;
            carP_mc._y=carP_mc._y;
    //Keyboard Listener on stage
    //stage.addEventListener(KeyboardEvent.KEY_DOWN, theKeysDown);
    //stage.addEventListener(KeyboardEvent.KEY_UP, theKeysUp);
    //Makes MazeArt follow the movement of the path_mc
    /*addEventListener(Event.ENTER_FRAME, onNewFrame01);
    function onNewFrame01(e:Event):void{
        maze_mc.x=wallDet1_mc.x;
        maze_mc.y=wallDet1_mc.y
    function Car_P(e:KeyboardEvent):void
        //maze_mc.addEventListener(KeyboardEvent, wallDet1_mc);
        //wallDet1_mc.addEventListener(KeyboardEvent.KEY_DOWN, maze_mc);

  • Need to Create a Wall Barrier and Detection for Maze Game

    Hi, I have a basic maze that I created the artwork in Photoshop and brought it into Flash as a PNG file.  My trouble is that my car object is going through the wall.  Could someone help me on correcting this.  I've been trying for hours to fix this but was unsuccessful.  I'm hoping someone out there has some advice on how to get it to work.  Thanks in advance.
    Iz

    Hi - I put in the codes for the upPressed (to test it) and these are the errors that came up. 
    Scene 1, Layer 'Actions', Frame 1, Line 110
    1120: Access of undefined property speed.
    Scene 1, Layer 'Actions', Frame 1, Line 110
    1120: Access of undefined property i.
    Scene 1, Layer 'Actions', Frame 1, Line 110
    1120: Access of undefined property i.
    Scene 1, Layer 'Actions', Frame 1, Line 114
    1120: Access of undefined property wallhitBool.
    Scene 1, Layer 'Actions', Frame 1, Line 112
    1120: Access of undefined property i.
    Scene 1, Layer 'Actions', Frame 1, Line 110
    1120: Access of undefined property i.
    Here is the updated program:
    import flash.events.KeyboardEvent;
    stop();
    /* Move with Keyboard Arrows
    Allows the specified symbol instance to be moved with the keyboard arrows.
    Instructions:
    1. To increase or decrease the amount of movement, replace the number 5 below with the number of pixels you want the symbol instance to move with each key press.
    Note the number 5 appears four times in the code below.
    wallDet1_mc.enabled= false;
    wallDet2_mc.enabled= false;
    wallDet3_mc.enabled= false;
    wallDet4_mc.enabled= false;
    wallDet5_mc.enabled= false;
    wallDet6_mc.enabled= false;
    wallDet7_mc.enabled= false;
    wallDet8_mc.enabled= false;
    wallDet9_mc.enabled= false;
    wallDet10_mc.enabled= false;
    var upPressed:Boolean = false;
    var downPressed:Boolean = false;
    var leftPressed:Boolean = false;
    var rightPressed:Boolean = false;
    carP_mc.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_3);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_3);
    stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_3);
    stage.addEventListener(Event.ENTER_FRAME, everyFrame);
    function fl_MoveInDirectionOfKey_3(event:Event)
        if (upPressed)
            carP_mc.y -= 5;
        if (downPressed)
            carP_mc.y += 5;
        if (leftPressed)
            carP_mc.x -= 5;
        if (rightPressed)
            carP_mc.x += 5;
    function fl_SetKeyPressed_3(event:KeyboardEvent):void
        switch (event.keyCode)
            case Keyboard.UP:
                upPressed = true;
                break;
            case Keyboard.DOWN:
                downPressed = true;
                break;
            case Keyboard.LEFT:
                leftPressed = true;
                break;
            case Keyboard.RIGHT:
                rightPressed = true;
                break;
    function fl_UnsetKeyPressed_3(event:KeyboardEvent):void
        switch (event.keyCode)
            case Keyboard.UP:
                upPressed = false;
                break;
            case Keyboard.DOWN:
                downPressed = false;
                break;
            case Keyboard.LEFT:
                leftPressed = false;
                break;
            case Keyboard.RIGHT:
                rightPressed = false;
                break;
    function everyFrame(event:Event):void {
    var mazehit:Boolean = false;
    if (upPressed) {
    mazehit=false
    for(i = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(this["wallDet"+i+"_mc"])){
    wallhitBool=true;
    break;
    if(mazehit){
    carP_mc.x -= 5;
    if (downPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc))
    if(carP_mc.hitTestObject(wallDet2_mc))
    if(carP_mc.hitTestObject(wallDet3_mc))
    if(carP_mc.hitTestObject(wallDet4_mc))
    if(carP_mc.hitTestObject(wallDet5_mc))
    if(carP_mc.hitTestObject(wallDet6_mc))
    if(carP_mc.hitTestObject(wallDet7_mc))
    if(carP_mc.hitTestObject(wallDet8_mc))
    if(carP_mc.hitTestObject(wallDet9_mc))
    if(carP_mc.hitTestObject(wallDet10_mc)) 
    carP_mc.y -= 5;
    mazehit = true;
    //break;
    if (leftPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc))
    if(carP_mc.hitTestObject(wallDet2_mc))
    if(carP_mc.hitTestObject(wallDet3_mc))
    if(carP_mc.hitTestObject(wallDet4_mc))
    if(carP_mc.hitTestObject(wallDet5_mc))
    if(carP_mc.hitTestObject(wallDet6_mc))
    if(carP_mc.hitTestObject(wallDet7_mc))
    if(carP_mc.hitTestObject(wallDet8_mc))
    if(carP_mc.hitTestObject(wallDet9_mc))
    if(carP_mc.hitTestObject(wallDet10_mc))  {
    carP_mc.x += 5;
    mazehit = true;
    //break;
    if (rightPressed) {
    //for(var i:int = 0; i < speed; i++) {
    if(carP_mc.hitTestObject(wallDet1_mc))
    if(carP_mc.hitTestObject(wallDet2_mc))
    if(carP_mc.hitTestObject(wallDet3_mc))
    if(carP_mc.hitTestObject(wallDet4_mc))
    if(carP_mc.hitTestObject(wallDet5_mc))
    if(carP_mc.hitTestObject(wallDet6_mc))
    if(carP_mc.hitTestObject(wallDet7_mc))
    if(carP_mc.hitTestObject(wallDet8_mc))
    if(carP_mc.hitTestObject(wallDet9_mc))
    if(carP_mc.hitTestObject(wallDet10_mc))
    carP_mc.x -= 5;
    mazehit = true;
    //break;
    /**onClipEvent(enterFrame){
        if(this.hitArea(carP_mc._x,carP_mc._y, true)){                   
            carP_mc._x=carP_mc._x;
            carP_mc._y=carP_mc._y;
    //Keyboard Listener on stage
    //stage.addEventListener(KeyboardEvent.KEY_DOWN, theKeysDown);
    //stage.addEventListener(KeyboardEvent.KEY_UP, theKeysUp);
    //Makes MazeArt follow the movement of the path_mc
    /*addEventListener(Event.ENTER_FRAME, onNewFrame01);
    function onNewFrame01(e:Event):void{
        maze_mc.x=wallDet1_mc.x;
        maze_mc.y=wallDet1_mc.y
    function Car_P(e:KeyboardEvent):void
        //maze_mc.addEventListener(KeyboardEvent, wallDet1_mc);
        //wallDet1_mc.addEventListener(KeyboardEvent.KEY_DOWN, maze_mc);

  • Simple maze game for LV enjoyment and please help with my problem

    Here has a simple game for enjoyment, you can try to play and improve it with code/map etc.
    Green color represent player, and red for Exit.
    Hope you can kindly look at my problem and hope can get your kindly help.
    Thank you everyone.
    //BR
    Vincent
    Attachments:
    Maze_Game.zip ‏79 KB

    Sorry for the wrong link
    Here: my problem
    Thank you very much

  • I'm writing a mazerace game...I need help from a Java Pro regarding GUI

    I've tested my code using a textUI, but not successful with GUI.
    Following are the files I have at present but are incomplete...someone please assist me, let me know what I'm missing to run the program successfully in a window.
    All I need to do is to bring the maze (2D array) onto a window, and listen to the keys (A,S,D,W & J,K,L,I) and make the move accordingly (using the move method in the MazeRace Class)
    This is my class - MazeRace
    import javax.swing.*;
    import java.io.*;
    * This class is responsible for:
    * -Initializes instance variables used to store the current state of the game
    * -When a player moves it checks if the move is legal
    * and updates the state of the game if move is allowable and made
    * -Reports information about current state of the game when asked:
    * o whether game has been won
    * o how many moves have been made by a given player
    * o what is the current configuration of the maze, etc.
    public class MazeRace {
    /** The Maze Race layout */
    private static char[][] mazeLayout;
    /** Dimensions of the maze */
    //private static final int rowLength = mazeLayout.length;
    //private static final int columnLength = mazeLayout[0].length;
    /** space in the grid is a wall */
    private static final char wall = 'X';
    /** space in the grid has been used */
    private static final char spaceUsed = '.';
    /** space in the grid is available */
    private static final char spaceAvailable = ' ';
    /** Character for Charles, Ada & Goal*/
    private static final char CHARLES = 'C';
    private static final char ADA = 'A';
    private static final char GOAL = 'G';
    /** Location of Goal in the Maze */
    private static int rowGoal = 0;
    private static int columnGoal = 0;
    /** Location of Ada in the Maze */
    private static int rowAda = 0;
    private static int columnAda = 0;
    /** Location of Charles in the Maze */
    private static int rowCharles = 0;
    private static int columnCharles = 0;
    /** Number of Ada's moves */
    private static int countAdasMoves = 0;
    /** Number of Charles's moves */
    private static int countCharlesMoves = 0;
    * Constructor for MazeRace
    * &param mazeGrid - 2D array of characters
    public MazeRace(char[][] mazeGrid){
    this.mazeLayout = mazeGrid;
    for (int row = 0; row < mazeLayout.length; row++){
    for (int column = 0; column < mazeLayout[0].length; column++){
    if (mazeLayout[row][column] == GOAL){
    this.rowGoal = row;
    this.columnGoal = column;
    if (mazeLayout[row][column] == ADA){
    this.rowAda = row;
    this.columnAda = column;
    if (mazeLayout[row][column] == CHARLES){
    this.rowCharles = row;
    this.columnCharles = column;
    public boolean canMoveLeft(){
    int rowA = this.rowAda;
    int columnA = this.columnAda;
    int rowC = this.rowCharles;
    int columnC = this.rowCharles;
    boolean canMove = false;
    if (mazeLayout[rowA][columnA - 1] == spaceAvailable
    || mazeLayout[rowA][columnA - 1] == GOAL) {
    canMove = true;
    return canMove;
    * This method takes in a single character value that indicates
    * both the player making the move, and which direction the move is in.
    * If move is legal, the player's position will be updated. Move is legal
    * if player can move one space in that direction i.e. the player isn't
    * moving out of the maze, into a wall or a space has already been used.
    * @param moveDirection: indicates the player making the move and direction
    * @return moveMade: boolean value true if move was made, false otherwise
    public boolean move(char move){
    boolean validMove = false;
    /** store Ada's current row location in a temp variable */
    int rowA = this.rowAda;
    /** store Ada's current column location in a temp variable */
    int columnA = this.columnAda;
    /** store Charles current row location in a temp variable */
    int rowC = this.rowCharles;
    /** store Charles current column location in a temp variable */
    int columnC = this.columnCharles;
    /** if Ada is moving left, check if she can make a move */
    if (move == 'A' && (mazeLayout[rowA][columnA - 1] == spaceAvailable
    || mazeLayout[rowA][columnA - 1] == GOAL)) {
    /** if move is legal, then update old space to spaceUsed '.' */
    mazeLayout[rowA][columnA] = spaceUsed;
    /** update Ada's new position */
    mazeLayout[rowA][columnA - 1] = ADA;
    this.rowAda = rowA; //update new row location of Ada
    this.columnAda = columnA - 1; //update new column location of Ada
    validMove = true; //valid move has been made
    countAdasMoves++; //increment Ada's legal move
    /** if Ada is moving down, then check if she can make the move */
    if (move == 'S'&& (mazeLayout[rowA + 1][columnA] == spaceAvailable
    || mazeLayout[rowA + 1][columnA] == GOAL)) {
    mazeLayout[rowA][columnA] = spaceUsed;
    mazeLayout[rowA + 1][columnA] = ADA;
    this.rowAda = rowA + 1;
    this.columnAda = columnA;
    validMove = true;
    countAdasMoves++;
    /** if Ada is moving right, then check if she can make the move */
    if (move == 'D'&& (mazeLayout[rowA][columnA + 1] == spaceAvailable
    || mazeLayout[rowA][columnA + 1] == GOAL)) {
    mazeLayout[rowA][columnA] = spaceUsed;
    mazeLayout[rowA][columnA + 1] = ADA;
    this.rowAda = rowA;
    this.columnAda = columnA + 1;
    validMove = true;
    countAdasMoves++;
    /** if Ada is moving up, then check if she can make the move */
    if (move == 'W'&& (mazeLayout[rowA - 1][columnA] == spaceAvailable
    || mazeLayout[rowA - 1][columnA] == GOAL)) {
    mazeLayout[rowA][columnA] = spaceUsed;
    mazeLayout[rowA - 1][columnA] = ADA;
    this.rowAda = rowA - 1;
    this.columnAda = columnA;
    validMove = true;
    countAdasMoves++;
    /** if Charles is moving left, then check if he can make the move */
    if (move == 'J'&& (mazeLayout[rowC][columnC - 1] == spaceAvailable
    || mazeLayout[rowC][columnC - 1] == GOAL)) {
    mazeLayout[rowC][columnC] = spaceUsed;
    mazeLayout[rowC][columnC -1] = CHARLES;
    this.rowCharles = rowC;
    this.columnCharles = columnC - 1;
    validMove = true;
    countCharlesMoves++;
    /** if Charles is moving down, then check if he can make the move */
    if (move == 'K'&& (mazeLayout[rowC + 1][columnC] == spaceAvailable
    || mazeLayout[rowC + 1][columnC] == GOAL)) {
    mazeLayout[rowC][columnC] = spaceUsed;
    mazeLayout[rowC + 1][columnC] = CHARLES;
    this.rowCharles = rowC + 1;
    this.columnCharles = columnC;
    validMove = true;
    countCharlesMoves++;
    /** if Charles is moving right, then check if he can make the move */
    if (move == 'L'&& (mazeLayout[rowC][columnC + 1] == spaceAvailable
    || mazeLayout[rowC][columnC + 1] == GOAL)) {
    mazeLayout[rowC][columnC] = spaceUsed;
    mazeLayout[rowC][columnC + 1] = CHARLES;
    this.rowCharles = rowC;
    this.columnCharles = columnC + 1;
    validMove = true;
    countCharlesMoves++;
    /** if Charles is moving up, then check if he can make the move */
    if (move == 'I'&& (mazeLayout[rowC - 1][columnC] == spaceAvailable
    || mazeLayout[rowC - 1][columnC] == GOAL)){
    mazeLayout[rowC][columnC] = spaceUsed;
    mazeLayout[rowC - 1][columnC] = CHARLES;
    this.rowCharles = rowC - 1;
    this.columnCharles = columnC;
    validMove = true;
    countCharlesMoves++;
    return validMove;
    * This method indicates whether the current maze configuration is a winning
    * configuration for either player or not.
    * Return 1 if Ada won
    * Return 2 if Charles won
    * Return 0 if neither won
    * @return int won: Indicates who won the game (1 or 2) or no one won the
    * game (0)
    public static int hasWon() {
    int won = 0;
    /** if location of Goal's row and column equals Ada's then she won */
    if (rowGoal == rowAda && columnGoal == columnAda){
    won = 1;
    /** if location of Goal's row and column equals Charles's then he won */
    if (rowGoal == rowCharles && columnGoal == columnCharles){
    won = 2;
    /** if both players are away from the Goal then no one won */
    if ((rowGoal != rowAda && columnGoal != columnAda) &&
    (rowGoal != rowCharles && columnGoal != columnCharles)) {
    won = 0;
    return won;
    * This method indicates whether in the current maze configuration both
    * players are caught in dead ends.
    * @return deadEnd: boolean value true if both players can't make a valid
    * move, false otherwise
    public static boolean isBlocked(){
    boolean deadEnd = false;
    /** Check if Ada & Charles are blocked */
    if (((mazeLayout[rowAda][columnAda - 1] == wall
    || mazeLayout[rowAda][columnAda - 1] == spaceUsed
    || mazeLayout[rowAda][columnAda - 1] == CHARLES)
    && (mazeLayout[rowAda][columnAda + 1] == wall
    || mazeLayout[rowAda][columnAda + 1] == spaceUsed
    || mazeLayout[rowAda][columnAda + 1] == CHARLES)
    && (mazeLayout[rowAda + 1][columnAda] == wall
    || mazeLayout[rowAda + 1][columnAda] == spaceUsed
    || mazeLayout[rowAda + 1][columnAda] == CHARLES)
    && (mazeLayout[rowAda - 1][columnAda] == wall
    || mazeLayout[rowAda - 1][columnAda] == spaceUsed
    || mazeLayout[rowAda - 1][columnAda] == CHARLES))
    && ((mazeLayout[rowCharles][columnCharles - 1] == wall
    || mazeLayout[rowCharles][columnCharles - 1] == spaceUsed
    || mazeLayout[rowCharles][columnCharles - 1] == ADA)
    && (mazeLayout[rowCharles][columnCharles + 1] == wall
    || mazeLayout[rowCharles][columnCharles + 1] == spaceUsed
    || mazeLayout[rowCharles][columnCharles + 1] == ADA)
    && (mazeLayout[rowCharles + 1][columnCharles] == wall
    || mazeLayout[rowCharles + 1][columnCharles] == spaceUsed
    || mazeLayout[rowCharles + 1][columnCharles] == ADA)
    && (mazeLayout[rowCharles - 1][columnCharles] == wall
    || mazeLayout[rowCharles - 1][columnCharles] == spaceUsed
    || mazeLayout[rowCharles - 1][columnCharles] == ADA))) {
    deadEnd = true;
    return deadEnd;
    * This method returns an integer that represents the number of moves Ada
    * has made so far. Only legal moves are counted.
    * @return int numberOfAdasMoves: number of moves Ada has made so far
    public static int numAdaMoves() {
    return countAdasMoves;
    * This method returns an integer that represents the number of moves Charles
    * has made so far. Only legal moves are counted.
    * @return int numberOfCharlesMoves: number of moves Charles has made so far
    public static int numCharlesMoves() {
    return countCharlesMoves;
    * This method returns a 2D array of characters that represents the current
    * configuration of the maze
    * @return mazeLayout: 2D array that represents the current configuration
    * of the maze
    public static char[][] getGrid() {
    return mazeLayout;
    * This method compares contents of this MazeRace object to given MazeRace.
    * The two will not match if:
    * o the two grids have different dimensions
    * o the two grids have the same dimensios but positions of walls, players or
    * goal differs.
    * @param MazeRace: MazeRace object is passed in and compared with the given
    * MazeRace grid
    * @return boolean mazeEqual: true if both grids are same, false otherwise
    public static boolean equals(char[][] mr) {
    boolean mazeEqual = true;
    /** If the length of the arrays differs, then they are not equal */
    if (mr.length != mazeLayout.length || mr[0].length != mazeLayout[0].length){
    mazeEqual = false;
    } else {
    /** If lengths are same, then compare every element of the array to other */
    int count = 0;
    int row = 0;
    int column = 0;
    while( count < mr.length && mazeEqual) {
    if( mr[row][column] != mazeLayout[row][column]) {
    mazeEqual = false;
    count = count + 1;
    row = row + 1;
    column = column + 1;
    return mazeEqual;
    * This method represents the current state of the maze in a string form
    * @return string mazeString: string representation of the maze configuration
    public String toString() {
    String mazeString = "";
    for (int row = 0; row < mazeLayout.length; row++){
    for (int column = 0; column < mazeLayout[0].length; column++){
    mazeString = mazeString + mazeLayout[row][column];
    mazeString = mazeString + "\n";
    return mazeString.trim();
    The following is the Driver class: MazeRaceDriver
    import javax.swing.*;
    import java.io.*;
    * This class is the starting point for the maze race game. It is invoked
    * from the command line, along with the location of the layout file and
    * the desired interface type. Its main purpose is to initialize the
    * components needed for the game and the specified interface.
    public class MazeRaceDriver {
    * A method that takes a text file representation of the maze and
    * produces a 2D array of characters to represent the same maze.
    * @param layoutFileName location of the file with the maze layout
    * @return The maze layout.
    public static char[][] getLayoutFromFile( String layoutFileName )
    throws IOException {
    BufferedReader br = new BufferedReader(new FileReader(layoutFileName));
    String s = br.readLine();
    int r = 0; // start at row 1
    int c = s.length(); // initialize column to the length of the string
    while(s != null){
    r++;
    s = br.readLine();
    char[][]grid = new char[r][c];
    // this part, gets the text file into a char array
    BufferedReader brr = new BufferedReader(new FileReader(layoutFileName));
    String ss = brr.readLine();
    int row = 0;
    while(ss != null){
    for(int col = 0; col < c; col++){
    grid[row][col] = ss.charAt(col);
    row++;
    ss = brr.readLine();
    return grid;
    * The main method of your program.
    * @param args command-line arguments provided by the user
    public static void main( String[] args ) throws IOException {
    // check for too few or too many command line arguments
    if ( args.length != 2 ) {
    System.out.println( "Usage: " +
    "java MazeRaceDriver <location> <interface type>" );
    return;
    if ( args[1].toLowerCase().equals( "text" ) ) {
    char[][] layout = getLayoutFromFile( args[0] );
    MazeRace maze = new MazeRace( layout );
    MazeRaceTextUI game = new MazeRaceTextUI( maze );
    game.startGame();
    else if ( args[1].toLowerCase().equals( "gui" ) ) {
    // Get the filename using a JFileChooser
    // read the layout from the file
    // starting the window-based maze game
    JFileChooser chooser = new JFileChooser("");
    int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    BufferedReader br =
    new BufferedReader(new FileReader(chooser.getSelectedFile()));
    String inputLine = br.readLine();
    while (inputLine != null) {
    System.out.println(inputLine);
    inputLine = br.readLine();
    char[][] layout = getLayoutFromFile( args[0] );
    MazeRace maze = new MazeRace( layout );
    MazeRaceWindow game = new MazeRaceWindow( maze );
    game.startGame();
    } else {
    System.out.println("Cancel was selected");
    } else {
    System.out.println( "Invalid interface for game." +
    " Please use either TEXT or GUI." );
    return;
    The following is the MazeRaceWindow class
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    * This class is responsible for displaying the maze race game. It should
    * set up the maze window when the game is started and update the display
    * with each move.
    public class MazeRaceWindow extends JFrame {
    private JLabel[][] mazeLabel;
    private JFrame mazeFrame;
    * Reference to the underlying MazeRace object which needs to be
    * updated when either player moves
    private MazeRace maze;
    * Class constructor for the GUI object
    * @param maze the underlying MazeRace object
    public MazeRaceWindow( MazeRace maze ) {
    this.maze = maze;
    System.out.println(maze);
    mazeFrame = new JFrame();
    mazeFrame.setSize(200,200);
    Container content = mazeFrame.getContentPane();
    System.out.println(content);
    content.setLayout(new GridLayout(.length, mazeLayout[0].Length));
    for (int i = 0; i < MazeRace.length; i++ ) {
    for (int j = 0; j < MazeRace[0].length; j++ ) {
    mazeLabel = new JLabel[MazeRace.rowLength][MazeRace.columnLength];
    content.add(mazeLabel[i][j]);
    System.out.println(mazeLabel[i][j]);
    mazeFrame.pack();
    mazeFrame.setVisible(true);
    //content.add(mazeLabel);
    //mazeFrame.addKeyListener(this);
    * A method to be called to get the game running.
    public void startGame() throws IOException {
    System.out.println();
    /* loop to continue to accept moves as long as there is at least one
    * player able to move and no one has won yet
    while ( !maze.isBlocked() && maze.hasWon() == 0 ) {
    // prints out current state of maze
    System.out.println( maze.toString() );
    System.out.println();
    // gets next move from players
    System.out.println("Next move?");
    System.out.print("> ");
    BufferedReader buffer =
    new BufferedReader( new InputStreamReader( System.in ) );
    String moveText = "";
    moveText = buffer.readLine();
    System.out.println();
    // note that even if a string of more than one character is entered,
    // only the first character is used
    if ( moveText.length() >= 1 ) {
    char move = moveText.charAt( 0 );
    boolean validMove = maze.move( move );
    // The game has finished, so we output the final state of the maze, and
    // a message describing the outcome.
    System.out.println( maze );
    int status = maze.hasWon();
    if ( status == 1 ) {
    System.out.println( "Congratulations Ada! You won the maze in "
    + maze.numAdaMoves() + " moves!" );
    } else if ( status == 2 ) {
    System.out.println( "Congratulations Charles! You won the maze in "
    + maze.numCharlesMoves() + " moves!" );
    } else {
    System.out.println( "Stalemate! Both players are stuck. "
    + "Better luck next time." );
    The following is the Listener class: MazeRaceListener
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    /** Listens for keystrokes from the GUI interface to the MazeRace game. */
    public class MazeRaceListener extends KeyAdapter {
    * Reference to the underlying MazeRace object which needs to be updated
    * when either player moves
    private MazeRace maze;
    * Reference to the MazeRaceWindow object that displays the state of
    * the game
    private MazeRaceWindow mazeWindow;
    * Class constructor for the key listener object
    * @param maze the underlying MazeRace object
    public MazeRaceListener( MazeRace maze ) {
    this.maze = maze;
    * A method that sets which JFrame will display the game and need to be
    * updated with each move.
    * @param window the JFrame object that displays the state of the game
    public void setMazeRaceWindow( MazeRaceWindow window ) {
    mazeWindow = window;
    * A method that will be called each time a key is pressed on the active
    * game display JFrame.
    * @param event contains the pertinent information about the keyboard
    * event
    public void keyTyped( KeyEvent event ) {
    char move = event.getKeyChar();
    // TODO: complete method so that the appropriate action is taken
    // in the game
    //mazeLabel.setText(String.valueOf(move).toUpperCase());
    }

    and listen to the keys (A,S,D,W & J,K,L,I) and make the move accordingly [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings

  • How to make maze walls?

    Hello,
    First off I would like to clearify that i'm terrible at this and have no idea what im doing
    Anyhow, i would like to make a maze game with accelerometer. I have managed to make a ball within a certain area with this code:
    import flash.events.Event;
    var accelX:Number;
    var accelY:Number;
    var fl_Accelerometer:Accelerometer = new Accelerometer();
    fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
    function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
              accelX = event.accelerationX;
              accelY = event.accelerationY;
    ball.addEventListener(Event.ENTER_FRAME, moveBall);
    function moveBall(evt:Event){
              ball.x -= accelX*30;
              ball.y += accelY*30;
              if(ball.x > (480-ball.width/2)){
                        ball.x = 480-ball.width/2;
              if(ball.x < (0+ball.width/2)){
                        ball.x = 0+ball.width/2;
              if(ball.y > (800-ball.width/2)){
                 ball.y = 800-ball.width/2;
              if(ball.y < (0+ball.width/2)){
                        ball.y = 0+ball.width/2;
    Now the problem is that i would like to make some walls within this maze, some restricted areas if i may, so it becomes an actually maze. Have tried and failed several times and have only managed to make a but not limit it. so it just cuts the screen in half etc.

    create your maze.  convert each rectangle in the maze to a movieclip and assign an instance name (eg, m1,m2,...,m44).  don't convert any L-shaped, U-shaped or rotated L-shaped, U-shaped etc sections.  only rectangular blocks.
    you can then use:
    var prevX:int;
    var prevY:int;
    var i:int;
    var mP:Sprite=new Sprite();
    addChild(mP);
    for(i=1;i<=44,i++){
    mP.addChild(this["m"+i]);
    function moveBall(evt:Event){
              ball.x -= accelX*30;
              ball.y += accelY*30;
              if(ball.x > (480-ball.width/2)){
                        ball.x = 480-ball.width/2;
              if(ball.x < (0+ball.width/2)){
                        ball.x = 0+ball.width/2;
              if(ball.y > (800-ball.width/2)){
                 ball.y = 800-ball.width/2;
              if(ball.y < (0+ball.width/2)){
                        ball.y = 0+ball.width/2;
    checkWallF();
    function checkWallF():void{
    for(i=0;i<mP.numChildren;i++){
    if(ball.hitTestObject(mP.getChildAt(i))){
    ball.x=prevX;
    ball.y=prevY;
    break;
    prevX=ball.x;
    prevY=ball.y

  • Iterative maze generation with a stack and queue

    I searched the forums, and a couple of hits were interesting, particularly http://forum.java.sun.com/thread.jsp?forum=54&thread=174337 (the mazeworks site is very very cool), but they all centered on using a recursive method to create a maze. Well, my recursive maze generation is fine; it seems to me that recursion lends itself quite well to this particular form of abuse, so well in fact that I am having trouble wrapping my head around an iterative approach. :) I need to create a maze iteratively, using a stack if specified by the user, else a queue. I can vaguely see how a stack simulates recursion but conceptualization of the queue in particular is making my hair hurt. So I was just wondering if anyone had any thoughts or pointers that they wouldn't mind explaining to me to help me with this project. Thanks kindly.
    Maduin

    Stacks (i.e. a first in, last out data storage structure) are very, very closely tied to recursive calls - after all, the only reason that the recursion works at all is because the language is placing the current state of the method on a stack before it calls the method again.
    As for using queue's to implement the same type of thing, are you allowed to use a dequeue (double ended queue)? If so, dequeue's are a pretty common way of implementing a stack - they allow you to implement both FILO and FIFO (first in, first out) structures by whether you pull the stored item from the head or tail of the dequeue.
    If you are talking about a FIFO, then that's a different story - let us know!
    - K
    PS - recursion is an odd topic to get your head around - keep working at it! The biggest thing to realize is that all recursive routines must have SOME way to exit them without continuing the recursion. The design of a recursive call, then, is generally easiest to do when implemented by answering the following question: "Under what condition should the recursion stop?", and then building the routine backwards from there.

  • Points and discussion about the concepts behind making a 2D game

    Hi all. I'm currently trying my hand at a 2D RPG style game. I have a few questions open for discussion, however, regarding the general points of implementation behind it.
    1. Tiles vs static background argument aside, am I right in the thinking the best way of implementing movement across a big background map is actually to move the background and other sprites in relation to the player, giving the illusion of player movement although he in fact never moves from the center of the screen? Is there a way of actually creating a large map, populating it with sprites, and then moving the player across it and panning the screen after him?
    2. Collision detection. If we go with the idea of moving everything in relation to the player rather than the player himself, woudln't this mean a large amount of calculations when collision detection occurs. Example, u want the player to stop moving when he hits a brick wall so you have to tell every entity sprite to stop moving in response to key presses (because remember, pressing up moves everything else up, not the player character).
    3. Isometric. Is the easiest way of implementing an isometric style game just to develop isometric graphics and sprites?
    4. Tiles. I've been doing a lot of reading into tiles but I'm not sure what's a better implementation: a tile system which consists of the entire background and things like houses split into tiles or a simple big background which can be scrolled around and is populated by house sprites which are all moved in relation to the player and their collision detections done individually. Tiles certainly seem like a nice innovation but I feel like the graphics suffer as a consequence and u end up with a 8bit NES looking game!
    I'm just getting to grips with the concepts behind a lot of game design and all of this are some interesting points which I thought would be insightful to discuss. Opinions please!
    Cheers.

    Everything I'm about to say is based off of a tile-based Maze game I made.
    1. Using a big background map is a bit lazy if you ask me, but graphically it would be easier to create a nice-looking game. You also have to think about memory. Let's say you manage to get an 800x600 background image at the size of 200kb with JPEG compression. That 200kb jpg image you use as a background is not 200kb when loaded into memory. I dont remember exactly how much bigger it gets in memory, so this next statement is probably wrong. But I heard that: 4bytes per pixel for the ARGB data, and there are 800x600 (480,000) pixels. That's 480000*4 (1920000) bytes if that statement is right. But it's probably wrong, so hopefully Abuse or someone will correct it :)
    2. Move EVERYTHING up? I think you're a little mixed up. When the background (and all objects with it) is scrolled, their actual X,Y data is not changed. It is simply drawn according to the scroll offset. The only thing that is being calclulated for movement is the character/scroll offset. Think of it as a camera. The entire world is not moving, just the location of where you're viewing it. Quick example:
    You have a Tree who's location is (10,10). If the scroll offset is (0,0), then that Tree will be drawn at (10,10). But let's say your character moves up 5 pixels. You say you want him centered, so the scroll offset also moves up 5 pixels, making the offset (0,-5). When it's time to draw again, that Tree can't be at the same place it was, because the character moved. If the character moved up, the Tree would appear as if it moved DOWN. So you'd draw it like:
    g.drawImage(tree.getImage(),tree.x-scrollOffsetX,tree.y-scrollOffsetY,null);With that math, the Tree is actually drawn at (10,15), which is lower than before the character moved. You don't actually loop through all of your objects and change each and every X and Y value, you just change the global scroll offset
    Speaking of collision detection, this is where TileMaps have a large advantage. In a TileMap, you don't have to check through each and every object in the world for collision. You can just grab the 4 surrounding tiles (north,west,east,south) from the Tile array. This means there are only 4 collision detections no matter where the character is in any situation on the map.
    If you used an image for background instead of tiles, you'd have to check each object in the world for collision because it's harder to tell how close it is to the character. One thing you could do is just grab all of the object currently visible on screen and check their collision, but, depending on where you are on the map, this could easily cause an inconsistent frame rate (you could be in a field of grass that has no collision or a forest of 50 trees each screen- LOTS of collision!).
    3. I dont got much to say about isometric :P
    4. an 8bit NES game, eh? That is the common misconception that you have to use images that are the same size of the tiles. Have you seen the game "The Legend of Zelda: Four Swords"? That's a tile-based game, but on several occasions you see trees that are 10 times bigger than the 20x20 tiles. They mixed it up, they used a TileMap for the basic ground, and put good looking large images on top. The large images (such as a large tree) uses 4 or 5 "base" tiles that are used for collision. That way the character will only collide with the bottom-half of the tree, giving the appearance of going "behind" the tree when the Y value is above the middle line of the tree. This is far away from looking like an 8bit NES game :)
    I hope that was more helpful than it was confusing, but I tend to babble, so.. anyway. Hope it helps :o

  • Problem using KeyListener in a JFrame

    Let's see if anyone can help me:
    I'm programming a Maze game, so I use a JFrame called Window, who extends JFrame and implements ActionListener, KeyListener. Thw thing is that the clase Maze is a JPanel, so I add it to my Frame and add the KeyListener to both, the Maze and the Window, but still nothing seems to happen.
    I've tried to remove the KeyListener from both separately, but still doesn't work...
    Any suggestions???

    This is the code for my Window.java file. May be someone can see the error...
    package maze;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Window extends JFrame implements ActionListener, KeyListener {
      private Maze maze;
      private JButton crear = new JButton("New");
      public Window(int size, String s) {
        super("3D Maze");
        boolean b = true;
        if (s.equalsIgnoreCase("-n"))
          b = false;
        else if (s.equalsIgnoreCase("-v"))
          b = true;
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        maze = new Maze(size,size,b);
        crear.addActionListener(this);
        addKeyListener(this);
        maze.addKeyListener(this);
        c.add(crear,BorderLayout.NORTH);
        c.add(maze,BorderLayout.CENTER);
        setSize(600,650);
        show();
      public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == e.VK_UP || e.getKeyCode() == e.VK_W)
          maze.walk();
        else if (e.getKeyCode() == e.VK_DOWN || e.getKeyCode() == e.VK_S)
          maze.back();
        else if (e.getKeyCode() == e.VK_LEFT || e.getKeyCode() == e.VK_A)
          maze.turnLeft();
        else if (e.getKeyCode() == e.VK_RIGHT || e.getKeyCode() == e.VK_D)
          maze.turnRight();
        else if (e.getKeyCode() == e.VK_V)
          maze.alternaMostrarCreacion();
        else if (e.getKeyCode() == e.VK_M)
          maze.switchMap();
      public void keyTyped(KeyEvent e) {}
      public void keyReleased(KeyEvent e) {
      public void actionPerformed(ActionEvent e) {
        maze.constructMaze();
      public static void main(String[] args) {
        int i = 30;
        String s = "-v";
        if (args.length != 0) {
          try {
            i = Integer.parseInt(args[0]);
            if (!(i >= 15 && i <= 50))
              i = 30;
            s = args[1];
          catch(Exception e) {}
        Window w = new Window(i,s);
        w.addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
              ImageIcon im = new ImageIcon("./Logo.gif");
              String s = "";
              s += "3D MAZE\n\n";
              s += "Creator: Allan Marin\n";
              s += "http://metallan.topcities.com\n\n";
              s += ""+((char)(169))+" 2002";
              JOptionPane.showMessageDialog(null,s,"About...",JOptionPane.PLAIN_MESSAGE,im);
              System.exit(0);
    }

Maybe you are looking for

  • TV Out stops after 1 minute of playback

    I have a Nano 4g and have problems with the TV out function. I can get the TV out to work with the 30pin video component cable, but after 1 minute of playback the Nano shuts down and the video stops. When I go in to restart the video the video out to

  • How to choose diffetent PO types in R/3 from a SC in Classic Scenario

    Hello everyone, I am working with SRM 5.0 in a classic scenario and I have a problem. I create a SC, then it is sent to sourcing cockpit where I assign it a vendor to create a PO, but I can't choose what kind of PO I want to create. In PPOMA_BB, the

  • Mouse over a menu on the portal

    hello We are using Portal Nw2004s SPS14. I would like to know if it possible that, when you put the mouse over a menu on the portal, a label appears with a long text. I mean, If it is possible, in the standard. Thanks and Regards Noemi

  • IPod 4G won't start. Bad battery?

    Trying to fix my daughter's iPod Touch 4th gen.  If I plug in the USB cable, I can get the red battery indicator with the charging bolt underneath the battery.  Trying to power it up never produces the Apple logo.  If I go through the steps to boot i

  • WD ABAP: call dialog window from component controller method

    Hi all, I need to call a dialog box from a method in the component controller. It would be helpful if u could post the code too. Thanks, Sravanthi