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

2013/5/15

Randomly generated dungeon

1
2
3
4
5
henrYoda henrYoda

2013/5/19

#
@thssfrnssssmnt I am trying to figure out something, I don't really have time to "set a score" on your game :) @danpost it is still not working, it says: cannot reference myTwoDArray before supertype constructor has been called My mainWorldClass:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class mainWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainWorldClass extends World/*Or whatever you want to call it*/  
{  
    private int[][] world;  

    public MainWorldClass(int[][] array)  
    {  
        super(800, 400, 1);
        world = array;
    }  

    public void setItemsFromArray(int[][] world)    
    {  
        int gap = 30; // see note below  
        for (int i = 0; i < world.length; i++) for (int j = 0; j < world[i].length; j++)    
            {  
                Actor actor = null; // to hold any actor created  
                switch (world[i][j]) {  
                    case 0: break; // no actor here  
                    case 1: actor = new Player(); break;  
                    case 2: actor = new Enemy(); break;  
                    case 3: actor = new Wall(); break;  
                    case 4: actor = new  Item(); break;  
                }  
                if (actor != null) addObject(actor, i*gap, j*gap);  
        }  
    }  
}  
my game class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class game here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class game extends MainWorldClass
{
    int[][] myTwoDArray = {  
                {0, 0, 0, 0, 0},  
                {2, 0, 1, 0, 2},  
                {0, 0, 0, 0, 0}  
            };  

        //gets height of a 2D array (it equals 3)  
        int height = myTwoDArray.length;  

        //gets width of a 2D array (it equals 5)  
        int width = myTwoDArray[0].length;  
    /**
     * Constructor for objects of class game.
     * 
     */
    public game()
    {    
        super(myTwoDArray);
        
        
        
    }
}
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
plz don't tell him danpost. remember he wouldn't help you
henrYoda henrYoda

2013/5/19

#
Hey dude, chill out. Obviously I won't be able to help danpost, he is much more skilled than me
danpost danpost

2013/5/19

#
Change: int myTwoDArray = { to: static int myTwoDArray = { Also, you 'super' call in the MainWorldClass constructor should be: super(array.length*30, array.length*30, 1);
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
sorry i meant to say he wouldn't help you if he could
henrYoda henrYoda

2013/5/19

#
Ok, now it compiles. But now my world size is tiny and none of my objects appear. Have I missed something out?
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
lol
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
nice 1
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
u've been bammed up by ur hero
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
hahahahahahahahahahaha
danpost danpost

2013/5/19

#
You need to increase the size of the array to increase the size of your created world. Remove lines 17 through 20 from your MainWorldClass code (this will just execute the 'setItemsFromArray' code instead of calling the method (which was missing).
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
ur game would have been working about half an hour ago if u hadn;t been a ****
henrYoda henrYoda

2013/5/19

#
Hi danpost, so what I did was that I called the method setItemsFromArray. My objects appeared but the screen is so tiny I don't think I did it right. What should I do?
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
the funny thing is he's so up ur arse that he'll just assume the code u gave him isn't causing the problem
thssfrnssssmnt thssfrnssssmnt

2013/5/19

#
this is hilarious!
There are more replies on the next page.
1
2
3
4
5