Commits

littledot5566 committed 4c7bab5

*Added travelled threshold when generating prizes.

Comments (0)

Files changed (2)

src/nctuw/littledot/localtreasure/components/ExpeditionActivity.java

 import nctuw.littledot.util.Echo;
 import nctuw.littledot.util.Leg;
 
+import org.holoeverywhere.app.AlertDialog;
 import org.holoeverywhere.app.ProgressDialog;
 import org.holoeverywhere.widget.Toast;
 
 			return pdLock;
 
 		} else if (id == EXPEDITION_COMPLETE_DIALOG) {
-			return DialogManager.onCreateDialog(this, mExpedition);
+			long seconds = (mExpedition.getEndTS() - mExpedition.getStartTS()) / 1000;
+
+			String message;
+			if (mExpedition.getPrize() != null) {
+				message = String.format(
+						"You have come a long way to complete this expedition!\n\n"
+								+ "You have found some %s in your travels.\n\n"
+								+ "Distance travelled: %f meters\n"
+								+ "Time taken: %d seconds\n",
+						mExpedition.getPrize().getName(), mExpedition.getTravelled(),
+						seconds);
+			}
+			else {
+				message = String.format(
+						"You have come a long way to complete this expedition!\n\n"
+								+ "Distance travelled: %f meters\n"
+								+ "Time taken: %d seconds\n",
+						mExpedition.getTravelled(), seconds);
+			}
+
+			// Use the Builder class for convenient dialog construction
+			AlertDialog.Builder builder = new AlertDialog.Builder(this);
+
+			builder.setTitle("Congratulations!").setMessage(message)
+					.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+						public void onClick(DialogInterface dialog, int id) {
+							dialog.dismiss();
+							finish();
+						}
+					});
+
+			return builder.create();
 		}
 
 		return super.onCreateDialog(id, args);
 			Leg.a("apart=" + distLeft + " required=" + mExpedition.getDistance()
 					* 0.05);
 			mExpedition.setEndTS(System.currentTimeMillis());
-			mExpedition.setPrize(Treasure.generateReward());
+			mExpedition.setPrize(Treasure.generateReward(mExpedition));
 
 			mSP.setActiveExpeditionID(0);
 

src/nctuw/littledot/localtreasure/database/Treasure.java

 import java.util.Random;
 
 import nctuw.littledot.localtreasure.R;
-import android.os.Parcel;
-import android.os.Parcelable;
 
 public enum Treasure {
 	WOOD(1, R.drawable.item_wood_24_24, "Wood"),
 	 * 
 	 * @return
 	 */
-	public static Treasure generateReward() {
+	public static Treasure generateReward(Expedition e) {
+		if (e.getTravelled() < 500D)
+			return null;
+
 		Random rand = new Random();
-		int index = rand.nextInt(values().length);
+		int index = 0;
+
+		// different tiers of reward based on distance travelled?
+		if (e.getTravelled() > 500D)
+			index = rand.nextInt(values().length);
 
 		return values()[index];
 	}