From 043e79a5b46761e0b9fa226eb89472c3f5324a75 Mon Sep 17 00:00:00 2001
From: Martin <ms618@hdm-stuttgart.de>
Date: Mon, 15 Jan 2024 13:36:44 +0100
Subject: [PATCH] Update: Persistence.java (minor fixes) Update:
 PlayerStatistics.java (remade methods to add changes)

---
 .../DataStorage/Classes/Persistence.java      | 13 +++++-----
 .../DataStorage/Classes/PlayerStatistics.java | 24 +++++++++----------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java
index 5ced7271..c1ca1b82 100644
--- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java
+++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java
@@ -294,15 +294,16 @@ public class Persistence {
         }
     }
 
-    public void updatePlayerStatistics(int kills, int deaths, int gameTime, boolean gameWon) throws DatabaseException{  //after game round
-        statistics.setKills(statistics.getKills() + kills);
-        statistics.setDeaths(statistics.getDeaths() + deaths);
-        statistics.setGameTime(statistics.getGameTime() + gameTime);
+    public void updatePlayerStatistics(int kills, int deaths, int gameTime, int blocksDestroyed, boolean gameWon) throws DatabaseException{  //after game round
+        statistics.addKills(kills);
+        statistics.addDeaths(deaths);
+        statistics.addGameTime(gameTime);
+        statistics.addBlocksDestroyed(blocksDestroyed);
         if(gameWon){
-            statistics.setGamesWon(statistics.getGamesWon() + 1);
+            statistics.addGamesWon();
         }
         else{
-            statistics.setGamesWon(statistics.getGamesLost() + 1);
+            statistics.addGamesLost();
         }
         log.info("Statistics successfully updated!");
     }
diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java
index dbfdd698..41a54e7e 100644
--- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java
+++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java
@@ -27,48 +27,48 @@ public class PlayerStatistics {
         return gamesLost;
     }
 
-    public void setGamesLost(int gamesLost) {
-        this.gamesLost = gamesLost;
+    protected void addGamesLost() {
+        gamesLost = gamesLost + 1;
     }
 
     public int getGamesWon() {
         return gamesWon;
     }
 
-    public void setGamesWon(int gamesWon) {
-        this.gamesWon = gamesWon;
+    protected void addGamesWon() {
+        gamesWon = gamesWon + 1;
     }
 
     public int getKills() {
         return kills;
     }
 
-    public void setKills(int kills) {
-        this.kills = kills;
+    protected void addKills(int kills) {
+        this.kills = this.kills + kills;
     }
 
     public int getDeaths() {
         return deaths;
     }
 
-    public void setDeaths(int deaths) {
-        this.deaths = deaths;
+    protected void addDeaths(int deaths) {
+        this.deaths = this.deaths + deaths;
     }
 
     public int getBlocksDestroyed() {
         return blocksDestroyed;
     }
 
-    public void setBlocksDestroyed(int blocksDestroyed) {
-        this.blocksDestroyed = blocksDestroyed;
+    protected void addBlocksDestroyed(int blocksDestroyed) {
+        this.blocksDestroyed = this.blocksDestroyed + blocksDestroyed;
     }
 
     public int getGameTime() {
         return gameTime;
     }
 
-    public void setGameTime(int gameTime) {
-        this.gameTime = gameTime;
+    protected void addGameTime(int gameTime) {
+        this.gameTime = this.gameTime + gameTime;
     }
 
 }
-- 
GitLab