Advertisement
Guest User

Field.java

a guest
Sep 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. package jp.starfree.cpsv;
  2.  
  3. /*
  4. * FieldClass
  5. * @author CreeperSaviour
  6. * @version 0.0.1
  7. */
  8.  
  9. public class Field {
  10.  
  11. private int width, height;
  12.  
  13. private final char[][] field;
  14.  
  15. /*
  16. * 10 * 10 のFieldをインスタンス化する
  17. * @since 0.0.1
  18. */
  19. Field() {
  20. this.width = 10;
  21. this.height = 10;
  22. this.field = new char[this.width][this.height];
  23. for(var i = 0; i < this.width; i += 1) {
  24. for(var j = 0; j < this.height; j += 1) {
  25. this.field[i][j] = ' ';
  26. }
  27. }
  28. }
  29.  
  30. /*
  31. * width * height のFieldをインスタンス化する
  32. * @since 0.0.1
  33. * @param width 幅
  34. * @param height 高さ
  35. */
  36. Field(int width, int height) {
  37. if(width != height) {
  38. try { throw new Exception("Failed Instantiating.");
  39. } catch (Exception e) { }
  40. System.exit(-1);
  41. }
  42. this.width = width;
  43. this.height = height;
  44. this.field = new char[this.width][this.height];
  45. for(var i = 0; i < this.width; i += 1) {
  46. for(var j = 0; j < this.height; j += 1) {
  47. this.field[i][j] = ' ';
  48. }
  49. }
  50. }
  51.  
  52. /*
  53. * 引数のfieldをもとにFieldをインスタンス化する
  54. * @since 0.0.1
  55. * @param field フィールド
  56. */
  57. Field(char[][] field) {
  58. this.field = field;
  59. }
  60.  
  61. /*
  62. * widthを返す
  63. * @since 0.0.1
  64. * @return width
  65. */
  66. public int getWidth() {
  67. return this.width;
  68. }
  69.  
  70. /*
  71. * heightを返す
  72. * @since 0.0.1
  73. * @return height
  74. */
  75. public int getHeight() {
  76. return this.height;
  77. }
  78.  
  79. /*
  80. * 左からwidth番目、上からheight番目においての文字を返す
  81. * @since 0.0.1
  82. * @param width 幅
  83. * 壁も含める
  84. * @param height 高さ
  85. * 壁も含める
  86. * @return 失敗したら@
  87. */
  88. public char getSquare(int width, int height) {
  89. return '@';
  90. }
  91.  
  92. /*
  93. * フィールドに左からwidth番目、上からheight番目においての文字を入れる
  94. * @since 0.0.1
  95. * @param width 幅
  96. * @param height 高さ
  97. * @param type 種類
  98. * @return 成功したらtrue, 失敗したらfalse
  99. */
  100. public boolean setSquare(int width, int height, String type) {
  101. return false;
  102. }
  103.  
  104. /*
  105. * フィールドの取得
  106. * @since 0.0.1
  107. * @return Field型のフィールド
  108. */
  109. public Field getField() {
  110. return new Field(this.field);
  111. }
  112.  
  113. /*
  114. * フィールドの取得
  115. * @since 0.0.1
  116. * @return char[][]型のフィールド
  117. */
  118. public char[][] toCharArray() {
  119. return this.field;
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement