Changeset 96857ee in galcon-client for src/com/example/helloandroid
- Timestamp:
- May 26, 2010, 3:46:05 AM (14 years ago)
- Branches:
- master
- Children:
- 1a91f0d
- Parents:
- 159eef8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r159eef8 r96857ee 1 1 package com.example.helloandroid; 2 2 3 import java.math.*; 4 3 5 public class Fleet { 4 int x; 5 int y; 6 double direction; 7 Planet destination; 8 int numShips; 9 int faction; 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; 10 13 14 /* Optimising: pre-calculate paths */ 11 15 public Fleet(Planet source, Planet destination, int numShips, int faction) { 12 x = source.getX(); 13 y = source.getY(); 16 //Calculate initial coordinates and direction 14 17 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 ((direction >= 0) && (direction < Math.PI/2)){ 27 x = (int)(Math.cos(direction)*(source.radius + 10) + source.x ); 28 y = (int)(Math.sin(direction)*(source.radius + 10) + source.y ); 29 } else if((direction >= Math.PI/2) && (direction < Math.PI)){ 30 31 } else if((direction >= Math.PI) && (direction < 3*Math.PI/2)){ 32 33 } else { 34 35 } 15 36 this.numShips = numShips; 16 37 this.faction = faction; … … 18 39 } 19 40 41 42 public int getX() { 43 return x; 44 } 45 46 47 48 public void setX(int x) { 49 this.x = x; 50 } 51 52 53 54 public int getY() { 55 return y; 56 } 57 58 59 60 public void setY(int y) { 61 this.y = y; 62 } 63 64 65 66 public double getDirection() { 67 return direction; 68 } 69 70 71 72 public void setDirection(double direction) { 73 this.direction = direction; 74 } 75 76 77 78 public Planet getDestination() { 79 return destination; 80 } 81 82 83 84 public void setDestination(Planet destination) { 85 this.destination = destination; 86 } 87 88 89 90 public int getNumShips() { 91 return numShips; 92 } 93 94 95 96 public void setNumShips(int numShips) { 97 this.numShips = numShips; 98 } 99 100 101 102 public int getFaction() { 103 return faction; 104 } 105 106 107 108 public void setFaction(int faction) { 109 this.faction = faction; 110 } 111 112 113 20 114 public void update() { 21 115 //update coordinates 116 22 117 } 23 118 24 119 // attack the destination planet 25 120 public void attack() { 26 121 //planet attack 27 122 } 28 123 }
Note:
See TracChangeset
for help on using the changeset viewer.