Skip to content
Snippets Groups Projects
Commit 3ff8f710 authored by Schuh Martin's avatar Schuh Martin
Browse files

Merge branch 'DataBase' into 'main'

Merging from Database to development

Closes #16

See merge request !6
parents d4c74a4d 6c4d4c17
No related branches found
Tags v0.1.5
1 merge request!6Merging from Database to development
Showing
with 911 additions and 16 deletions
......@@ -6,3 +6,5 @@
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
/misc.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="battleArena@battlearena.database.windows.net" uuid="7b1fc391-14cb-46cf-a8a0-29c091f02047">
<driver-ref>azure.ms</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc-driver>
<jdbc-url>jdbc:sqlserver://battlearena.database.windows.net:1433;database=battleArena;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
......@@ -7,7 +7,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Scripts/DDL_Script_Oracle.sql" dialect="AZURE" />
<file url="PROJECT" dialect="AZURE" />
</component>
<component name="SqlResolveMappings">
<file url="file://$PROJECT_DIR$/src/main/java/de/hdm_stuttgart/battlearena/Persistance/Classes/DBalt.java" scope="{&quot;node&quot;:{ &quot;@negative&quot;:&quot;1&quot;, &quot;group&quot;:{ &quot;@kind&quot;:&quot;root&quot;, &quot;node&quot;:{ &quot;@negative&quot;:&quot;1&quot; } } }}" />
</component>
</project>
\ No newline at end of file
......@@ -51,6 +51,24 @@
<version>19.0.2.1</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>23.3.0.23.09</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.4.2.jre11</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
<build>
......
......@@ -4,7 +4,6 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class GameSceneController {
private static final Logger log = LogManager.getLogger(GameSceneController.class);
}
package de.hdm_stuttgart.battlearena.Exceptions;
public class DatabaseError extends Exception{
public DatabaseError() {}
public DatabaseError(String message2)
{
super(message2);
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
public class AzureDB implements IDataBase{
/*this class is only here for showcasing the interchangeability of the DBMS*/
private static final Logger log = LogManager.getLogger(OracleDB.class);
@Override
public Connection connect() throws DatabaseError {
try {
String url = "jdbc:sqlserver://battlearena.database.windows.net;encrypt=true;user=battleArenaAdmin;password=krassesRPGGame23#;databaseName=battleArena;";
log.info("Connecting to the database!");
Connection connection = DriverManager.getConnection(url);
log.info("Database connection test" + connection.getCatalog());
connection.setAutoCommit(true);
return connection;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("SQL Connection Error");
}
}
@Override
public ArrayList<MapData> getCoreMaps() throws DatabaseError{
try(Connection connection = connect()) {
ArrayList<MapData> newMaps = new ArrayList<MapData>();
String sql = "SELECT * FROM CoreMaps";
PreparedStatement stmt = connection.prepareStatement(sql);
log.info("Sending SQL statement");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")));
}
log.info("SQL query successful");
rs.close();
stmt.close();
return newMaps;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("Error retrieving Coremaps");
}
}
public ArrayList<String> getCommunityMapsList() throws DatabaseError{
try(Connection connection = connect()) {
ArrayList<String> tempList = new ArrayList<String>();
String sql = "SELECT map_name FROM CommunityMaps";
PreparedStatement stmt = connection.prepareStatement(sql);
log.info("Sending SQL statement");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
tempList.add(rs.getString("map_name"));
}
log.info("SQL query successful");
rs.close();
stmt.close();
return tempList;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("Error retrieving MapList");
}
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Properties;
import java.sql.*;
public class DBalt implements IDataBasealt {
private static final Logger log = LogManager.getLogger(DBalt.class);
@Override
public Connection connect() throws IOException, SQLException {
log.info("Loading the properties File!");
Properties properties = new Properties();
properties.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
log.info("Connecting to the database!");
Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties.getProperty("user"), properties.getProperty("password"));
log.info("Database connection test" + connection.getCatalog());
connection.setAutoCommit(true);
return connection;
}
@Override
public void createNewPlayer(String playerName) throws SQLException, IOException {
try(Connection connection = connect()) {
String sql = "INSERT INTO players (player_name, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time)" + "VALUES (?,?,?,?,?,?,?)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, playerName);
preparedStatement.setInt(2, 0);
preparedStatement.setInt(3, 0);
preparedStatement.setInt(4, 0);
preparedStatement.setInt(5, 0);
preparedStatement.setInt(6, 0);
preparedStatement.setInt(7, 0);
log.info("Inserting new player");
preparedStatement.execute();
}
}
@Override
public void createMap(String name, int length, int width, String mapData) throws SQLException, IOException {
try(Connection connection = connect()) {
String mapSize = length + "X" + width;
String sql = "INSERT INTO battleArena.dbo.maps (map_name, map_size, map_data, map_version, map_hash) VALUES(?,?,?,?,?)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, name);
preparedStatement.setString(2, mapSize);
preparedStatement.setString(3, mapData);
log.info("Inserting new map");
preparedStatement.execute();
}
}
@Override
public LinkedHashMap<String, String> getMapNames() throws SQLException, IOException {
LinkedHashMap<String, String> mapNames = new LinkedHashMap<>();
try(Connection connection = connect()) {
String sql = "SELECT maps.map_id, maps.map_name FROM maps";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
ResultSet results = preparedStatement.executeQuery();
log.info("Getting map names");
while (results.next()) {
mapNames.put(results.getString("map_id"), results.getString("map_name"));
}
connection.close();
return mapNames;
}
}
@Override
public String getMapByID(String ID) throws SQLException, IOException {
try(Connection connection = connect()) {
String sql = "SELECT map_name FROM maps WHERE map_id = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, ID);
log.info("Getting Map...");
String map = preparedStatement.executeQuery().toString();
return map;
}
}
@Override
public String getMapSizeByID(String ID) throws SQLException, IOException {
try(Connection connection = connect()) {
String sql = "SELECT map_size FROM maps WHERE battleArena.dbo.maps.map_id=?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, ID);
ResultSet result = preparedStatement.executeQuery();
log.info("getting map size...");
String mapSize = result.getString("map_size");
return mapSize;
}
}
@Override
public ResultSet getStatistics(String playerName) throws SQLException, IOException {
try(Connection connection = connect()){
String sql = "SELECT * FROM players where player_name = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, playerName);
ResultSet resultSet = preparedStatement.executeQuery();
log.info("getting statistics...");
return resultSet;
}
}
@Override
public void updateMap(String mapID, String mapName, String mapData) throws SQLException, IOException {
try(Connection connection = connect()) {
String sql = "UPDATE maps SET map_name = ?, map_data = ? WHERE map_id = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, mapName);
preparedStatement.setString(2, mapData);
preparedStatement.setString(3, mapID);
preparedStatement.execute();
log.info("updating map in Database");
}
}
@Override
public void updatePlayerName(String playerNameNew, String playerNameOld) throws SQLException, IOException {
try(Connection connection = connect()){
String sql = "UPDATE players SET player_name = ? WHERE player_name = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, playerNameNew);
preparedStatement.setString(2, playerNameOld);
preparedStatement.execute();
log.info("updating player name in Database...");
}
}
@Override
public void updatePlayerStatistics(String playerName, int gamesWon, int gamesLost, int kills, int deaths, int blocksDestroyed, int gameTime) throws SQLException, IOException {
try (Connection connection = connect()){
String sql = "UPDATE players SET games_won = ?, games_lost = ?, kills = ?, " + "deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, gamesWon);
preparedStatement.setInt(2, gamesLost);
preparedStatement.setInt(3, kills);
preparedStatement.setInt(4, deaths);
preparedStatement.setInt(5, blocksDestroyed);
preparedStatement.setInt(6, gameTime);
preparedStatement.setString(7, playerName);
preparedStatement.execute();
log.info("updating player statistics");
}
}
@Override
public void deletePlayer(String playerName) throws IOException, SQLException {
try(Connection connection = connect()) {
String sql = "DELETE FROM players WHERE player_name=?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, playerName);
preparedStatement.execute();
log.info("deleting player");
}
}
@Override
public void deleteMap(String mapID) throws SQLException, IOException {
try(Connection connection = connect()) {
String sql = "DELETE * FROM maps WHERE map_id = ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, mapID);
preparedStatement.execute();
log.info("deleting map...");
}
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.FileReader;
import java.io.FileWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
public class GsonHandler {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final Logger log = LogManager.getLogger(GsonHandler.class);
Type mapDataType = new TypeToken<ArrayList<MapData>>(){}.getType();
public ArrayList<MapData> loadMaps(String filePath) throws DatabaseError{
try (FileReader reader = new FileReader(filePath)) {
ArrayList<MapData> maps = new ArrayList<MapData>();
maps = gson.fromJson(reader, mapDataType);
log.info("GSON - Maps successfully loaded from JSON");
return maps;
} catch (Exception e) {
log.info(e);
log.info("GSON - Loading Maps from JSON failed");
throw new DatabaseError("Error Loading Maps!");
}
}
public void saveMaps(ArrayList<MapData> maps, String filePath) throws DatabaseError{
try (FileWriter writer = new FileWriter(filePath)) {
gson.toJson(maps, writer);
log.info("GSON - Maps successfully saved to JSON");
} catch (
Exception e) {
log.info(e);
log.info("GSON - Saving Maps to JSON failed");
throw new DatabaseError("Error Loading Maps!");
}
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError;
import java.sql.Connection;
import java.util.ArrayList;
public interface IDataBase {
Connection connect() throws DatabaseError;
ArrayList<MapData> getCoreMaps() throws DatabaseError;
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedHashMap;
public interface IDataBasealt {
//connection-Methods
Connection connect() throws IOException, SQLException;
//CRUD Operations
//Create Operations
void createNewPlayer(String playerName) throws SQLException, IOException;
void createMap(String name, int length, int width, String mapData) throws SQLException, IOException;
//Read-operations
LinkedHashMap<String, String> getMapNames() throws SQLException, IOException;
String getMapByID(String ID) throws SQLException, IOException;
String getMapSizeByID(String ID) throws SQLException, IOException;
ResultSet getStatistics(String playerName) throws SQLException, IOException;
//Update-operations
void updateMap(String mapID , String mapName, String mapData) throws SQLException, IOException;
void updatePlayerName(String playerNameNew, String PlayerNameOld) throws SQLException, IOException;
void updatePlayerStatistics(String playerName, int gamesWon, int gamesLost, int kills, int deaths, int blocksDestroyed, int gameTime) throws SQLException, IOException;
//Delete-operations
void deletePlayer(String playerName) throws IOException, SQLException;
void deleteMap(String mapID) throws SQLException, IOException;
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MapData {
private static final Logger log = LogManager.getLogger(Persistence.class);
private String mapID;
private String mapName;
private int mapWidth;
private int mapHeight;
private String mapData;
protected MapData(String mapID, String mapName, int mapWidth, int mapHeight, String mapData) {
try {
this.mapID = mapID;
this.mapName = mapName;
this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
this.mapData = mapData;
}
catch (Exception e){
log.error(e);
}
}
public String getMapID() {
return mapID;
}
public String getMapName() {
return mapName;
}
public int getMapWidth() {
return mapWidth;
}
public int getMapHeight() {
return mapHeight;
}
public String getMapData() {
return mapData;
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import de.hdm_stuttgart.battlearena.Exceptions.DatabaseError;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.sql.*;
import java.util.ArrayList;
import java.util.Properties;
import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleConnection;
public class OracleDB implements IDataBase {
private static final Logger log = LogManager.getLogger(OracleDB.class);
@Override
public Connection connect() throws DatabaseError{
try {
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.eu-frankfurt-1.oraclecloud.com))(connect_data=(service_name=g093caf2cf1fea4_battlearena_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))");
ods.setUser("battlearenaplayer");
ods.setPassword("jo3+++w3rw+s##AA");
Connection conn = ods.getConnection();
log.info("Connecting to the database!");
return conn;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("SQL connection error");
}
}
@Override
public ArrayList<MapData> getCoreMaps() throws DatabaseError{
try(Connection connection = connect()) {
ArrayList<MapData> newMaps = new ArrayList<MapData>();
String sql = "SELECT * FROM battlearenadata.coremaps";
PreparedStatement stmt = connection.prepareStatement(sql);
log.info("Sending SQL statement");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")));
}
rs.close();
stmt.close();
log.info("Coremaps retrieved successfully");
return newMaps;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("Error retrieving coremaps");
}
}
public ArrayList<String> getCommunityMapsList() throws DatabaseError{
try(Connection connection = connect()) {
ArrayList<String> tempList = new ArrayList<String>();
String sql = "SELECT map_name FROM battlearenadata.communitymaps";
PreparedStatement stmt = connection.prepareStatement(sql);
log.info("Sending SQL statement");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
tempList.add(rs.getString("map_name"));
}
rs.close();
stmt.close();
log.info("Community map names retrieved successfully");
return tempList;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("Error retrieving community map names");
}
}
public MapData getCommunityMapByID(String mapID) throws DatabaseError{
try(Connection connection = connect()) {
String sql = "SELECT * FROM battlearenadata.communitymaps WHERE map_ID = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, mapID);
log.info("Sending SQL statement");
ResultSet rs = stmt.executeQuery();
MapData mapChosen = new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data"));
rs.close();
stmt.close();
log.info("Community map retrieved successfully");
return mapChosen;
}
catch(Exception e){
log.error(e);
throw new DatabaseError("Error retrieving community map");
}
}
public void uploadCommunityMapByID(MapData map) throws DatabaseError{
try(Connection connection = connect()) {
String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, map.getMapID());
stmt.setString(2, map.getMapName());
stmt.setInt(3, map.getMapWidth());
stmt.setInt(4, map.getMapHeight());
stmt.setString(5, map.getMapData());
log.info("Sending SQL statement");
stmt.executeQuery();
stmt.close();
log.info("Community Map retrieved successfully");
}
catch(Exception e){
log.error(e);
throw new DatabaseError("Error uploading created community map");
}
}
/*
public void updateCommunityStats(Persistence persistence){
//Update the commulative Stats
}
*/
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.sql.Connection;
import java.util.ArrayList;
public class Persistence {
private static final Logger log = LogManager.getLogger(Persistence.class);
private static final Persistence persistenceSingleton = new Persistence();
private final GsonHandler gsonHandler = new GsonHandler();
private final DBalt sqlHandler = new DBalt(); //??
private Connection connection; //??
protected ArrayList<MapData> coreMaps;
protected ArrayList<MapData> communityMaps;
private final String filePathCoreMaps = "src/main/resources/maps/coreMaps.json";
private final String filePathCommunityMaps = "src/main/resources/maps/communityMaps.json";
private int[] sizeArrayInt; //??
private String sizeString; //??
protected static PlayerStatistics statistics = new PlayerStatistics("", 0,0,0,0,0,0);
//suggestion: rename to "playerData"
OracleDB db = new OracleDB(); //for testing purposes; evtl. Methoden von OracleDB static machen und von GSON Handler
private Persistence (){}
public static Persistence getInstance(){
return persistenceSingleton;
}
public void loadCoreMaps(){
try {
coreMaps = gsonHandler.loadMaps(filePathCoreMaps);
log.info("Maps successfully loaded from file");
//log.info(coreMaps.get(0).getMapName()); //for testing purposes
}
catch(Exception e){
log.error(e);
}
}
public void updateCoreMaps(){
try {
coreMaps = db.getCoreMaps();
gsonHandler.saveMaps(coreMaps, filePathCoreMaps);
log.info("Maps successfully updated from SQL-Server");
//log.info(coreMaps.get(0).getMapName()); //for testing purposes
}
catch(Exception e){
log.error(e);
}
}
public void getCommunityMap(String mapSelected){
try {
communityMaps.add(db.getCommunityMapByID(mapSelected));
gsonHandler.saveMaps(communityMaps, filePathCommunityMaps);
log.info("Community Map successfully retrieved from SQL-Server!");
}
catch(Exception e){
log.error(e);
}
}
public void uploadCommunityMap(MapData map){
try {
db.uploadCommunityMapByID(map);
communityMaps.add(map); //hier noch prüfen, ob die Map lokal bereits existiert (falls eine Verbindung zur DB scheitern sollte, kann man sie dennoch lokal speichern
gsonHandler.saveMaps(communityMaps, filePathCommunityMaps);
log.info("Maps successfully updated from SQL-Server!");
}
catch(Exception e){
log.error(e);
}
}
public void createPlayer (){
}
public void loadStatistics(){
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class PlayerStatistics {
private static final Logger log = LogManager.getLogger(PlayerStatistics.class);
private String playerName;
private int gamesLost;
private int gamesWon;
private int kills;
private int deaths;
private int blocksDestroyed;
private int gameTime;
public PlayerStatistics(String playerName, int gamesLost, int gamesWon, int kills, int deaths, int blocksDestroyed, int gameTime) {
this.playerName = playerName;
this.gamesLost = gamesLost;
this.gamesWon = gamesWon;
this.kills = kills;
this.deaths = deaths;
this.blocksDestroyed = blocksDestroyed;
this.gameTime = gameTime;
}
public String getPlayerName() {
return playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public int getGamesLost() {
return gamesLost;
}
public void setGamesLost(int gamesLost) {
this.gamesLost = gamesLost;
}
public int getGamesWon() {
return gamesWon;
}
public void setGamesWon(int gamesWon) {
this.gamesWon = gamesWon;
}
public int getKills() {
return kills;
}
public void setKills(int kills) {
this.kills = kills;
}
public int getDeaths() {
return deaths;
}
public void setDeaths(int deaths) {
this.deaths = deaths;
}
public int getBlocksDestroyed() {
return blocksDestroyed;
}
public void setBlocksDestroyed(int blocksDestroyed) {
this.blocksDestroyed = blocksDestroyed;
}
public int getGameTime() {
return gameTime;
}
public void setGameTime(int gameTime) {
this.gameTime = gameTime;
}
}
package de.hdm_stuttgart.battlearena.Persistance.Classes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.LinkedHashMap;
public class RuntimeInfo {
private static final Logger log = LogManager.getLogger(RuntimeInfo.class);
private static final RuntimeInfo runtimeInfoSingleton = new RuntimeInfo();
private final Persistence persistenceInst = Persistence.getInstance();
private LinkedHashMap<String, String> mapNames;
public MapData mapCreated; //to store parsed Data from MapCreator for Upload to SQL
public String communityMapSelected;
protected ArrayList<String> coreMapsListLocal; //include mapID
protected ArrayList<String> communityMapsListLocal; //include mapID
protected ArrayList<String> communityMapsListRemote;
public String mapTileString; //Maxe chose this name
private RuntimeInfo(){};
public static RuntimeInfo getInstance(){
return runtimeInfoSingleton;
}
private void setMap(String mapSelected, boolean choseCoremaps){
if(choseCoremaps) {
for (int mapListIndex = 0; mapListIndex < persistenceInst.coreMaps.size(); mapListIndex++) {
if (persistenceInst.coreMaps.get(mapListIndex).getMapID().equals("mapSelected")) {
mapTileString = persistenceInst.coreMaps.get(mapListIndex).getMapID();
}
}
}
else {
for (int mapListIndex = 0; mapListIndex < persistenceInst.communityMaps.size(); mapListIndex++) {
if (persistenceInst.communityMaps.get(mapListIndex).getMapID().equals("mapSelected")) {
mapTileString = persistenceInst.coreMaps.get(mapListIndex).getMapID();
}
}
}
}
public void getCommunityMap(){
persistenceInst.getCommunityMap(communityMapSelected);
}
public void uploadMapCreated(){
persistenceInst.uploadCommunityMap(mapCreated);
}
//add Hash-Creator for creating map_ID and parse if map_data is according to specs
private void updateStats(String outcome, String kills, String deaths, int gameTime){
//update PlayerStatistics
//update SQL
}
public void createCoreMapsList(){
for(int i = 0; i < persistenceInst.coreMaps.size(); i++){
coreMapsListLocal.add(persistenceInst.coreMaps.get(i).getMapName());
}
}
public void createCommunityMapsListLocal(){
try {
for (int i = 0; i < persistenceInst.communityMaps.size(); i++) {
communityMapsListLocal.add(persistenceInst.communityMaps.get(i).getMapName());
}
}
catch (Exception e){
log.info(e);
}
}
//if no Data in JSON throw Exception and inform user
public void fetchCommunityMapListRemote(){
try {
communityMapsListRemote = persistenceInst.db.getCommunityMapsList();
log.info("MapList successfully retrieved from server!");
log.info(communityMapsListRemote.get(0)); //for testing purposes
}
catch(Exception e){
log.error(e);
}
}
public void getStatsByID(String playerID){
//fetches from SQL stats by player with provided ID - players can display stats of other players in "Statistics" Scene
}
}
package de.hdm_stuttgart.battlearena.Persistance;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class DataBase implements IDataBase{
private static final Logger log = LogManager.getLogger(DataBase.class);
}
package de.hdm_stuttgart.battlearena.Persistance;
public interface IDataBase {
}
--Note: DDL to be run as admin on MsSQL (AzureDB);
DROP TABLE coremaps;
DROP TABLE communitymaps;
CREATE TABLE coremaps(
map_id CHAR(40) NOT NULL UNIQUE, --SHA1 hash is 40 chars length in hex
map_name VARCHAR(30) NOT NULL,
map_width INTEGER NOT NULL,
map_height INTEGER NOT NULL,
map_data VARCHAR(1682) NOT NULL); --allows for map size up to 29x29
CREATE TABLE communitymaps(
map_id CHAR(40) NOT NULL UNIQUE, --SHA1 hash is 40 chars length in hex
map_name VARCHAR(30) NOT NULL,
map_width INTEGER NOT NULL,
map_height INTEGER NOT NULL,
map_data VARCHAR(1682) NOT NULL); --allows for map size up to 29x29
INSERT INTO coremaps (map_id, map_name, map_width, map_height, map_data)
VALUES ('a593cafd1d061f0f463a2d2051bf4718aaaf5c48',
'Arena1',
18,
18,
'4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3');
INSERT INTO coremaps (map_id, map_name, map_width, map_height, map_data)
VALUES ('e559d8fbb53b333f5839cb3c6c0c515395afe344',
'Arena2',
18,
18,
'4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 3 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment