[159eef8] | 1 | package com.example.helloandroid;
|
---|
| 2 |
|
---|
[96857ee] | 3 | import java.math.*;
|
---|
| 4 |
|
---|
[159eef8] | 5 | public class Fleet {
|
---|
[96857ee] | 6 | private int x;
|
---|
| 7 | private int y;
|
---|
| 8 | private double slope, xIntercept;
|
---|
| 9 | private double direction;
|
---|
| 10 | private Planet destination;
|
---|
| 11 | private int numShips;
|
---|
| 12 | private int faction;
|
---|
[159eef8] | 13 |
|
---|
[96857ee] | 14 | /* Optimising: pre-calculate paths */
|
---|
[159eef8] | 15 | public Fleet(Planet source, Planet destination, int numShips, int faction) {
|
---|
[96857ee] | 16 | //Calculate initial coordinates and direction
|
---|
| 17 |
|
---|
| 18 | //line formula
|
---|
| 19 | slope = ((source.y - destination.y)/(source.x - destination.x));
|
---|
| 20 | xIntercept = destination.y - (slope*destination.x);
|
---|
| 21 |
|
---|
| 22 | //direction
|
---|
| 23 | direction = 1/Math.tan(slope);
|
---|
| 24 |
|
---|
| 25 | //coordinates for all 4 coordinates
|
---|
| 26 | if ((direction >= 0) && (direction < Math.PI/2)){
|
---|
| 27 | x = (int)(Math.cos(direction)*(source.radius + 10) + source.x );
|
---|
| 28 | y = (int)(Math.sin(direction)*(source.radius + 10) + source.y );
|
---|
| 29 | } else if((direction >= Math.PI/2) && (direction < Math.PI)){
|
---|
| 30 |
|
---|
| 31 | } else if((direction >= Math.PI) && (direction < 3*Math.PI/2)){
|
---|
[159eef8] | 32 |
|
---|
[96857ee] | 33 | } else {
|
---|
| 34 |
|
---|
| 35 | }
|
---|
[159eef8] | 36 | this.numShips = numShips;
|
---|
| 37 | this.faction = faction;
|
---|
| 38 | this.destination = destination;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
[96857ee] | 42 | public int getX() {
|
---|
| 43 | return x;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | public void setX(int x) {
|
---|
| 49 | this.x = x;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | public int getY() {
|
---|
| 55 | return y;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | public void setY(int y) {
|
---|
| 61 | this.y = y;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | public double getDirection() {
|
---|
| 67 | return direction;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | public void setDirection(double direction) {
|
---|
| 73 | this.direction = direction;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | public Planet getDestination() {
|
---|
| 79 | return destination;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | public void setDestination(Planet destination) {
|
---|
| 85 | this.destination = destination;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | public int getNumShips() {
|
---|
| 91 | return numShips;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | public void setNumShips(int numShips) {
|
---|
| 97 | this.numShips = numShips;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | public int getFaction() {
|
---|
| 103 | return faction;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | public void setFaction(int faction) {
|
---|
| 109 | this.faction = faction;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | public void update() {
|
---|
| 115 | //update coordinates
|
---|
| 116 |
|
---|
[159eef8] | 117 | }
|
---|
| 118 |
|
---|
| 119 | // attack the destination planet
|
---|
| 120 | public void attack() {
|
---|
[96857ee] | 121 | //planet attack
|
---|
[159eef8] | 122 | }
|
---|
| 123 | }
|
---|