Advertisement
Guest User

Arrays.java

a guest
Apr 30th, 2011
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. /**
  2. *
  3. * @author Damien Bell <SkyeShatter@gmail.com>
  4. */
  5.  
  6. public class Arrays {
  7. private char[][] Arrays;
  8. private boolean used;
  9.  
  10. public Arrays(char[][] PlayerArray) {
  11. Arrays = PlayerArray;
  12. }
  13. public void AddBoatVert(int x, int y, int z, char boatLetter) {
  14. int i, j;
  15. for (i=0; i<z; i++){ // while I < SelectedBoat.health, increment i
  16. if (Arrays[y][x]!=' '){ // if X / y do not = default value
  17. System.out.println("Oh dear, it seems as though there is a collision at location: "+Boatloc.ReverseBoatLoc(y, x)+ "Please try another location");// There is a collision at location x/y
  18. for (j=0; j<i; j++){ // for counter j < counter i
  19. if (i > 0){//
  20. y--;
  21. Arrays[y][x]=' ';
  22. }
  23. else if (i<=0){
  24. break;
  25. }
  26. }
  27. }
  28. else {
  29. Arrays[y][x]= boatLetter;
  30. y++;
  31. }
  32.  
  33.  
  34. }// End for
  35. }
  36. public void AddBoatHoriz(int x, int y, int z, char boatLetter) {
  37. int i;
  38. for (i=0; i<z; i++){
  39. if (Arrays[y][x]!=' '){
  40. System.out.println("Oh dear, it seems as though there is a collision at location: "+Boatloc.ReverseBoatLoc(y, x));
  41. x++;
  42. for (i=0; i<z; i++){
  43. Arrays[y][x]=' ';
  44. }
  45. }
  46. else{
  47. Arrays[y][x]= boatLetter;
  48. x++;
  49. }
  50.  
  51.  
  52. }
  53. }
  54.  
  55.  
  56.  
  57. public static void DisplayMap(char[][] Array){
  58. //Player Grid Output.
  59. int i=0, j=0;
  60. System.out.println("____________Player setup:____________\n"); // Top of the 'player positioning' box.
  61. System.out.println(" A B C D E F G H I J"); // Top of grid letters
  62. System.out.println("");// blank line
  63. for (i=0; i < Array.length; i++){ // Outer loop of the 2d array output
  64. if (i< 9){
  65. System.out.print("| "+ (i+1) +" "); // Left side of the box
  66. }
  67. else{
  68. System.out.print("| "+ (i+1) +" ");
  69. }
  70. for (j=0; j<10; j++){ // Inner loop of array
  71. System.out.print(Array[i][j]+ " "); // Array output
  72. }// End inner for.
  73. System.out.println(" |"); // Right side of playermap box
  74. }//End outer for
  75. System.out.println("______________________________________"); // Formatting-- Bottom of box
  76. }
  77.  
  78. public static boolean ArrayCheckPlayer(boolean[][] boolarray, int x, int y){
  79. boolean BoolCheck=false;// Set default boolcheck to false, or spot-unoccupied
  80. if (boolarray[x][y]==false){
  81. BoolCheck=false; // False means the spot is occupied already
  82. }
  83. else if(boolarray[x][y]==true){
  84. BoolCheck=true; // Spot is used.
  85. }
  86. return BoolCheck;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement