This site requires JavaScript, please enable it in your browser!
Greenfoot back
RedPhoneBooth
RedPhoneBooth wrote ...

2012/9/25

No World Class Found Error

RedPhoneBooth RedPhoneBooth

2012/9/25

#
I've been trying to work on some maze generation things for my adventurey type dungeon crawler game but as soon as I added the code for the generation, whenever I compiled it doesn't show the world, if I try to share it it says no world class was found. Well there is a world class (I think), one of my classes extends world. I moved all of my maze gen code into its own class and it didn't do anything, I probably deleted some vital line of code or something but I'm not really sure what. I'm running greenfoot 2.1.2 and there are 5 classes: Maze(The world), Swoosh, Knight, MazeGen, and Object. Thank you for reading! Here is the entire world class. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Maze here. * * @author (your name) * @version (a version number or a date) */ public class Maze extends World { private int room_Num = 0; public static int world = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},//0: Ungenroom { 1, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1},//1: Level 1 Room { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},//2: Level 2 Room { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},//3: Level 3 Room { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},//4: Level 4 Room { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},//5: Level 5 Room { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},//6 { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},//7: Key Room { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},//8: Treasure Room { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},//9: Stair Room { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, };//10 public Knight player = new Knight(); /** * Constructor for objects of class Town. * */ public Maze() { // Create a new world with 640x640 cells with a cell size of 1x1 pixels. super(640, 640, 1); addObject(player, 312, 312); MazeGen gen = new MazeGen(); loadRoom(); } public void act() { knight_Tracker(); } public void knight_Tracker() { if (player.get_X() == 0) { change_Rooms_Left(); } if (player.get_X() == 639) { change_Rooms_Right(); } if (player.get_Y() == 0) { change_Rooms_Up(); } if (player.get_Y() == 639) { change_Rooms_Down(); } } public void change_Rooms_Down() { int x = get_X_Location(); int y = get_Y_Location(); int a = player.get_X(); world = room_Num; y = y + 2; room_Num = world; world = 2; removeObject(player); addObject(player, a, 1); loadRoom(); } public void change_Rooms_Up() { int x = get_X_Location(); int y = get_Y_Location(); int a = player.get_X(); world = room_Num; y = y - 2; room_Num = world; world = 2; removeObject(player); addObject(player, a, 638); loadRoom(); } public void change_Rooms_Left() { int x = get_X_Location(); int y = get_Y_Location(); int a = player.get_Y(); world = room_Num; x = x - 2; room_Num = world; world = 2; removeObject(player); addObject(player, 638, a); loadRoom(); } public void change_Rooms_Right() { int x = get_X_Location(); int y = get_Y_Location(); world = room_Num; x = x + 2; room_Num = world; world = 2; removeObject(player); addObject(player, 1, 320); loadRoom(); } public int get_Y_Location() { int y_Location = 0; for (int x = 0; x<=10; x++) { for (int y = 0; y<=10; y++) { if(world == 2) { y_Location = y; } } } return y_Location; } public int get_X_Location() { int x_Location = 0; for (int x = 0; x<=10; x++) { for (int y = 0; y<=10; y++) { if(world == 2) { x_Location = x; } } } return x_Location; } public void loadRoom() { int x = get_X_Location(); int y = get_Y_Location(); removeObjects(getObjects(Object.class)); x++; if (world == 1) { RIGHT(); } else { doorRIGHT(); } x--; x--; if (world == 1) { LEFT(); } else { doorLEFT(); } x++; y--; if (world == 1) { UP(); } else { doorUP(); } y++; y++; if (world == 1) { DOWN(); } else { doorDOWN(); } y--; if (room_Num == 7) { keyRoom(); } if (room_Num == 8) { treasureRoom(); } } public void treasureRoom() { } public void keyRoom() { } public void doorUP() { for (int a = 0; a != 2; a++) { addObject(new Object(), 126*a+63, 0); } for (int a = 3; a != 5; a++) { addObject(new Object(), 126*a+63, 0); } } public void doorLEFT() { for (int a = 0; a != 3; a++) { addObject(new Object(), 0, 96*a); } for (int a = 4; a != 7; a++) { addObject(new Object(), 0, 96*a); } } public void doorDOWN() { for (int a = 0; a != 2; a++) { addObject(new Object(), 126*a+63, 640); } for (int a = 3; a != 6; a++) { addObject(new Object(), 126*a+63, 640); } } public void doorRIGHT() { for (int a = 0; a != 3; a++) { addObject(new Object(), 640, 96*a); } for (int a = 4; a != 7; a++) { addObject(new Object(), 640, 96*a); } } public void UP() { for (int a = 0; a != 6; a++) { addObject(new Object(), 126*a+63, 0); } } public void DOWN() { for (int a = 0; a != 6; a++) { addObject(new Object(), 126*a+63, 640); } } public void LEFT() { for (int a = 0; a != 6; a++) { addObject(new Object(), 0, 126*a+63); } } public void RIGHT() { for (int a = 0; a != 6; a++) { addObject(new Object(), 640, 126*a+63); } } }
danpost danpost

2012/9/26

