From ef4a818ace531f07620c0de25b45b27593f8691e Mon Sep 17 00:00:00 2001 From: Max Gerbeth Date: Sun, 15 Jan 2023 17:57:35 +0100 Subject: [PATCH] Create JSONObjects in Shop.buy() --- src/main/java/org/bitbiome/shop/Shop.java | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 6e9fe3b..0fdd3c5 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -4,6 +4,7 @@ import org.json.JSONArray; import org.json.JSONObject; import java.io.File; +import java.io.FileWriter; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -19,8 +20,28 @@ public class Shop { currentShopItems = loadPartofItems(allItems, 2); } - public boolean buy(){ - //ToDo + public boolean buy(String itemName, int amount){ + System.out.println("Hallo"); + //Create File Objects + File filePlayerConfig = new File("src/main/resources/playerconfig.json"); + File fileGameConfig = new File("src/main/resources/gameconfig.json"); + File fileItem = new File("src/main/resources/items.json"); + try { + //Create JSONObjects + String content1 = new String(Files.readAllBytes(Paths.get(filePlayerConfig.toURI())), "UTF-8"); + JSONObject playerConfig = new JSONObject(content1); + + String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8"); + JSONObject gameConfig = new JSONObject(content2); + + String content3 = new String(Files.readAllBytes(Paths.get(fileItem.toURI())), "UTF-8"); + JSONArray itemJSON = new JSONArray(content3); + + + + }catch (Exception e){ + e.printStackTrace(); + } return true; }