Advertisement
Guest User

Untitled

a guest
May 6th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. package Tanker;
  2.  
  3. public class Tank {
  4.  
  5. public int speed;
  6. private int direction;
  7. private int x;
  8. public int y;
  9. public ActionField actionField;
  10. public BattleField battleField;
  11.  
  12. public Tank() throws Exception {
  13. setX(0);
  14. setY(0);
  15. }
  16.  
  17. public Tank(ActionField actionField, BattleField battleField, int x, int y, int direction){
  18. this.actionField = actionField;
  19. this.battleField = battleField;
  20. setX(x);
  21. setY(y);
  22. this.direction = direction;
  23. }
  24.  
  25. public void turn(int direction) throws Exception {
  26. this.direction = direction;
  27. actionField.processTurn(this);
  28. }
  29.  
  30. public void move() throws Exception {
  31. actionField.processMove(this);
  32. }
  33.  
  34. public void moveRandom(int x, int y){
  35.  
  36. }
  37.  
  38. public void moveToQuadrant(){
  39.  
  40. }
  41.  
  42. void fire() throws Exception {
  43.  
  44. Bullet bullet = new Bullet(x+25, y+25,direction);
  45.  
  46. int step = 1;
  47. while ((bullet.getX() >-14 && bullet.getX() <570) && (bullet.getY() >-14 && bullet.getY() <570)) {
  48.  
  49. if (direction == 1) {
  50. bullet.updateY(-step);
  51. } else if (direction == 2) {
  52. bullet.updateY(step);
  53. } else if (direction == 3) {
  54. bullet.updateX(-step);
  55. } else {
  56. bullet.updateX(step);
  57. }
  58.  
  59. actionField.processFire(bullet);
  60. //repaint();
  61. }
  62. }
  63.  
  64.  
  65. public int getDirection() {
  66. return direction;
  67. }
  68.  
  69. public int getSpeed() {
  70. return speed;
  71. }
  72.  
  73. public int getY() {
  74. return y;
  75. }
  76.  
  77. public int getX() {
  78. return x;
  79. }
  80.  
  81. public ActionField getActionField() {
  82. return actionField;
  83. }
  84.  
  85. public BattleField getBattleField() {
  86. return battleField;
  87. }
  88.  
  89. public void setActionField(ActionField actionField) {
  90. this.actionField = actionField;
  91. }
  92.  
  93. public void setBattleField(BattleField battleField) {
  94. this.battleField = battleField;
  95. }
  96.  
  97. public void setDirection(int direction) {
  98. this.direction = direction;
  99. }
  100.  
  101. public void setSpeed(int speed) {
  102. this.speed = speed;
  103. }
  104.  
  105. public void setX(int x) {
  106. this.x = x;
  107. }
  108.  
  109. public void setY(int Y){
  110. this.y = y;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement