Changes in / [38ac100:012e702] in galcon-client
- Location:
- src/com/example/helloandroid
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r38ac100 r012e702 22 22 private boolean isClockwise; 23 23 24 /* Optimi zing: pre-calculate paths */24 /* Optimising: pre-calculate paths */ 25 25 public Fleet(Planet source, Planet destination, int numShips, int faction) { 26 26 source.setNumShips(source.getNumShips()-numShips); -
src/com/example/helloandroid/GameView.java
r38ac100 r012e702 10 10 import android.graphics.Color; 11 11 import android.graphics.Paint; 12 import android.graphics.RectF;13 import android.graphics.Paint.FontMetrics;14 12 import android.os.Bundle; 15 13 import android.os.Handler; … … 79 77 public ArrayList<Fleet> fleets; 80 78 public Planet planetSelected; 81 82 int mFleetSize;83 79 84 80 public DrawingThread(SurfaceHolder surfaceHolder, Context context, … … 105 101 106 102 fleets = new ArrayList<Fleet>(); 107 108 mFleetSize = 50;109 103 } 110 104 … … 245 239 if(Planet.collisionDetected(p, planets)) { 246 240 x--; 247 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth -20<=p.getX()+p.getRadius() ||248 p.getY()-p.getRadius() < 0 || mCanvasHeight -20<=p.getY()+p.getRadius()) {241 }else if(p.getX()-p.getRadius() < 0 || mCanvasWidth<=p.getX()+p.getRadius() || 242 p.getY()-p.getRadius() < 0 || mCanvasHeight<=p.getY()+p.getRadius()) { 249 243 x--; 250 244 }else { … … 349 343 } 350 344 } 351 352 float textSize = mTextPaint.getTextSize();353 mTextPaint.setTextSize(24);354 FontMetrics metrics = mTextPaint.getFontMetrics();355 mTextPaint.setColor(Color.WHITE);356 357 canvas.drawText(mFleetSize+"%", mCanvasWidth-mTextPaint.measureText(mFleetSize+"%"), mCanvasHeight-20-(metrics.ascent+metrics.descent), mTextPaint);358 359 mTextPaint.setTextSize(textSize);360 361 mLinePaint.setColor(Color.YELLOW);362 canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, mCanvasWidth-70, mCanvasHeight-5), 5, 5, mLinePaint);363 364 mLinePaint.setColor(Color.GREEN);365 canvas.drawRoundRect(new RectF(70, mCanvasHeight-15, 70+(mCanvasWidth-140)*mFleetSize/100, mCanvasHeight-5), 5, 5, mLinePaint);366 345 } 367 346 … … 392 371 while(i.hasNext()){ 393 372 f = i.next(); 394 if(f.getNumShips() == 0) {373 if(f.getNumShips() == 0) 395 374 i.remove(); 396 }else375 else 397 376 f.update(planets); 398 377 } … … 434 413 Log.i("Gencon", "Detected touch event"); 435 414 436 if(event.getAction() == MotionEvent.ACTION_UP) { 437 if(70 <= event.getX() && event.getX() <= thread.mCanvasWidth-70 && 438 thread.mCanvasHeight-15 <= event.getY() && event.getY() <= thread.mCanvasHeight-5) { 439 thread.mFleetSize = ((int)event.getX()-70)*100/(thread.mCanvasWidth-140); 415 if(event.getAction() != MotionEvent.ACTION_DOWN) 416 return true; 417 418 synchronized(thread.planetsLock) { 419 if(thread.planetSelected != null) { 420 Planet target = null; 421 422 for(Planet p : thread.planets) { 423 if(p.contains((int)event.getX(), (int)event.getY())) { 424 target = p; 425 break; 426 } 427 } 428 429 if(target != null && thread.planetSelected.getFaction() != 0) { 430 synchronized(thread.fleetsLock) { 431 Fleet f = new Fleet(thread.planetSelected, target, 1, 1); 432 f.setFaction(thread.planetSelected.getFaction()); 433 thread.fleets.add(f); 434 } 435 } 436 437 thread.planetSelected.unselect(); 438 thread.planetSelected = null; 439 }else { 440 for(Planet p : thread.planets) { 441 if(p.contains((int)event.getX(), (int)event.getY())) { 442 p.select(); 443 thread.planetSelected = p; 444 break; 445 } 446 } 440 447 } 441 }else if(event.getAction() == MotionEvent.ACTION_DOWN) {442 synchronized(thread.planetsLock) {443 if(thread.planetSelected != null) {444 Planet target = null;445 446 for(Planet p : thread.planets) {447 if(p.contains((int)event.getX(), (int)event.getY())) {448 target = p;449 break;450 }451 }452 453 if(target != null && target != thread.planetSelected && thread.planetSelected.getFaction() != 0) {454 synchronized(thread.fleetsLock) {455 Fleet f = new Fleet(thread.planetSelected, target, thread.planetSelected.getNumShips()*thread.mFleetSize/100, thread.planetSelected.getFaction());456 f.setFaction(thread.planetSelected.getFaction());457 thread.fleets.add(f);458 }459 }460 461 thread.planetSelected.unselect();462 thread.planetSelected = null;463 }else {464 for(Planet p : thread.planets) {465 if(p.contains((int)event.getX(), (int)event.getY())) {466 p.select();467 thread.planetSelected = p;468 break;469 }470 }471 }472 }473 448 } 474 449 -
src/com/example/helloandroid/Planet.java
r38ac100 r012e702 132 132 133 133 public void update() { 134 if(faction != 0)135 numShips += radius/10;134 //if(faction != 0) 135 //numShips++; 136 136 137 137 }
Note:
See TracChangeset
for help on using the changeset viewer.