ucsb-cs56-projects / cs56-games-treasure-hunter

-
1 stars 7 forks source link

Code for randomly placing treasures #27

Closed danielledodd closed 8 years ago

danielledodd commented 8 years ago

The code to randomly set the treasures on the map could be written in a more efficient way that allows for easier future changes, such as having more than 3 treasures. Currently, the code looks like this:

int treasure1X = (int)(Math.random()*12);
int treasure1Y = (int)(Math.random()*9);
...
...
... 
while((treasure1X == treasure3X && treasure1Y == treasure3Y)
     || (treasure2X == treasure3X && treasure2Y == treasure3Y)){
   treasure3X = (int)(Math.random()*12);
   treasure3Y = (int)(Math.random()*9);

Perhaps a function can be used instead of the multiple while statements to ensure each treasure is uniquely placed. For example, maybe you could write an isOccupied function.

Suggested points: ~75

vincenicoara commented 8 years ago

W16 OK

athielk commented 8 years ago

F16 OK (75 pts) Also could be put in new class for treasure. Look at issue #30.