Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package less1.tanks;
  2.  
  3. import java.util.Random;
  4.  
  5. /**
  6. * Created by BJJ on 12.02.2016.
  7. */
  8. public class Tank {
  9.  
  10. private BattleField battleField ;
  11. private ActionField act ;
  12. private Bullet bullet ;
  13.  
  14. // 1 - top, 2 - bottom, 3 - left, 4 - right
  15. private int direction = 3;
  16. private int x = 192;
  17. private int y = 512;
  18.  
  19. private int speed = 6;
  20.  
  21.  
  22.  
  23. public int getDirection() {
  24. return direction;
  25. }
  26.  
  27.  
  28.  
  29. public int getX() {
  30. return x;
  31. }
  32.  
  33. public int getY() {
  34. return y;
  35. }
  36.  
  37. public int getSpeed() {
  38. return speed;
  39. }
  40.  
  41. public int updeteX(int x){
  42. return this.x+=x;
  43. }
  44.  
  45. public int updeteY(int y){
  46. return this.y+=y;
  47. }
  48.  
  49.  
  50. public Tank(ActionField act, BattleField battleField){
  51. this(act,battleField,64,64,2);
  52.  
  53. }
  54.  
  55. public Tank(ActionField act,BattleField battleField,int x,int y, int direction){
  56.  
  57. this.act =act;
  58. this.battleField = battleField;
  59. this.x = x;
  60. this.y = y;
  61. this.direction = direction;
  62.  
  63. }
  64.  
  65. public int random(int a) throws Exception{
  66.  
  67. Random r = new Random();
  68. int i;
  69. while (true) {
  70. i = r.nextInt(a);
  71. if (i > 0) {
  72. return i;
  73. }
  74. }
  75. }
  76.  
  77. void startRandomTankPosition()throws Exception{
  78. if(random(10)==9)
  79. {x=0;
  80. y=0;
  81. }else{
  82. x =random(9)*64;
  83. y =random(9)*64;
  84. }
  85.  
  86. }
  87.  
  88. public void turn(int direction) throws Exception {
  89. this.direction =direction;
  90. act.processTurn(this);
  91. }
  92.  
  93. public void move()throws Exception{
  94. act.processMove(this);
  95. }
  96.  
  97. void clean()throws Exception{
  98. act.processClean();
  99. }
  100.  
  101. void moveRandom() throws Exception{
  102. act.processMoveRandom();
  103. }
  104.  
  105.  
  106.  
  107.  
  108. void fire() throws Exception {
  109. Bullet bullet = new Bullet(x+25,y+25,direction) ;
  110. act.processFire(bullet);
  111. }
  112.  
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement