Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This is the driving engine of the program. It parses the command-line
- * arguments and calls the appropriate methods in the other classes.
- *
- * You should edit this file in three ways:
- * 1) Insert your database username and password in the proper places.
- * 2) Implement the generation of the world by reading the world file.
- * 3) Implement the three functions showPossibleMoves, showPlayerAssets
- * and showScores.
- */
- import java.math.BigDecimal;
- import java.net.URL;
- import java.sql.*; // JDBC stuff.
- import java.util.Calendar;
- import java.util.Map;
- import java.util.Properties;
- import java.io.*; // Reading user input.
- import java.util.ArrayList;
- import java.util.concurrent.Executor;
- import java.util.*;
- public class GameCopy
- {
- public class Player
- {
- String playername;
- String personnummer;
- String country;
- private String startingArea;
- public Player (String name, String nr, String cntry, String startingArea) {
- this.playername = name;
- this.personnummer = nr;
- this.country = cntry;
- this.startingArea = startingArea;
- }
- }
- String USERNAME = "USERNAME";
- String PASSWORD = "PASSWORD";
- /* Print command optionssetup.
- * /!\ you don't need to change this function! */
- public void optionssetup() {
- System.out.println();
- System.out.println("Setup-Options:");
- System.out.println(" n[ew player] <player name> <personnummer> <country>");
- System.out.println(" d[one]");
- System.out.println();
- }
- /* Print command options.
- * /!\ you don't need to change this function! */
- public void options() {
- System.out.println("\nOptions:");
- System.out.println(" n[ext moves] [area name] [area country]");
- System.out.println(" l[ist properties] [player number] [player country]");
- System.out.println(" s[cores]");
- System.out.println(" r[efund] <area1 name> <area1 country> [area2 name] [area2 country]");
- System.out.println(" b[uy] [name] <area1 name> <area1 country> [area2 name] [area2 country]");
- System.out.println(" m[ove] <area1 name> <area1 country>");
- System.out.println(" p[layers]");
- System.out.println(" q[uit move]");
- System.out.println(" [...] is optional\n");
- }
- /* Given a town name, country and population, this function
- * should try to insert an area and a town (and possibly also a country)
- * for the given attributes.
- */
- void insertTown(Connection conn, String name, String country, String population) throws SQLException {
- /* Check if the specified country exists in the "Countries"-table.
- If it doesn't, insert it. Then insert the new area.
- */
- try {
- String check = "select count(1) from Countries where name = '" + country + "'";
- PreparedStatement ps = conn.prepareStatement(check);
- ResultSet rs = ps.executeQuery();
- boolean recordFound = rs.next();
- //If the country didn't exist, insert it.
- if (!recordFound) {
- Statement st = conn.createStatement();
- st.executeUpdate("INSERT INTO Countries " +
- "VALUES ('"+country+"')");
- }
- Statement st = conn.createStatement();
- st.executeUpdate("INSERT INTO Areas " +
- "VALUES ('"+country+"', '"+name+"', '"+population+"')");
- st.executeUpdate("INSERT INTO Towns " +
- "VALUES ('"+country+"', '"+name+"')");
- } catch (Exception e) {
- System.err.println("Got an exception in insertTown");
- System.err.println(e.getMessage());
- }
- }
- /* Inserts a country */
- void insertCountry(Connection conn, String country) throws SQLException {
- /* Check that a specified country doesn't exists before inserting it */
- int recordFound = 0;
- try {
- PreparedStatement ps = conn.prepareStatement("SELECT COUNT (name) FROM Countries WHERE name = (?);");
- ps.setString(1, country);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- recordFound = rs.getInt(1);
- }
- } catch (SQLException se) {
- System.err.println(se.getMessage());
- }
- try {
- if (recordFound < 1) {
- PreparedStatement st = conn.prepareStatement("INSERT INTO Countries (name) VALUES (?);");
- st.setString(1, country);
- st.executeUpdate();
- }
- } catch (SQLException se) {
- System.out.println("Error in insertCountry");
- System.out.println(se.getMessage());
- }
- }
- /* Given a city name, country and population, this function
- * should try to insert an area and a city (and possibly also a country)
- * for the given attributes.
- * The city visitbonus should be set to 0.
- */
- void insertCity(Connection conn, String name, String country, String population) throws SQLException {
- /* Check if the specified country exists in the "Countries"-table.
- If it doesn't, insert it. Then insert the new area.
- */
- /*
- int recordFound = 0;
- try {
- String check = "select count(1) from Countries where name = '" + country + "'";
- PreparedStatement ps = conn.prepareStatement(check);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- recordFound = rs.getInt(1);
- }
- } catch (SQLException se) {
- System.err.println(recordFound);
- System.err.println(se.getMessage());
- }
- */
- try {
- /*
- PreparedStatement st = conn.prepareStatement("INSERT INTO Countries (name) VALUES (?);");
- st.setString(1, country);
- st.executeUpdate();
- */
- insertCountry(conn, country);
- } catch (SQLException se) {
- System.err.println("Error inserting country in insertCity");
- System.err.println(se.getMessage());
- System.exit(2);
- }
- try {
- //Create a new area
- Statement st = conn.createStatement();
- st.executeUpdate("INSERT INTO Areas " +
- "VALUES ('"+country+"', '"+name+"', '"+population+"')");
- //Create a new city and set visitbonus to 0
- st.executeUpdate("INSERT INTO Cities " +
- "VALUES ('"+country+"', '"+name+"', 0)");
- } catch (Exception e) {
- System.err.println("Got an exception in insertCity");
- System.err.println(e.getMessage());
- System.exit(2);
- }
- }
- /* Given two areas, this function
- * should try to insert a government owned road with tax 0
- * between these two areas.
- */
- void insertRoad(Connection conn, String area1, String country1, String area2, String country2) throws SQLException {
- String emptyString = "";
- //ssn and name for the government is, as defined in the LabPM, "".
- try {
- Statement st = conn.createStatement();
- st.executeUpdate("INSERT INTO Roads " +
- "VALUES ('"+country1+"', '"+area1+"', '"+country2+"', '"+area2+"', '"+emptyString+"', '"+emptyString+"', 0)");
- } catch (Exception e) {
- System.err.println("Got an exception in insertRoad");
- System.err.println(e.getMessage());
- }
- }
- /* Given a player, this function
- * should return the area name of the player's current location.
- */
- String getCurrentArea(Connection conn, Player person) throws SQLException {
- String name = person.playername;
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery("SELECT locationArea FROM Persons WHERE name = '" + name + "'");
- return rs.getString("name");
- }
- /* Given a player, this function
- * should return the country name of the player's current location.
- */
- String getCurrentCountry(Connection conn, Player person) throws SQLException {
- String name = person.playername;
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery("SELECT locationCountry FROM Persons WHERE name = '" + name + "'");
- return rs.getString("name");
- }
- /* Given a player, this function
- * should try to insert a table entry in persons for this player
- * and return 1 in case of a success and 0 otherwise.
- * The location should be random and the budget should be 1000.
- */
- int createPlayer(Connection conn, Player person) throws SQLException {
- String name = person.playername;
- String personNummer = person.personnummer;
- String country = person.country;
- String startingArea = person.startingArea;
- Statement st = conn.createStatement();
- //Select a random country and area
- String query = ("SELECT country, name FROM Areas ORDER BY RANDOM() LIMIT 1;");
- ResultSet rs = st.executeQuery(query);
- String locationCountry = "", locationArea = "";
- while (rs.next()) {
- locationCountry = rs.getString(1);
- locationArea = rs.getString(2);
- }
- /*Tries to insert the provided and randomized values in the database */
- try {
- Statement stmt = conn.createStatement();
- stmt.executeUpdate("INSERT INTO Persons" +
- "VALUES ('"+country+"', '"+personNummer+"', '"+name+"', '"+locationCountry+"', '"+locationArea+"', '1000')");
- } catch (Exception e) {
- System.err.println("Got an exception in insertRoad");
- System.err.println(e.getMessage());
- return 0;
- }
- return 1;
- }
- /* Given a player and an area name and country name, this function
- * sould show all directly-reachable destinations for the player from the
- * area from the arguments.
- * The output should include area names, country names and the associated road-taxes
- */
- void getNextMoves(Connection conn, Player person, String area, String country) throws SQLException {
- Statement st = conn.createStatement();
- String query = "SELECT tocountry, toarea, roadtax FROM Roads " +
- "WHERE fromcountry = '"+country+"' AND fromarea = '"+area+"'";
- ResultSet rs = st.executeQuery(query);
- while(rs.next())
- {
- System.out.print("Reachable destinations - Area, Country, Roadtax ");
- System.out.println("Area: " + (rs.getString(1)) + "Country: " +(rs.getString(2))+ " Roadtax: " +(rs.getString(3)) + ".");
- }
- rs.close();
- st.close();
- }
- /* Given a player, this function
- * sould show all directly-reachable destinations for the player from
- * the player's current location.
- * The output should include area names, country names and the associated road-taxes
- */
- void getNextMoves(Connection conn, Player person) throws SQLException {
- Statement st = conn.createStatement();
- /*Get the players location */
- String pname = person.playername;
- String nameQuery = "SELECT locationcountry, locationarea FROM Persons " +
- "WHERE name = '"+pname+"'";
- ResultSet nameSet = st.executeQuery(nameQuery);
- String locCountry = "";
- String locArea = "";
- while(nameSet.next()) {
- locCountry = nameSet.getString(1);
- locArea = nameSet.getString(2);
- }
- nameSet.close();
- /* Get that players reachable locations */
- String locationQuery = "SELECT tocountry, toarea, roadtax FROM Roads " +
- "WHERE fromcountry = '"+locCountry+"' " +
- "AND fromarea = '"+locArea+"' ";
- ResultSet locationSet = st.executeQuery(locationQuery);
- /* Print all reachable destinations */
- while(locationSet.next()) {
- System.out.println("Area: " + (locationSet.getString(1)) + "Country: " +(locationSet.getString(2))+ " Roadtax: " +(locationSet.getString(3)) + ".");
- }
- locationSet.close();
- st.close();
- }
- /* Given a personnummer and a country, this function
- * should list all properties (roads and hotels) of the person
- * that is identified by the tuple of personnummer and country.
- */
- void listProperties(Connection conn, String personnummer, String country) {
- try {
- Statement st = conn.createStatement();
- /* Creates a string of the names of all hotels owned */
- String hotelQuery = "SELECT name FROM Hotels WHERE ownercountry = '"+country+"' AND ownerpersonnummer = '"+personnummer+"'";
- ResultSet hotelSet = st.executeQuery(hotelQuery);
- String ownedHotels = "";
- while(hotelSet.next()) {
- ownedHotels = ownedHotels + "Owns hotel " + hotelSet.getString(1) + "\n";
- }
- hotelSet.close();
- /* Creates a string listing owned roads, identified by their start and endpoints */
- String roadQuery = "SELECT fromcountry, fromarea, tocountry, toarea FROM Roads " +
- "WHERE ownercountry = '"+country+"' AND ownerpersonnummer = '"+personnummer+"'";
- ResultSet roadSet = st.executeQuery(roadQuery);
- String ownedRoads = "";
- while(roadSet.next()) {
- String fromCountry = roadSet.getString(1);
- String fromArea = roadSet.getString(2);
- String toCountry = roadSet.getString(3);
- String toArea = roadSet.getString(4);
- ownedRoads = ownedRoads + "Owns road between " + fromCountry + " , " + fromArea + " and " + toCountry + " , " + toArea + "\n";
- }
- } catch (Exception e) {
- System.err.println("Got an exception in listProperties");
- }
- }
- /* Given a player, this function
- * should list all properties of the player.
- */
- void listProperties(Connection conn, Player person) throws SQLException {
- String ssn = person.personnummer;
- String country = person.country;
- listProperties(conn, ssn, country);
- }
- /* This function should print the budget, assets and refund values for all players.
- */
- void showScores(Connection conn) throws SQLException {
- Statement st = conn.createStatement();
- String query = "SELECT * FROM AssetSummary;";
- ResultSet rs = st.executeQuery(query);
- /* Print everything */
- while (rs.next()) {
- System.out.println(rs.getString(0) + " " + rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
- }
- }
- /* Given a player, a from area and a to area, this function
- * should try to sell the road between these areas owned by the player
- * and return 1 in case of a success and 0 otherwise.
- */
- int sellRoad(Connection conn, Player person, String area1, String country1, String area2, String country2) throws SQLException {
- String playerName = person.playername;
- String SSN = person.personnummer;
- Statement st = conn.createStatement();
- /* Updates the given road, making the government the owner. */
- String query = "UPDATE Roads " +
- "SET ownerpersonnummer = ' ' , ownercountry = ' ' " +
- "WHERE ownerpersonnummer = '"+SSN+"' AND fromcountry = '"+country1+"' " +
- "AND fromarea = '"+area1+"' AND tocountry = '"+country2+"' " +
- "AND toArea = '"+area2+"'; ";
- try {
- st.executeUpdate(query);
- }catch (SQLException se){
- return 0;
- }
- return 1;
- }
- /* Given a player and a city, this function
- * should try to sell the hotel in this city owned by the player
- * and return 1 in case of a success and 0 otherwise.
- */
- int sellHotel(Connection conn, Player person, String city, String country) throws SQLException {
- String SSN = person.personnummer;
- Statement st = conn.createStatement();
- /* "Destroys" the hotel, removing it from the table */
- String query = "DELETE FROM Hotels WHERE "+
- "ownerpersonnummer = '"+SSN+"' AND locationcountry = '"+country+"' " +
- "AND locationname = '"+city+"';";
- try {
- st.executeUpdate(query);
- } catch (SQLException se) {
- return 0;
- }
- return 1;
- }
- /* Given a player, a from area and a to area, this function
- * should try to buy a road between these areas owned by the player
- * and return 1 in case of a success and 0 otherwise.
- */
- int buyRoad(Connection conn, Player person, String area1, String country1, String area2, String country2) throws SQLException {
- /* Inserts a new road */
- Statement st = conn.createStatement();
- String ownercountry = person.country;
- String ownerpersonnummer = person.personnummer;
- String query = "INSERT INTO Roads VALUES ('"+country1+"', '"+area1+"', '"+country2+"', '"+area2+"', '"+country2+"', '"+ownercountry+"', '"+ownerpersonnummer+"', getval('roadtax'));";
- try {
- st.executeUpdate(query);
- } catch (SQLException se) {
- System.out.println("Got an exception in buyRoad");
- return 0;
- }
- return 1;
- }
- /* Given a player and a city, this function
- * should try to buy a hotel in this city owned by the player
- * and return 1 in case of a success and 0 otherwise.
- */
- int buyHotel(Connection conn, Player person, String name, String city, String country) throws SQLException {
- Statement st = conn.createStatement();
- String ownercountry = person.country;
- String ownerpersonnummer = person.personnummer;
- String query = "INSERT INTO Hotels VALUES ( '"+name+"', '"+country+"', '"+city+"', '"+ownercountry+"', '"+ownerpersonnummer+"')";
- /* Inserts a new hotel in a city */
- try {
- st.executeUpdate(query);
- } catch (SQLException se) {
- System.out.println("Got an exception in buyHotel");
- return 0;
- }
- return 1;
- }
- /* Given a player and a new location, this function
- * should try to update the players location
- * and return 1 in case of a success and 0 otherwise.
- */
- int changeLocation(Connection conn, Player person, String area, String country) throws SQLException {
- String changeCountry = person.country;
- String changePersonnummer = person.personnummer;
- Statement st = conn.createStatement();
- String query = "UPDATE Persons SET locationcountry = '"+country+"', locationarea = '"+area+"' " +
- "WHERE personnummer = '"+changePersonnummer+"' AND country = '"+changeCountry+"';";
- try {
- st.executeUpdate(query);
- } catch (SQLException se) {
- System.out.println("Got an exception in changeLocation");
- return 0;
- }
- return 1;
- }
- /* This function should add the visitbonus of 1000 to a random city
- */
- void setVisitingBonus(Connection conn) throws SQLException {
- Statement st = conn.createStatement();
- /*String query = "UPDATE Cities " +
- "SET visitbonus = 1000 " +
- "WHERE name = (SELECT name FROM CITIES " +
- "ORDER BY RANDOM()" +
- "LIMIT 1);"; */
- String query = "(SELECT NAME FROM CITIES " +
- "ORDER BY RANDOM()" +
- "LIMIT 1);";
- try {
- st.executeQuery(query);
- } catch (SQLException se) {
- /* Terminate the session if an exception is thrown */
- System.out.println(se.getMessage());
- System.out.println("Got an exception in setVisitingBonus");
- System.exit(0);
- }
- }
- /* This function should print the winner of the game based on the currently highest budget.
- */
- void announceWinner(Connection conn) throws SQLException {
- Statement st = conn.createStatement();
- String query = "SELECT * FROM Persons " +
- "WHERE name != ('The government') " +
- "ORDER BY budget DESC LIMIT (1);";
- try {
- System.out.println("And the winner is.....");
- st.executeQuery(query);
- } catch (SQLException se) {
- System.out.println("Got an exception in announceWinner");
- System.exit(0);
- }
- }
- void play (String worldfile) throws IOException {
- // Read username and password from config.cfg
- try {
- BufferedReader nf = new BufferedReader(new FileReader("config.cfg"));
- String line;
- if ((line = nf.readLine()) != null) {
- USERNAME = line;
- }
- if ((line = nf.readLine()) != null) {
- PASSWORD = line;
- }
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- if (USERNAME.equals("USERNAME") || PASSWORD.equals("PASSWORD")) {
- System.out.println("CONFIG FILE HAS WRONG FORMAT");
- return;
- }
- try {
- try {
- Class.forName("org.postgresql.Driver");
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- String url = "jdbc:postgresql://ate.ita.chalmers.se/";
- Properties props = new Properties();
- props.setProperty("user",USERNAME);
- props.setProperty("password",PASSWORD);
- final Connection conn = DriverManager.getConnection(url, props);
- System.out.println("Managed to connect");
- /* This block creates the government entry and the necessary
- * country and area for that.
- */
- try {
- PreparedStatement statement = conn.prepareStatement("INSERT INTO Countries (name) VALUES (?)");
- statement.setString(1, "");
- statement.executeUpdate();
- statement = conn.prepareStatement("INSERT INTO Areas (country, name, population) VALUES (?, ?, cast(? as INT))");
- statement.setString(1, "");
- statement.setString(2, "");
- statement.setString(3, "1");
- statement.executeUpdate();
- statement = conn.prepareStatement("INSERT INTO Persons (country, personnummer, name, locationcountry, locationarea, budget) VALUES (?, ?, ?, ?, ?, cast(? as NUMERIC))");
- statement.setString(1, "");
- statement.setString(2, "");
- statement.setString(3, "Government");
- statement.setString(4, "");
- statement.setString(5, "");
- statement.setString(6, "0");
- statement.executeUpdate();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- // Initialize the database from the worldfile
- try {
- BufferedReader br = new BufferedReader(new FileReader(worldfile));
- String line;
- while ((line = br.readLine()) != null) {
- String[] cmd = line.split(" +");
- if ("ROAD".equals(cmd[0]) && (cmd.length == 5)) {
- insertRoad(conn, cmd[1], cmd[2], cmd[3], cmd[4]);
- } else if ("TOWN".equals(cmd[0]) && (cmd.length == 4)) {
- /* Create an area and a town entry in the database */
- insertTown(conn, cmd[1], cmd[2], cmd[3]);
- } else if ("CITY".equals(cmd[0]) && (cmd.length == 4)) {
- /* Create an area and a city entry in the database */
- insertCity(conn, cmd[1], cmd[2], cmd[3]);
- }
- }
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- ArrayList<Player> players = new ArrayList<Player>();
- while(true) {
- optionssetup();
- String mode = readLine("? > ");
- String[] cmd = mode.split(" +");
- cmd[0] = cmd[0].toLowerCase();
- if ("new player".startsWith(cmd[0]) && (cmd.length == 5)) {
- Player nextplayer = new Player(cmd[1], cmd[2], cmd[3], cmd[4]);
- if (createPlayer(conn, nextplayer) == 1) {
- players.add(nextplayer);
- }
- } else if ("done".startsWith(cmd[0]) && (cmd.length == 1)) {
- break;
- } else {
- System.out.println("\nInvalid option.");
- }
- }
- System.out.println("\nGL HF!");
- int roundcounter = 1;
- int maxrounds = 5;
- while(roundcounter <= maxrounds) {
- System.out.println("\nWe are starting the " + roundcounter + ". round!!!");
- /* for each player from the playerlist */
- for (int i = 0; i < players.size(); ++i) {
- System.out.println("\nIt's your turn " + players.get(i).playername + "!");
- System.out.println("You are currently located in " + getCurrentArea(conn, players.get(i)) + " (" + getCurrentCountry(conn, players.get(i)) + ")");
- while (true) {
- options();
- String mode = readLine("? > ");
- String[] cmd = mode.split(" +");
- cmd[0] = cmd[0].toLowerCase();
- if ("next moves".startsWith(cmd[0]) && (cmd.length == 1 || cmd.length == 3)) {
- /* Show next moves from a location or current location. Turn continues. */
- if (cmd.length == 1) {
- String area = getCurrentArea(conn, players.get(i));
- String country = getCurrentCountry(conn, players.get(i));
- getNextMoves(conn, players.get(i));
- } else {
- getNextMoves(conn, players.get(i), cmd[1], cmd[2]);
- }
- } else if ("list properties".startsWith(cmd[0]) && (cmd.length == 1 || cmd.length == 3)) {
- /* List properties of a player. Can be a specified player
- or the player himself. Turn continues. */
- if (cmd.length == 1) {
- listProperties(conn, players.get(i));
- } else {
- listProperties(conn, cmd[1], cmd[2]);
- }
- } else if ("scores".startsWith(cmd[0]) && cmd.length == 1) {
- /* Show scores for all players. Turn continues. */
- showScores(conn);
- } else if ("players".startsWith(cmd[0]) && cmd.length == 1) {
- /* Show scores for all players. Turn continues. */
- System.out.println("\nPlayers:");
- for (int k = 0; k < players.size(); ++k) {
- System.out.println("\t" + players.get(k).playername + ": " + players.get(k).personnummer + " (" + players.get(k).country + ") ");
- }
- } else if ("refund".startsWith(cmd[0]) && (cmd.length == 3 || cmd.length == 5)) {
- if (cmd.length == 5) {
- /* Sell road from arguments. If no road was sold the turn
- continues. Otherwise the turn ends. */
- if (sellRoad(conn, players.get(i), cmd[1], cmd[2], cmd[3], cmd[4]) == 1) {
- break;
- } else {
- System.out.println("\nTry something else.");
- }
- } else {
- /* Sell hotel from arguments. If no hotel was sold the turn
- continues. Otherwise the turn ends. */
- if (sellHotel(conn, players.get(i), cmd[1], cmd[2]) == 1) {
- break;
- } else {
- System.out.println("\nTry something else.");
- }
- }
- } else if ("buy".startsWith(cmd[0]) && (cmd.length == 4 || cmd.length == 5)) {
- if (cmd.length == 5) {
- /* Buy road from arguments. If no road was bought the turn
- continues. Otherwise the turn ends. */
- if (buyRoad(conn, players.get(i), cmd[1], cmd[2], cmd[3], cmd[4]) == 1) {
- break;
- } else {
- System.out.println("\nTry something else.");
- }
- } else {
- /* Buy hotel from arguments. If no hotel was bought the turn
- continues. Otherwise the turn ends. */
- if (buyHotel(conn, players.get(i), cmd[1], cmd[2], cmd[3]) == 1) {
- break;
- } else {
- System.out.println("\nTry something else.");
- }
- }
- } else if ("move".startsWith(cmd[0]) && cmd.length == 3) {
- /* Change the location of the player to the area from the arguments.
- If the move was legal the turn ends. Otherwise the turn continues. */
- if (changeLocation(conn, players.get(i), cmd[1], cmd[2]) == 1) {
- break;
- } else {
- System.out.println("\nTry something else.");
- }
- } else if ("quit".startsWith(cmd[0]) && cmd.length == 1) {
- /* End the move of the player without any action */
- break;
- } else {
- System.out.println("\nYou chose an invalid option. Try again.");
- }
- }
- }
- setVisitingBonus(conn);
- ++roundcounter;
- }
- announceWinner(conn);
- System.out.println("\nGG!\n");
- } catch (SQLException e) {
- System.err.println(e);
- System.exit(2);
- }
- }
- private String readLine(String s) throws IOException {
- System.out.print(s);
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
- char c;
- StringBuilder stringBuilder = new StringBuilder();
- do {
- c = (char) bufferedReader.read();
- stringBuilder.append(c);
- } while(String.valueOf(c).matches(".")); // Without the DOTALL switch, the dot in a java regex matches all characters except newlines
- System.out.println("");
- stringBuilder.deleteCharAt(stringBuilder.length()-1);
- return stringBuilder.toString();
- }
- /* main: parses the input commands.
- * /!\ You don't need to change this function! */
- public static void main(String[] args) throws Exception
- {
- String worldfile = args[0];
- GameCopy g = new GameCopy();
- g.play(worldfile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement