Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package less1.tanks;
- import java.util.Random;
- /**
- * Created by BJJ on 12.02.2016.
- */
- public class Tank {
- private BattleField battleField ;
- private ActionField act ;
- private Bullet bullet ;
- // 1 - top, 2 - bottom, 3 - left, 4 - right
- private int direction = 3;
- private int x = 192;
- private int y = 512;
- private int speed = 6;
- public int getDirection() {
- return direction;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- public int getSpeed() {
- return speed;
- }
- public int updeteX(int x){
- return this.x+=x;
- }
- public int updeteY(int y){
- return this.y+=y;
- }
- public Tank(ActionField act, BattleField battleField){
- this(act,battleField,64,64,2);
- }
- public Tank(ActionField act,BattleField battleField,int x,int y, int direction){
- this.act =act;
- this.battleField = battleField;
- this.x = x;
- this.y = y;
- this.direction = direction;
- }
- public int random(int a) throws Exception{
- Random r = new Random();
- int i;
- while (true) {
- i = r.nextInt(a);
- if (i > 0) {
- return i;
- }
- }
- }
- void startRandomTankPosition()throws Exception{
- if(random(10)==9)
- {x=0;
- y=0;
- }else{
- x =random(9)*64;
- y =random(9)*64;
- }
- }
- public void turn(int direction) throws Exception {
- this.direction =direction;
- act.processTurn(this);
- }
- public void move()throws Exception{
- act.processMove(this);
- }
- void clean()throws Exception{
- act.processClean();
- }
- void moveRandom() throws Exception{
- act.processMoveRandom();
- }
- void fire() throws Exception {
- Bullet bullet = new Bullet(x+25,y+25,direction) ;
- act.processFire(bullet);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement