944,101 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 229
  • Java RSS
Nov 6th, 2009
0

Help with hw...

Expand Post »
AHHH so i've been writing this code with my teachers help. IT will now be able to get 1 coordinate, but i want it to get teh same number of coordinates, i set my shipsize to.. waht can i do...my teacher said I could do a loop... but.... i couldnt get it to work....( this is jsut part of the code) you dotn the otehrs...

java Syntax (Toggle Plain Text)
  1. import java.util.ArrayList;
  2.  
  3. public class GameBoard
  4. {
  5. private boolean[][] i = new boolean[10][10];
  6.  
  7. boolean spotIsTaken = true;
  8.  
  9. public ArrayList<String> placeShip(int shipSize)
  10. {
  11. System.out.println(shipSize);
  12.  
  13. String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
  14.  
  15. int row =(int)(Math.random()*10);
  16. int column =(int)(Math.random()*10);
  17.  
  18.  
  19. while(spotIsTaken)
  20. {
  21. if(i[row][column])
  22. {
  23. row =(int)(Math.random()*10);
  24. column =(int)(Math.random()*10);
  25. }
  26. else
  27. {
  28. spotIsTaken = false;
  29. }
  30.  
  31. }
  32.  
  33.  
  34. for (int i = )
  35.  
  36.  
  37.  
  38.  
  39. ArrayList<String> points = new ArrayList<String>();
  40.  
  41. points.add(letters[row] + (column + 1));
  42.  
  43.  
  44. System.out.println(letters[row]+ (column + 1));
  45.  
  46. return points;
  47. }
  48.  
  49. }
  50.  
  51.  
  52. // Returns an ArrayList of coordinates
  53. // where a ship of shipSize can be placed
  54. // Example: placeShip(3)
  55. // could return { b3, b4, b5 }
Last edited by peter_budo; Nov 6th, 2009 at 4:25 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
icreamed is offline Offline
1 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: working with Java GUI
Next Thread in Java Forum Timeline: playing PIG





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC