Created
July 17, 2013 17:30
-
-
Save A-J-C/6022653 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int randA = getInt(); //Random x position | |
int randB = getInt(); // Random y position | |
for (int a = 0; a < 10; a++) { | |
for (int b = 0; b < 10; b++) { | |
if (a == randA && b == randB) addObject(new BaseCamp(), a, b); | |
else setLand(a, b); | |
} | |
} // Loop populating the 10 x 10 grid with different land types apart from one space which is for the 'BaseCamp' | |
int[] xPos = new int[10]; // 2 Arrays to hold the co ordinates of the 'lava' squares | |
int[] yPos = new int[10]; | |
int l = 0; | |
while (l < 10) { | |
int lA = getInt(), lB = getInt(); | |
xPos[l] = lA; | |
yPos[l] = lB; | |
addObject(new Lava(), lA, lB); | |
l++; | |
} // Loop adding the lava into 10 random squares and recording there coords into the above 2 arrays | |
/* ================== */ | |
/* I think this is where the problem is it is meant to randomly place 4 'peope' | |
but it can only place it in spaces that dont contain the base camp or lava | |
I have tried to set it up so that a new person is added only if the random coords | |
dont match the coords of the base camp or any lava squares but it doesnt work | |
any ideas!? Help appreciated!*/ | |
int i = 0; | |
while (i <= 4) { | |
int a = getInt(), b = getInt(); | |
if (a != randA || b != randB) { | |
for (int z = 0; z < 10; z++) { | |
if (a != xPos[z] || b != yPos[z]) { | |
addObject(new Person(), a, b); | |
i++; | |
break; | |
} | |
} | |
} | |
} | |
/* ================ */ | |
private static int getInt() { | |
return (int) Math.floor(Math.random() * 9 + 1); // Method to get a random number upto 10 | |
} | |
private static int getRand() { | |
return (int) Math.floor(Math.random() * 3 + 1); // Method to get random number upto 3 | |
} | |
private void setLand(int a, int b) { // Method that randomly allocates land | |
switch (getRand()) { | |
case 1: | |
addObject(new Grassland(), a, b); | |
break; | |
case 2: | |
addObject(new Rocks(), a, b); | |
break; | |
case 3: | |
addObject(new Ice(), a, b); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment