I have started making a java applet for a game like battleships. Here is what I am trying to do:
Builds a 10x10 board, randomly picking 10 coordinates on which 'ships' are located. The user guesses ship locations by clicking on the board, placing white pegs for a 'miss', and red pegs for a 'hit'. As soon as the user hits the last 'ship' the program writes a winning message including the number of guesses it took and exits.
I have made the 10x10 board and have stored the random locations of the reg pegs in an ArrayList. Right now, it allows outputs the coordinates of the hidden red dots for me to test, and places them when they are hit. It doesn't let me click the white dots though and I am not sure why. Any help is appreciated and thank you. Here is a section of my code:
while(unWon){
Coordinate currentClick = board.getClick();
for(Coordinate c: ships){
if(c.getRow() == currentClick.getRow()){
if(c.getCol() == currentClick.getCol()){
if(totalClicks<=100) {
for (int i = 0; i < ships.size(); i++) {
if((currentClick.getCol()==ships.get(i).getCol()) && (currentClick.getRow()==ships.get(i).getRow())){
board.putPeg("red", currentClick.getRow(), currentClick.getCol());
break;
}
else{
board.putPeg("white", currentClick.getRow(), currentClick.getCol());
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire