source: galcon-client/src/com/example/helloandroid/Planet.java@ 5a03a06

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

Fleet attack function works now

  • Property mode set to 100644
File size: 1.2 KB
Line 
1package com.example.helloandroid;
2
3import java.util.ArrayList;
4
5public class Planet {
6 int radius;
7 int regenRate; // ships per second
8 private int x;
9 private int y;
10 int faction;
11 int numShips;
12
13 public Planet(int radius, int x, int y) {
14 this.radius = radius;
15 this.x = x;
16 this.y = y;
17 faction = 0;
18 numShips = 0;
19
20 regenRate = 0; //change this to some expression / funcion call
21 }
22
23 public int getX() {
24 return x;
25 }
26
27 public int getY() {
28 return y;
29 }
30
31 public int getRadius() {
32 return radius;
33 }
34
35 public int getNumShips() {
36 return numShips;
37 }
38
39 public void setNumShips(int num) {
40 numShips = num;
41 }
42
43 public void setFaction(int faction) {
44 this.faction = faction;
45 }
46
47 public void update() {
48 //regen ships if not owned by faction 0
49 numShips++;
50 }
51
52 public void sendFleet(Planet p, int numShips) {
53
54 }
55
56 public boolean collides(Planet p) {
57 double dist = Math.sqrt(Math.pow(this.x-p.x, 2) + Math.pow(this.y-p.y, 2));
58
59 return dist <= this.radius + p.radius;
60 }
61
62 public static boolean collisionDetected(Planet p, ArrayList<Planet> curPlanets) {
63 for(Planet p2 : curPlanets) {
64 if(p.collides(p2))
65 return true;
66 }
67
68 return false;
69 }
70}
Note: See TracBrowser for help on using the repository browser.