add date to db
This commit is contained in:
parent
62f67b9aac
commit
713c717b47
@ -18,6 +18,7 @@ package org.wyrez.shootingstars.gui;
|
||||
|
||||
import com.jme3.input.event.MouseButtonEvent;
|
||||
import com.jme3.math.Vector2f;
|
||||
import java.text.DateFormat;
|
||||
import java.util.List;
|
||||
import org.wyrez.shootingstars.gui.controls.ButtonBase;
|
||||
import org.wyrez.shootingstars.gui.listener.HighscoreListener;
|
||||
@ -67,6 +68,7 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
|
||||
float marginScoreNameLeft = screenHelper.calcX(14f);
|
||||
float marginScorePointsLeft = screenHelper.calcX(300f);
|
||||
float marginScoreDateLeft = screenHelper.calcX(420f);
|
||||
float marginScoreSongNameLeft = screenHelper.calcX(600f);
|
||||
|
||||
float labelFontSize = screenHelper.calcX(20f);
|
||||
@ -81,9 +83,13 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
lblScoreNameHead.setText("Name");
|
||||
lblScoreNameHead.setFontSize(labelFontSize);
|
||||
|
||||
Label lblScorePointsHead = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f)));
|
||||
Label lblScorePointsHead = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy), new Vector2f(screenHelper.calcX(120f), screenHelper.calcY(40f)));
|
||||
lblScorePointsHead.setText("Points");
|
||||
lblScorePointsHead.setFontSize(labelFontSize);
|
||||
|
||||
Label lblScoreDateHead = new Label(screen, new Vector2f(startPointx + marginScoreDateLeft, startPointy), new Vector2f(screenHelper.calcX(180f), screenHelper.calcY(40f)));
|
||||
lblScoreDateHead.setText("Date");
|
||||
lblScoreDateHead.setFontSize(labelFontSize);
|
||||
|
||||
Label lblScoreSongNameHead = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f)));
|
||||
lblScoreSongNameHead.setText("Song Name");
|
||||
@ -114,6 +120,7 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
|
||||
this.addChild(lblScoreNameHead);
|
||||
this.addChild(lblScorePointsHead);
|
||||
this.addChild(lblScoreDateHead);
|
||||
this.addChild(lblScoreSongNameHead);
|
||||
this.addChild(plnScores);
|
||||
this.addChild(txtFilter);
|
||||
@ -134,6 +141,7 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
|
||||
float marginScoreNameLeft = screenHelper.calcX(14f);
|
||||
float marginScorePointsLeft = screenHelper.calcX(300f);
|
||||
float marginScoreDateLeft = screenHelper.calcX(420f);
|
||||
float marginScoreSongNameLeft = screenHelper.calcX(600f);
|
||||
|
||||
float marginScoreTop = screenHelper.calcY(50f);
|
||||
@ -153,9 +161,13 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
lblScoreName.setText(score.getPlayerName());
|
||||
lblScoreName.setFontSize(labelFontSize);
|
||||
|
||||
Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f)));
|
||||
Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(120f), screenHelper.calcY(40f)));
|
||||
lblScorePoints.setText(String.valueOf(score.getScore()));
|
||||
lblScorePoints.setFontSize(labelFontSize);
|
||||
|
||||
Label lblScoreDate = new Label(screen, new Vector2f(startPointx + marginScoreDateLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(180f), screenHelper.calcY(40f)));
|
||||
lblScoreDate.setText(DateFormat.getDateTimeInstance().format(score.getDate()));
|
||||
lblScoreDate.setFontSize(labelFontSize);
|
||||
|
||||
Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f)));
|
||||
lblScoreSongName.setText(score.getSongName());
|
||||
@ -163,6 +175,7 @@ public class HighscoreGUI extends Panel implements Gui {
|
||||
|
||||
plnScores.addChild(lblScoreName);
|
||||
plnScores.addChild(lblScorePoints);
|
||||
plnScores.addChild(lblScoreDate);
|
||||
plnScores.addChild(lblScoreSongName);
|
||||
marginScoreTop += screenHelper.calcY(50f);
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ package org.wyrez.shootingstars.gui.manager;
|
||||
*/
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
import org.wyrez.shootingstars.game.GameSettings;
|
||||
import org.wyrez.shootingstars.gui.model.Score;
|
||||
@ -54,8 +55,9 @@ public class HighscoreManager {
|
||||
|
||||
public void addScore(GameSettings gameSettings, OptionSettings optionSettings, int score) {
|
||||
String songName = gameSettings.getTrackArtist() + " ~ " + gameSettings.getTrackTitle();
|
||||
scores.add(new Score(songName, optionSettings.getUsername(), score));
|
||||
updateScoreFile(optionSettings.getUsername(), score, songName);
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
scores.add(new Score(songName, optionSettings.getUsername(), score, date));
|
||||
updateScoreFile(optionSettings.getUsername(), score, songName, date);
|
||||
}
|
||||
|
||||
public List<Score> getScoresWithSongName(String songName) {
|
||||
@ -64,7 +66,7 @@ public class HighscoreManager {
|
||||
try {
|
||||
ResultSet rs = connector.excecuteQuery(connection, "SELECT * FROM Scores WHERE LOWER(SongName) LIKE LOWER('%" + songName + "%');");
|
||||
while (rs.next()) {
|
||||
tempScores.add(new Score(rs.getString("SongName"), rs.getString("Name"), rs.getInt("Points")));
|
||||
tempScores.add(new Score(rs.getString("SongName"), rs.getString("Name"), rs.getInt("Points"), rs.getDate("Date")));
|
||||
}
|
||||
rs.close();
|
||||
} catch (Exception ex) {
|
||||
@ -78,7 +80,7 @@ public class HighscoreManager {
|
||||
try {
|
||||
ResultSet rs = connector.excecuteQuery(connection, "SELECT * FROM Scores;");
|
||||
while (rs.next()) {
|
||||
scores.add(new Score(rs.getString("SongName"), rs.getString("Name"), rs.getInt("Points")));
|
||||
scores.add(new Score(rs.getString("SongName"), rs.getString("Name"), rs.getInt("Points"), rs.getDate("Date")));
|
||||
}
|
||||
rs.close();
|
||||
} catch (Exception ex) {
|
||||
@ -86,9 +88,9 @@ public class HighscoreManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateScoreFile(String name, int score, String songName) {
|
||||
private void updateScoreFile(String name, int score, String songName, Date date) {
|
||||
try {
|
||||
connector.excecuteUpdate(connection, "INSERT INTO Scores(Name,Points,SongName) values('" + name + "'," + score + ", '" + songName + "')");
|
||||
connector.excecuteUpdate(connection, "INSERT INTO Scores(Name,Points,SongName,Date) values('" + name + "'," + score + ", '" + songName + "', '" + DateFormat.getDateTimeInstance().format(date) +"' )");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@ -21,11 +21,13 @@ package org.wyrez.shootingstars.gui.model;
|
||||
* @author Rappold
|
||||
*/
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class Score implements Serializable {
|
||||
private int score;
|
||||
private String playerName;
|
||||
private String songName;
|
||||
private Date date;
|
||||
|
||||
public void setSongName(String songName) {
|
||||
this.songName = songName;
|
||||
@ -39,6 +41,10 @@ public class Score implements Serializable {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
@ -51,9 +57,14 @@ public class Score implements Serializable {
|
||||
return score;
|
||||
}
|
||||
|
||||
public Score(String songName, String playerName, int score) {
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public Score(String songName, String playerName, int score, Date date) {
|
||||
this.songName = songName;
|
||||
this.score = score;
|
||||
this.playerName = playerName;
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,7 @@ public class SQLiteConnector {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
|
||||
String sqliteTable = "CREATE TABLE Scores (Name VARCHAR(250), Points INT(20), SongName VARCHAR(250))";
|
||||
String sqliteTable = "CREATE TABLE Scores (Name VARCHAR(250), Points INT(20), SongName VARCHAR(250), Date datetime)";
|
||||
File sQLiteDb = new File(DB_PATH);
|
||||
if (!sQLiteDb.exists()) {
|
||||
sQLiteDb.createNewFile();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user