package src;
import org.json.simple.JSONObject;

import java.io.*;

/**
 * Created by user on 04.05.2015.
 */
public class JsonWorker implements IJsonWorker {

    public void AddGameResult(String game, String firstPlayer, String firstPlayerLanguage, String secondPlayer, String secondPlayerLanguage, int gameResult, int sdkVer) throws IOException {

        String fileName = firstPlayer + "VS" + secondPlayer + "result.txt";

        File f = new File(fileName);

        f.createNewFile();

        JSONObject res = makeResultNote(game, firstPlayer, firstPlayerLanguage, secondPlayer, secondPlayerLanguage, gameResult, sdkVer);

        String insertedInFile = res.toString();

        RandomAccessFile file = new RandomAccessFile(fileName, "rw");

        file.skipBytes((int)file.length() - 1);

        file.writeBytes("{\r\n" + insertedInFile + "\r\n" + "}");

        file.close();

    }

    private JSONObject makeResultNote(String game, String firstPlayer, String firstPlayerLanguage, String secondPlayer, String secondPlayerLanguage, int gameResult, int sdkVer){

        JSONObject res = new JSONObject();

        res.put("game", game);
        res.put("firstPlayer", firstPlayer);
        res.put("firstPlayerLanguage", firstPlayerLanguage);
        res.put("secondPlayer", secondPlayer);
        res.put("secondPlayerLanguage",secondPlayerLanguage);
        res.put("gameResult", gameResult);
        res.put("sdkVer", sdkVer);

        return res;
    }

}

@@ -143,20 +143,393 @@
 ts I
-JsonWorker %7B
+DataBaseWorker %7B%0A%0A    public JsonWorker() throws IOException %7B%0A%0A        File f = new File(%22GamesResults.json%22);%0A%0A        if(f.exists())%0A        %7B%0A            f.delete();%0A        %7D%0A%0A        File F = new File(%22GamesResults.json%22);%0A%0A        RandomAccessFile file = new RandomAccessFile(%22GamesResults.json%22, %22rw%22);%0A%0A        file.writeBytes(%22%7B%5Cr%5Cn%5B%5Cr%5Cn%5D%5Cr%5Cn%7D%22);%0A%0A        file.close();%0A    %7D
 %0A%0A  
@@ -721,150 +721,8 @@
  %7B%0A%0A
-        String fileName = firstPlayer + %22VS%22 + secondPlayer + %22result.txt%22;%0A%0A        File f = new File(fileName);%0A%0A        f.createNewFile();%0A
 %0A   
@@ -962,16 +962,27 @@
 ile(
-fileName
+%22GamesResults.json%22
 , %22r
@@ -1034,10 +1034,9 @@
 () -
- 1
+4
 );%0A%0A
@@ -1063,18 +1063,8 @@
 tes(
-%22%7B%5Cr%5Cn%22 + 
 inse
@@ -1086,16 +1086,21 @@
 r%5Cn%22 + %22
+%5D%5Cr%5Cn
 %7D%22);%0A%0A  

Make all games result in one file, may be it works:D