I'm relatively new to programming and I have an activity where I need to create a boat racing game. In the game the player needs to move forward or backwards based on the roll of a dice. There are traps (#) and currents (C) in the game which need to be randomly scattered across a 100 column track. I'm having trouble getting the player to move as well as the traps and current to be scattered randomly. I know for the traps and current a random number generator is involved but I'm confused on how to use it. Can anyone help if it's not too much trouble? Here is what I have so far:
package boat_race;
import java.util.Random;
public class River {
public int[][] river = new int[2][99];//[1]
int freq;
int position;
int count = 0;
Random scatter = new Random();
public void setObstacle() {
//scatters both current and trap
for(int count = 0; count<40; count++)
{freq=scatter.nextInt(40);//frequency
position=scatter.nextInt(99);//position on the array
river[0][position]=freq;
//river[0][position]=5;
river[1][position]=freq;
}
}
public void checkObj(){
while(true){
if(river[0][count]%2==00){
//even number and moving back
count++;
}
if(river[0][count]%2==1){
//odd number and moving the number
count++;
}
}
}
public static void moveP1() {
// TODO Auto-generated method stub
}
public static void moveP2() {
// TODO Auto-generated method stub
}
public static void scatter() {
// TODO Auto-generated method stub
}
public void winner() {
// TODO Auto-generated method stub
}
}
Aucun commentaire:
Enregistrer un commentaire