/** * Takes all commands from the database * * @param gameId game to get the commands for * @return list of all commands */ @Override public List<ICommand> readAllCommands(int gameId) { List<ICommand> commands = new ArrayList<>(); try { File file = new File(fileName + gameId + ".txt"); if (!file.exists()) return commands; GsonBuilder gson = new GsonBuilder(); BufferedReader br = new BufferedReader(new FileReader(file)); String line = br.readLine(); while (line != null) { Scanner scan = new Scanner(line); String type = scan.next(); String newCommand = scan.nextLine(); CommandType ct = CommandType.convert(type); commands.add(CommandType.getClass(ct, newCommand)); line = br.readLine(); } br.close(); } catch (IOException e) { System.out.println("Error in TextCommandDAO readAllPlayers"); } return commands; }