emotionhero/app/src/main/java/com/rubenvandeven/emotionhero/Game.java

50 lines
1.2 KiB
Java

package com.rubenvandeven.emotionhero;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Created by ruben on 02/09/16.
*
* A play of a level by current user at a specific time
*/
public class Game {
public Long id;
public Scenario scenario;
public float score;
public Date time;
public String remoteId;
public Map<Integer, Hit> hits = new HashMap<>();
public Game(Long id, int lvl_id, float score, Date time, String remoteId) {
this(id, new Scenario(lvl_id, null), score, time, remoteId);
}
public Game(Long id, Scenario scenario, float score, Date time, String remoteId) {
this.id = id;
this.scenario= scenario;
this.score = score;
this.time = time == null ? new Date() : time;
this.remoteId = remoteId;
}
public void addHit(Hit hit) {
hits.put(hit.target.index, hit);
score = calculateScore();
}
private float calculateScore() {
float s = 0;
for(Hit hit: hits.values()) {
s += hit.score;
}
return s;
}
}