#
You have an extra comma ',' at the end of your array. Remove it and see if that fixes your problem. Also, try renaming your 'Object' class, it might be confusing the compiler since all Actor objects and World objects are sub-classes of the Object class (not your Object class).
RedPhoneBooth RedPhoneBooth

2012/9/26

#
Okey dokes, I updated greenfoot to the latest version and made the changes that you suggested and its all fine and dandy, but the maze gen code is causing the problem, I have to comment it out and restart the program to get it to show the world again. I'm assuming this is due to it getting into an infinite loop in its constructor, ill give it a go and try to fix it but here is the code if your intrested. Thanks for responding to my post so quickly! --------------------------------------------------------------------------------------------------------------------------------------- import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MazeGen here. * * @author (your name) * @version (a version number or a date) */ public class MazeGen extends Actor { int world = Maze.world; /** * Act - do whatever the MazeGen wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } public MazeGen() { Gen(); } public void Gen() { int builderX = 1; int builderY = 1; int keyRooms = 0; for (; getFreeRoom() != 0; getFreeRoom()) { int rand = Greenfoot.getRandomNumber(3); if (getFreeRoomsAround(builderX, builderY) == true) { if (rand == 0) { builderX++; world = 0; builderX++; } if (rand == 1) { builderX--; world = 0; builderX--; } if (rand == 2) { builderY--; world = 0; builderY--; } if (rand == 3) { builderY++; world = 0; builderY++; } } if (getFreeRoomsAround(builderX, builderY) == false && getFreeRoomsAround(builderX, builderY) == false &&getFreeRoomsAround(builderX, builderY) == false && getFreeRoomsAround(builderX, builderY) == false) { if (keyRooms != 2) { world = 7; keyRooms++; } else { world = 8; } if (getDoor(builderX, builderY) == 0) { builderX++; } if (getDoor(builderX, builderY) == 1) { builderX--; } if (getDoor(builderX, builderY) == 2) { builderY--; } if (getDoor(builderX, builderY) == 3) { builderY++; } if (getDoor(builderX, builderY) == 4) { System.out.println("Error: getDoor()"); break; } } } } public int getFreeRoom() { int freeRooms = 0; for (int x = 1; x <= 9; x = x + 2) { for (int y = 1; y <= 9; y = y + 2) { if (world == 0) { freeRooms++; } } } return freeRooms; } public boolean getFreeRoomsAround(int x, int y) { boolean freeRoomsAround = {false, false, false, false}; //right,left,up,down x =+ 2; if (x <= 10 && world != 0) { freeRoomsAround = true; } x =- 2; x =- 2; if (x >= 0 && world != 0) { freeRoomsAround = true; } x =+ 2; y =- 2; if (y >= 0 && world != 0) { freeRoomsAround = true; } y =+ 2; y =+ 2; if (y <= 10 && world != 0) { freeRoomsAround = true; } y =- 2; return freeRoomsAround; } public int getDoor(int x, int y) { int Door = 4; x++; if (x <= 10 && world == 0) { Door = 0; } x -= 2; if (x >= 0 && world == 0) { Door = 1; } x++; y--; if (y >= 0 && world == 0) { Door = 2; } y -= 2; if (y <= 10 && world == 0) { Door = 3; } return Door; } }
danpost danpost

2012/9/26

#
This line does not look right: for (; getFreeRoom() != 0; getFreeRoom())
danpost danpost

2012/9/26

#
There are also a lot a places you are using '=+' and '=-" where you should be using '-=' and '+='. Saying 'x =- 2;' is the same as saying 'x = 0 - 2;', where 'x -= 2;' is equivalent to 'x = x - 2;'
RedPhoneBooth RedPhoneBooth

2012/9/26

#
Hmmm, ill bet it isn't, for (int a = getFreeRoom(); a != 0; a = getFreeRoom()) didn't work though, also is there a shortcut to reset the java virtual machine?
RedPhoneBooth RedPhoneBooth

2012/9/26

#
OHHHH! Thats an embarrassing mistake haha ill give it a go
danpost danpost

2012/9/26

#
Select 'Controls' on the menu bar, then select 'Show Debugger'; click on 'Terminate' to reset. The menu shortcut is 'Ctrl-B'.
danpost danpost

2012/9/26

#
To help make your code more readable and less bulky, I simplified one of your methods:
public boolean[] getFreeRoomsAround(int x, int y)
{
    boolean[] rooms = { x + 2 <= 10 && world[x + 2][y] != 0,
             x - 2 >= 0 && world[x - 2][y] != 0,
             y - 2 >= 0 && world[x][y - 2] != 0,
             y + 2 <= 10 && world[x][y + 2] != 0 };
    return rooms;
}
Maybe you can try simplifying some of your other methods or code snippets.
danpost danpost

2012/9/26

#
I am a little confused, however. In the method getFreeRooms() you are looking for values equal to zero, where in getFreeRoomsAround(int, int) you are looking for values NOT equal to zero. That 'for' statement we were looking at in your Gen() method earlier should probably be a 'while' statement
while(getFreeRooms() != 0)
and in the first line after that 'int rand = Greenfoot.getRandomNumber(3); ' , the '3' should be '4'; otherwise 3 will never be returned. The return range of 'getRandomNumber(n)' is 0 to n - 1.
You need to login to post a reply.