Skip to content

Commit

Permalink
Merge pull request #111 from 2AA4-W24/salma
Browse files Browse the repository at this point in the history
Fixed battery not decreasing properly for echo/scan
  • Loading branch information
hydrowoxy authored Mar 17, 2024
2 parents 0474e4e + 9e57c8b commit 0a32505
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ca/mcmaster/se2aa4/island/team101/Drone.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void update(Response<?> response) {

// Set the charge based on the response cost
setCharge(typedResponse.getCost());
logger.info("COST OF ACTION: " + typedResponse.getCost());

// Update the map only if it was a scan response
if (lastCommand.equals("scan")) {
Expand Down Expand Up @@ -73,7 +74,9 @@ public Compass getCompass(){
}

private void setCharge(Integer cost) {
logger.info("BATTERY WAS: " + charge);
charge -= cost;
logger.info("BATTERY HAS BEEN CHANGED TO: " + charge);
logger.info("Battery level: {}", charge);
if (charge <= 0) {
logger.info("*** Drone is out of battery. ***");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public class EchoHandler implements ResponseHandler<EchoResponse> {
@Override
public EchoResponse handle(JSONObject response, JSONObject extras) {
int cost = extras.optInt("cost");
int cost = response.optInt("cost");
String status = response.optString("status");
int range = extras.optInt("range", 0);
String found = extras.optString("found", "Unknown");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ca.mcmaster.se2aa4.island.team101;

public class GenericResponse {
private final int cost;
private final String status;
protected final int cost;
protected final String status;

public GenericResponse(int cost, String status) {
this.cost = cost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class ScanHandler implements ResponseHandler<ScanResponse> {
@Override
public ScanResponse handle(JSONObject response, JSONObject extras) {
int cost = extras.optInt("cost");
int cost = response.optInt("cost");
String status = response.optString("status");
JSONArray biomes = extras.optJSONArray("biomes");
JSONArray creeks = extras.optJSONArray("creeks");
Expand Down

0 comments on commit 0a32505

Please sign in to comment.