You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. // Carrier = 5
  2. // Battleship = 4
  3. // Cruiser = 3
  4. // Submarine = 3
  5. // Pilot = 2
  6. public class Battleship{
  7. public static final int X = 0;
  8. public static final int Y = 0;
  9. private int[][] playerBoard;
  10. private int[][] computerBoardDisplay;
  11. private int[][] computerBoardHidden;
  12. private static int playerHits;
  13. private static int ComputerHits;
  14. public Battleship(int x, int y){
  15. this.playerBoard = new int[x][y];
  16. this.computerBoardDisplay = new int[x][y];
  17. this.computerBoardHidden = new int[x][y];
  18. }
  19. public int[][] getComputerBoardHidden(){
  20. return this.computerBoardHidden;
  21. }
  22. public int[][] getComputerBoardDisplay(){
  23. return this.computerBoardDisplay;
  24. }
  25. public int[][] getPlayerBoard(){
  26. return this.playerBoard;
  27. }
  28. public static void main(String[] args){
  29. int rand = randint(9,10);
  30. System.out.println(rand);
  31. }
  32. public static void randomizingBoard(int[][] board){
  33. boolean vert = false;
  34. int length;
  35. int[] lengths = {
  36. 2,
  37. 3,
  38. 3,
  39. 4,
  40. 5}
  41. boolean placed;
  42. Ship[] ships = new Ship[5];
  43. for (int i = 1; i < 5; i++){
  44. length = lengths[i]
  45. placed = false;
  46. while (!placed){
  47. int[] start = new int[2];
  48. int[] end = start.clone();
  49. if vert{
  50. end[Y] += length-1;
  51. }
  52. else {
  53. end[X] += length-1;
  54. }
  55. Ship cur_ship = new Ship(start,end);
  56. int rot = 0;
  57. while ((rot < 4) && !placed) {
  58. if cur_ship.isInside(board[0].length,board.length) {
  59. for (int j = 0; j < i + 1; j++){
  60. placed = !isIntersecting(
  61. }
  62. else {
  63. rot = 4;
  64. }
  65. }
  66. // swap starting position each time
  67. if (vert) {
  68. vert = false;
  69. }
  70. else {
  71. vert = true
  72. }
  73. }
  74. }
  75. }