package edu.miamioh.acm.highscore;

import java.util.ArrayList;

public class HighScoreManager {
	private Game game;
	private ArrayList<HighScore> scores;

	/**
	 * Construct a new HighScoreManager storing the scores for the given Game.
	 *
	 * @param g
	 *            the Game object to store the scores for
	 */
	public HighScoreManager(Game g) {
		game = g;
		scores = new ArrayList<HighScore>();
	}

	/**
	 * Construct a new HighScoreManager storing the scores for the Game with the
	 * given name.
	 *
	 * @param name
	 *            the name of the game to lookup in the database
	 */
	public HighScoreManager(String name) {
		game = getOrCreateGame(name);
		scores = new ArrayList<HighScore>();
	}

	/**
	 * Construct a new HighScore object and append it to the list of scores for
	 * the related Game.
	 *
	 * @param score
	 *            The score that the player earned
	 * @param p
	 *            the Player that scored the score
	 */
	public void newScore(int score, Player p) {
		HighScore s = new HighScore(1, score, game, p);
		scores.add(s);
	}

	/**
	 * Find the player with the given ID, or create it if it doesn't exist.
	 *
	 * @param id
	 *            The ID number of the Player
	 */
	public Player getOrCreatePlayer(int id) {
		return new Player(id, "Nate");
	}

	/**
	 * Search the Game database and if a Game with a matching name exists,
	 * return that Game, otherwise create it and save to the database.
	 *
	 * @param name
	 *            The name to search for in the database
	 */
	public Game getOrCreateGame(String name) {
		return new Game(0, name);
	}

	/**
	 * Return the list of {@link HighScore}s associated with the {@link Game}
	 * related to this {@link HighScoreManager}.
	 * 
	 * @return list of {@link HighScore}s
	 */
	public ArrayList<HighScore> getHighScores() {
		return scores;
	}
}
@@ -56,16 +56,35 @@
 rayList;
+%0Aimport java.sql.*;
 %0A%0Apublic
@@ -122,55 +122,184 @@
 ate 
-Game game;%0A%09private ArrayList%3CHighScore%3E scores
+static final String DEFAULT_DB_NAME = %22games.db%22;%0A%09%0A%09private Game game;%0A%09private ArrayList%3CHighScore%3E scores;%0A%09private ArrayList%3CPlayer%3E players;%0A%09private Connection connection
 ;%0A%0A%09
@@ -496,56 +496,491 @@
 %7B%0A%09%09
-game = g;%0A%09%09scores = new ArrayList%3CHighScore%3E();
+this(g, DEFAULT_DB_NAME);%0A%09%7D%0A%09%0A%09public HighScoreManager(Game g, String dbName) %7B%0A%09%09initialize(g, dbName);%0A%09%7D%0A%0A%09private void initialize(Game g, String dbName) %7B%0A%09%09game = g;%0A%09%09scores = new ArrayList%3CHighScore%3E();%0A%09%09players = new ArrayList%3CPlayer%3E();%0A%0A%09%09try %7B%0A%09%09%09Class.forName(%22org.sqlite.JDBC%22);%0A%09%09%09connection = DriverManager.getConnection(%22jdbc:sqlite:%22 + dbName);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09System.err.println(e.getClass().getName() + %22: %22 + e.getMessage());%0A%09%09%09System.exit(0);%0A%09%09%7D
 %0A%09%7D%0A
@@ -1190,33 +1190,37 @@
 eManager(String 
-n
+gameN
 ame) %7B%0A%09%09game = 
@@ -1216,74 +1216,151 @@
 %7B%0A%09%09
-game = getOrCreateGame(n
+this(gameName, DEFAULT_DB_NAME);%0A%09%7D%0A%09%0A%09public HighScoreManager(String gameName, String dbN
 ame)
-;%0A%09%09scores = new ArrayList%3CHighScore%3E(
+ %7B%0A%09%09initialize(getOrCreateGame(gameName), dbName
 );%0A%09
@@ -1902,30 +1902,34 @@
 int id) %7B%0A%09%09
-return
+Player p =
  new Player(
@@ -1941,16 +1941,46 @@
 Nate%22);%0A
+%09%09players.add(p);%0A%09%09return p;%0A
 %09%7D%0A%0A%09/**
@@ -2517,9 +2517,73 @@
 res;%0A%09%7D%0A
+%09%0A%09public ArrayList%3CPlayer%3E getPlayers() %7B%0A%09%09return players;%0A%09%7D%0A
 %7D

update manager