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

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

Fleet attack function works now

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[159eef8]1package com.example.helloandroid;
2
[8a4e64f]3import java.util.ArrayList;
4
[159eef8]5public class Planet {
6 int radius;
7 int regenRate; // ships per second
[9b87c8d]8 private int x;
9 private int y;
[159eef8]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
[9b87c8d]31 public int getRadius() {
32 return radius;
33 }
34
[8a4e64f]35 public int getNumShips() {
36 return numShips;
37 }
38
39 public void setNumShips(int num) {
40 numShips = num;
41 }
42
[1291908]43 public void setFaction(int faction) {
44 this.faction = faction;
45 }
46
[159eef8]47 public void update() {
48 //regen ships if not owned by faction 0
[8a4e64f]49 numShips++;
[159eef8]50 }
51
52 public void sendFleet(Planet p, int numShips) {
53
54 }
[8a4e64f]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 }
[159eef8]70}
Note: See TracBrowser for help on using the repository browser.