java - Why isn't my if-else block ever getting hit, even though it should be? (Just need another pair of eyes.) -


i making falling sand style game in java, , i'm having weird issues if-else block have. in dogravity() method, have various blocks of conditions cause different things happen, , odd reason, 1 block never getting hit.

when have block count how many times each condition hit, left , right blocks hit evenly:

else if(world[x][y+1]==empty && (x-1 >= 0) && world[x-1][y+1] == empty && (x+1 < world.length) && world[x+1][y+1]==empty) {     int r = rand.nextint(50);     if(r == 0) {         world[x-1][y+1] = world[x][y];         //system.out.println("go: right");         countright++;     }     else if(r == 1) {         world[x+1][y+1] = world[x][y];         //system.out.println("go: left");         countleft++;     }     else {         world[x][y+1] = world[x][y];         countcenter++;     }     world[x][y] = empty; } 

next comes condition, equally distributes left , right.

else if((x-1 >= 0) && world[x-1][y+1] == empty && (x+1 < world.length) && world[x+1][y+1]==empty) {     if(rand.nextboolean()) {         world[x-1][y+1] = world[x][y];         //countleft++;     }     else {         world[x+1][y+1] = world[x][y];         //countright++;     }     world[x][y] = empty; } 

but when count these blocks, left block never gets hit, when space left is open. feel stupid typo can't see reason.

else if((x-1 >= 0) && world[x-1][y+1] == empty) {     world[x-1][y+1] = world[x][y];     world[x][y] = empty;     countleft++;     system.out.println("hit left"); } else if((x+1 < world.length) && world[x+1][y+1] == empty) {     world[x+1][y+1] = world[x][y];     world[x][y] = empty;     countright++;     system.out.println("hit right"); } 

update: if remark out left block @ end, absolutely nothing changes. sand acts same. if remark out right block @ end, acts same if remark out both blocks. cannot figure out. should work... doesn't.

update: here's full source code. have no idea possibly be. will, in fact, drive me insane. http://pastebin.com/mxcbcvmb

your pastebin code show "hit left", need change creation of world (line 65 pastebin) to

    world = new color[worldwidth][worldheight+1]; 

because of y+1 part suppose. other grows both left , right.

edit: http://pastebin.com/gvmszn4z twiddled little dogravity make drops little more symmetric.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -