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

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

Fleet attack function works now

  • Property mode set to 100644
File size: 2.4 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.getX() - source.getX() != 0){
18 //line formula
19 slope = ((source.getY() - destination.getY())/(source.getX() - destination.getX()));
20 xIntercept = destination.getY() - (slope*destination.getX());
21
22 //direction
23 direction = 1/Math.tan(slope);
24
25 //coordinates for all 4 coordinates
26 if(destination.getX() - source.getX() < 0 )
27 direction += Math.PI;
28
29 x = (int)((Math.cos(direction)*(source.radius + 10) + source.getX()));
30 y = (int)((Math.sin(direction)*(source.radius + 10) + source.getY()));
31 } else {
32 if((destination.getY() - source.getY()) > 0 ){
33 direction = Math.PI/2;
34 x = destination.getX();
35 y = source.getY() + source.radius + 10;
36 } else {
37 direction = 3*Math.PI/2;
38 x = destination.getX();
39 y = source.getY() - 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.getNumShips()){
128 destination.setNumShips(destination.getNumShips() - numShips);
129 } else {
130 destination.setNumShips(numShips - destination.getNumShips());
131 destination.setFaction(this.faction);
132 }
133 }
134}
Note: See TracBrowser for help on using the repository browser.