Skip to content

Commit

Permalink
somewhat ready for test
Browse files Browse the repository at this point in the history
  • Loading branch information
olewehrmeyer committed Oct 1, 2014
1 parent d6c367a commit 3ab65e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ protected void onCreate(Bundle savedInstanceState) {

ButterKnife.inject(this);

if (GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0L) <= 0) {
/*if (GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0L) <= 0) {
seed = System.currentTimeMillis();
GeotownApplication.getPreferences().edit().putLong(AppConstants.PREF_PRNG_SEED, seed).apply();
}
}*/

doBindService();

Expand Down Expand Up @@ -280,7 +280,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent.putExtra("ENCODE_FORMAT", "QR_CODE");
intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");

String qrPayload = AppConstants.QR_CODE_PREFIX + ":" + GeotownApplication.getPreferences().getLong(AppConstants.PREF_CURRENT_ROUTE, 0L) + ":" + seed;
String qrPayload = AppConstants.QR_CODE_PREFIX + ":" + GeotownApplication.getPreferences().getLong(AppConstants.PREF_CURRENT_ROUTE, 0L) + ":" + GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0L);
intent.putExtra("ENCODE_DATA", qrPayload);

try {
Expand Down Expand Up @@ -369,11 +369,12 @@ private void routeEnd(boolean finished) {
.putLong(AppConstants.PREF_CURRENT_WAYPOINT, -1L).apply();
GeotownApplication.getPreferences().edit()
.putLong(AppConstants.PREF_CURRENT_ROUTE, -1L).apply();
GeotownApplication.getPreferences().edit()
.putLong(AppConstants.PREF_PRNG_SEED, 0L).apply();

if(finished) {
//we finished the route
GeotownApplication.getPreferences().edit()
.putLong(AppConstants.PREF_PRNG_SEED, 0L).apply();

GameUtil.publishRouteFinishToPlayGames(this, mGameHelper);

Crouton.makeText(this, R.string.message_playing_route_finished, Style.CONFIRM).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public void onClick(DialogInterface dialog, int which) {

} else { //No current Route
editor.putLong(AppConstants.PREF_CURRENT_ROUTE, mRoute.id);
editor.putLong(AppConstants.PREF_PRNG_SEED, 0L);
editor.apply();

//if route was played before, reset it now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,14 @@ public void onCreate() {
loadRoute();

long seed = GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0);
Log.d("Seed", "seed is " + seed + " : " + (seed != 0L));

random = new Random((seed != 0L) ? seed : System.currentTimeMillis());
if(seed == 0L) {
seed = System.currentTimeMillis();
GeotownApplication.getPreferences().edit().putLong(AppConstants.PREF_PRNG_SEED, seed).apply();
Log.d("seed", "put seed " + seed);
}
random = new Random(seed);
}

@Override
Expand Down Expand Up @@ -329,6 +335,8 @@ private void sendMessage(int messageCode, int arg1, int arg2) {
}

private void reportDistanceToTarget() {
if(currentTarget == null)
return;
if (distanceToTarget == -1) {
Location oldGPS = LocationServices.FusedLocationApi.getLastLocation(mApiClient);
if (oldGPS != null) {
Expand Down Expand Up @@ -425,7 +433,7 @@ private void selectNewWaypoint() {
.from(GeoTownWaypoint.class)
.where("done = ?", false)
.where("route = ?", currentRoute.getId())
.orderBy("question")
.orderBy("RANDOM()")
.execute();

Log.d("selectNewWaypoint", "new route null?: " + (currentWaypoint == null));
Expand All @@ -446,7 +454,8 @@ private void selectNewWaypoint() {
Log.d("GameService", "NO TRACK UPLOAD");
}
} else {
int index = random.nextInt(waypoints.size());
int index = Math.abs(random.nextInt() % waypoints.size());
Log.d("seed", "index: " + index + ": " + waypoints.size());
currentWaypoint = waypoints.get(index);
currentWaypoint.save();
Log.d("selectNewWaypoint", "new ID: " + currentWaypoint.id);
Expand Down

0 comments on commit 3ab65e3

Please sign in to comment.