[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
|
---|
[1a91f0d] | 17 | if(destination.x - source.x != 0){
|
---|
[96857ee] | 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
|
---|
[1a91f0d] | 26 | if(destination.x - source.x < 0 )
|
---|
| 27 | direction += Math.PI;
|
---|
[159eef8] | 28 |
|
---|
[1a91f0d] | 29 | x = (int)((Math.cos(direction)*(source.radius + 10) + source.x));
|
---|
| 30 | y = (int)((Math.sin(direction)*(source.radius + 10) + source.y));
|
---|
[96857ee] | 31 | } else {
|
---|
[1a91f0d] | 32 | if((destination.y - source.y) > 0 ){
|
---|
| 33 | direction = Math.PI/2;
|
---|
| 34 | x = destination.x;
|
---|
| 35 | y = source.y + source.radius + 10;
|
---|
| 36 | } else {
|
---|
| 37 | direction = 3*Math.PI/2;
|
---|
| 38 | x = destination.x;
|
---|
| 39 | y = source.y - source.radius - 10;
|
---|
| 40 | }
|
---|
[96857ee] | 41 | }
|
---|
[1a91f0d] | 42 |
|
---|
[159eef8] | 43 | this.numShips = numShips;
|
---|
| 44 | this.faction = faction;
|
---|
| 45 | this.destination = destination;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 |
|
---|
[96857ee] | 49 | public int getX() {
|
---|
| 50 | return x;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | public void setX(int x) {
|
---|
| 56 | this.x = x;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | public int getY() {
|
---|
| 62 | return y;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | public void setY(int y) {
|
---|
| 68 | this.y = y;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | public double getDirection() {
|
---|
| 74 | return direction;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | public void setDirection(double direction) {
|
---|
| 80 | this.direction = direction;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | public Planet getDestination() {
|
---|
| 86 | return destination;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | public void setDestination(Planet destination) {
|
---|
| 92 | this.destination = destination;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | public int getNumShips() {
|
---|
| 98 | return numShips;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | public void setNumShips(int numShips) {
|
---|
| 104 | this.numShips = numShips;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | public int getFaction() {
|
---|
| 110 | return faction;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | public void setFaction(int faction) {
|
---|
| 116 | this.faction = faction;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | public void update() {
|
---|
[1a91f0d] | 122 |
|
---|
[159eef8] | 123 | }
|
---|
| 124 |
|
---|
| 125 | // attack the destination planet
|
---|
| 126 | public void attack() {
|
---|
[1a91f0d] | 127 | if(numShips <= destination.numShips ){
|
---|
| 128 |
|
---|
| 129 | }
|
---|
[159eef8] | 130 | }
|
---|
| 131 | }
|
---|