Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly,you can use enums instead of strings as mentioned by Jack above. Eg</p> <p>private enum Objects{ Rock(1),Coin(8),Med(45)...and so on } </p> <p>In your array, you may store these objects as numbers rather than strings.</p> <p>eg:</p> <pre><code> boolean stopFlag=false; do{ //check each element of your world array with the enum and draw it for(int i=0;i&lt;yourObjectsArray.length;i++) { for(int j=0;j&lt;yourObjectsArray[i].length;j++){ switch(yourObjectsArray[i][j]) { case Objects.Rock: drawRock(i,j); break; case Objects.Coin: drawCoin(i,j); break; //and so on.... } } } //you can also put this into a separate function as drawWorld() and pass the objects. //Key press checking logic here. If user presses exit key [esc] then you set the stopFlag as true if(keypress==KEY_ESC){ stopFlag=true;} }while(!stopFlag); </code></pre> <p>An example of Draw Rock: </p> <pre><code>private void drawRock(int i,int j){ //i and j are the cols and row values so you need to resolve them to coordinates. //I am assuming u have a 800*600 screen and you mentioned that your world is 100x100 array. Then each of your object is 8*6 units in size so xCoord=i*8; yCoord=j*6; //So if you have to draw a rock on [10][15] it will resolve as //xCoord=10*8-&gt; 80 //yCoord=15*6-&gt; 90 so it will draw your rock in (80,90) on the screen //Now you can either open the rock image from your disk now or u maintain one instance of rock at the beginning of the program so that you can use the same image later rather than opening it everytime you encounter a new Rock object in your array.For now I will open it here. String path = "C:\\YourGameDirectory\\rock.jpg"; URL url = new File(path).toURI().toURL(); BufferedImage rockImg = ImageIO.read(url); //draw it to the screen now if you have the graphics instance. yourUIPanel.getGraphics().drawImage(rockImg,xCoord,yCoord,yourUIPanel); // You may find many resources that teach you how to draw an image on the screen in Java. You may repeat the same for all the objects. } </code></pre> <p>I hope the above codes helped you a-bit. If not,its my bad.</p> <p>You can try <a href="http://www.youtube.com/watch?v=86sDrOcNGUA" rel="nofollow" title="Youtube Series">this</a> tutorial series to get started. Although its in C , it has concepts that will help u acheive what you have mentioned above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload