source: galcon-client/src/com/example/helloandroid/Fleet.java@ 3e9f39e

Last change on this file since 3e9f39e was 1a91f0d, checked in by Zero Cool <devnull@…>, 14 years ago

Fleet Class pdate

  • Property mode set to 100644
File size: 2.2 KB
Line 
1package com.example.helloandroid;
2
3import java.math.*;
4
5public class Fleet {
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;
13
14 /* Optimising: pre-calculate paths */
15 public Fleet(Planet source, Planet destination, int numShips, int faction) {
16 //Calculate initial coordinates and direction
17 if(destination.x - source.x != 0){
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(destination.x - source.x < 0 )
27 direction += Math.PI;
28
29 x = (int)((Math.cos(direction)*(source.radius + 10) + source.x));
30 y = (int)((Math.sin(direction)*(source.radius + 10) + source.y));
31 } else {
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 }
41 }
42
43 this.numShips = numShips;
44 this.faction = faction;
45 this.destination = destination;
46 }
47
48
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() {
122
123 }
124
125 // attack the destination planet
126 public void attack() {
127 if(numShips <= destination.numShips ){
128
129 }
130 }
131}
Note: See TracBrowser for help on using the repository browser.