Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Level

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Level

    Hi

    I am programming a Pac man game. But I don't know how I can create a Level. I have upload the file, where you can see how the level should look. P stands for Pacman, M for his opponent, and # is a power up, * is the wall and ... is the stuff which he has to collect. My first idea, was that I convert this file into an Array. Then I could use a for loop, to display it on the Screen.
    But how can access the file?
    Can someone please help me?
    Attached Files Attached Files


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Level

    Thank you for your reply

    I have tried to implement it, but it doesn't work.
    public class Level {
     
    	File file;
     
    	public void read() throws IOException {
     
    		FileReader data = new FileReader(file);
     
    		BufferedReader b = new BufferedReader(data);
    		int row = 0;
    		String content = b.readLine();
     
    		while (content != null) {
    			row++;
    			content = b.readLine();
    		}
    		data.close();
     
    		data = new FileReader(file);
    		b = new BufferedReader(data);
     
    		char[] chararray = new char[1000];
    		int i = 0;
    		while ((i = data.read(chararray)) >= 0) {
     
    		}
     
    		char field[][] = new char[row][i / row];
     
    		data.close();
     
    	}
     
    }

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Level

    Explain "does not work." If there are error messages, post them. If the program's behavior is not as desired, describe what it's doing and how that is different than your expectations. Post sample runs if possible.

Similar Threads

  1. Yet another level format issue...
    By Gravity Games in forum Android Development
    Replies: 14
    Last Post: August 20th, 2012, 12:53 PM
  2. A level format problem
    By Gravity Games in forum Object Oriented Programming
    Replies: 8
    Last Post: June 4th, 2012, 02:20 PM
  3. [SOLVED] Help Generating a level
    By Montario in forum AWT / Java Swing
    Replies: 22
    Last Post: April 12th, 2012, 07:22 AM
  4. Attempting to get to next level in API
    By meathead in forum The Cafe
    Replies: 8
    Last Post: October 12th, 2011, 11:17 AM