Changes in / [8a4e64f:3e9f39e] in galcon-client
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r8a4e64f r3e9f39e 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 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 } 14 42 15 43 this.numShips = numShips; … … 18 46 } 19 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 20 121 public void update() { 21 122 … … 24 125 // attack the destination planet 25 126 public void attack() { 127 if(numShips <= destination.numShips ){ 26 128 129 } 27 130 } 28 131 }
Note:
See TracChangeset
for help on using the changeset viewer.