Merge, add HighscoreManager and DB Connection, add GuiControl for points

This commit is contained in:
TheCodeBoat 2013-06-21 10:28:50 +02:00
parent 62122dcb7e
commit b16b4b35b4
14 changed files with 345 additions and 47 deletions

Binary file not shown.

View File

@ -45,6 +45,7 @@ file.reference.jogg-0.0.7.jar=lib\\jogg-0.0.7.jar
file.reference.jorbis-0.0.15.jar=lib\\jorbis-0.0.15.jar file.reference.jorbis-0.0.15.jar=lib\\jorbis-0.0.15.jar
file.reference.mp3spi1.9.5.jar=lib\\mp3spi1.9.5.jar file.reference.mp3spi1.9.5.jar=lib\\mp3spi1.9.5.jar
file.reference.platform-3.5.2.jar=lib\\platform-3.5.2.jar file.reference.platform-3.5.2.jar=lib\\platform-3.5.2.jar
file.reference.sqlite-jdbc-3.7.2.jar=lib\\sqlite-jdbc-3.7.2.jar
file.reference.tritonus_aos-0.3.6.jar=lib\\tritonus_aos-0.3.6.jar file.reference.tritonus_aos-0.3.6.jar=lib\\tritonus_aos-0.3.6.jar
file.reference.tritonus_jorbis-0.3.6.jar=lib\\tritonus_jorbis-0.3.6.jar file.reference.tritonus_jorbis-0.3.6.jar=lib\\tritonus_jorbis-0.3.6.jar
file.reference.tritonus_share-0.3.6.jar=lib\\tritonus_share-0.3.6.jar file.reference.tritonus_share-0.3.6.jar=lib\\tritonus_share-0.3.6.jar
@ -85,7 +86,8 @@ javac.classpath=\
${file.reference.wget-1.2.7.jar}:\ ${file.reference.wget-1.2.7.jar}:\
${file.reference.xmlpull-1.1.3.1.jar}:\ ${file.reference.xmlpull-1.1.3.1.jar}:\
${file.reference.xpp3_min-1.1.4c.jar}:\ ${file.reference.xpp3_min-1.1.4c.jar}:\
${file.reference.xstream-1.4.2.jar} ${file.reference.xstream-1.4.2.jar}:\
${file.reference.sqlite-jdbc-3.7.2.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false

View File

@ -33,6 +33,9 @@ import org.wyrez.shootingstars.data.AudioDataManager;
import org.wyrez.shootingstars.data.YTDownloader; import org.wyrez.shootingstars.data.YTDownloader;
import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.factories.Materials;
import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.gui.manager.HighscoreManager;
import org.wyrez.shootingstars.gui.manager.ScoreComparator;
import org.wyrez.shootingstars.io.SQLiteConnector;
import org.wyrez.shootingstars.states.State; import org.wyrez.shootingstars.states.State;
import org.wyrez.shootingstars.states.StateManager; import org.wyrez.shootingstars.states.StateManager;
import org.wyrez.shootingstars.states.util.OptionSettings; import org.wyrez.shootingstars.states.util.OptionSettings;
@ -83,6 +86,9 @@ public class ShootingStars extends SimpleApplication {
container.registerSingleton(OptionSettings.class, optionSettings); container.registerSingleton(OptionSettings.class, optionSettings);
container.registerType(GameSettings.class, true); container.registerType(GameSettings.class, true);
container.registerType(StateManager.class, true); container.registerType(StateManager.class, true);
container.registerType(SQLiteConnector.class, true);
container.registerType(ScoreComparator.class, true);
container.registerType(HighscoreManager.class, true);
container.registerType(Screen.class, true); container.registerType(Screen.class, true);
container.registerType(AudioDataManager.class, true); container.registerType(AudioDataManager.class, true);
container.registerType(YTDownloader.class); container.registerType(YTDownloader.class);

View File

@ -16,6 +16,7 @@
*/ */
package org.wyrez.shootingstars.controls; package org.wyrez.shootingstars.controls;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control; import com.jme3.scene.control.Control;
import org.wyrez.shootingstars.helper.UserDataKeys; import org.wyrez.shootingstars.helper.UserDataKeys;
@ -27,19 +28,29 @@ import org.wyrez.shootingstars.helper.UserDataKeys;
public class StarPointControl extends BaseControl { public class StarPointControl extends BaseControl {
private int points = 100; //Todo Change StartPoint at Spawn private int points = 100; //Todo Change StartPoint at Spawn
private Spatial player;
public StarPointControl() { private ColorRGBA starColor;
public StarPointControl(Spatial player) {
this.player = player;
} }
@Override @Override
protected void controlUpdate(float tpf) { protected void controlUpdate(float tpf) {
if (spatial.getUserData(UserDataKeys.HITTED)) { if (spatial.getUserData(UserDataKeys.HITTED)) {
//Todo Check life time and set points int pointsToAdd = Integer.parseInt(player.getUserData(UserDataKeys.POINTS).toString()) + points;
player.setUserData(UserDataKeys.POINTS, pointsToAdd);
} else {
points -= tpf / 2;
if(points < 75) {
starColor = new ColorRGBA(0.5f, 0.5f, 0.5f, 1f);
//Todo Set color to spatial
}
} }
} }
public Control cloneForSpatial(Spatial spatial) { public Control cloneForSpatial(Spatial spatial) {
StarPointControl control = new StarPointControl(); StarPointControl control = new StarPointControl(player);
spatial.addControl(control); spatial.addControl(control);
return control; return control;
} }

View File

@ -25,6 +25,7 @@ import com.jme3.math.Vector2f;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.ui.Picture; import com.jme3.ui.Picture;
import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.controls.GuiPlayerPointsControl;
import org.wyrez.shootingstars.gui.controls.IndicatorBase; import org.wyrez.shootingstars.gui.controls.IndicatorBase;
import org.wyrez.shootingstars.gui.listener.GameListener; import org.wyrez.shootingstars.gui.listener.GameListener;
import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.buttons.Button;
@ -47,6 +48,8 @@ public class GameGUI extends Panel {
private Picture picCrosshair; private Picture picCrosshair;
private Indicator indOverheat; private Indicator indOverheat;
private AssetManager assetManager; private AssetManager assetManager;
private Spatial player;
private Label lblPoints;
public GameGUI(Screen screen, GameListener listener, AssetManager assetManager) { public GameGUI(Screen screen, GameListener listener, AssetManager assetManager) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
@ -68,6 +71,9 @@ public class GameGUI extends Panel {
float startPointOverheatx = 505f; float startPointOverheatx = 505f;
float startPointOverheaty = 270f; float startPointOverheaty = 270f;
float startPointPointsx = 1100f;
float startPointPointsy = 25f;
float startPointYMenu = 200f; float startPointYMenu = 200f;
btnStart = new ButtonBase(screen, new Vector2f(startPointx, startPointy), btnStart = new ButtonBase(screen, new Vector2f(startPointx, startPointy),
@ -112,21 +118,27 @@ public class GameGUI extends Panel {
indOverheat = new IndicatorBase(screen, new Vector2f(startPointOverheatx, startPointOverheaty), indOverheat = new IndicatorBase(screen, new Vector2f(startPointOverheatx, startPointOverheaty),
new Vector2f(275f, 180f), Indicator.Orientation.VERTICAL); new Vector2f(275f, 180f), Indicator.Orientation.VERTICAL);
indOverheat.setIndicatorColor(new ColorRGBA(0f, 0f, 1f, 0.5f)); //indOverheat.setIndicatorColor(new ColorRGBA(0f, 0f, 1f, 0.5f));
indOverheat.setAlphaMap("Textures/Crosshair_AlphaMap.png"); indOverheat.setAlphaMap("Textures/Crosshair_AlphaMap.png");
indOverheat.setOverlayImage("Textures/Crosshair_OverlayImage.png"); indOverheat.setOverlayImage("Textures/Crosshair_OverlayImage.png");
//indOverheat.setBaseImage("Textures/Crosshair_Overheat_Fog.png"); indOverheat.setIndicatorImage("Textures/Crosshair_Overheat_Fog.png");
lblPoints = new Label(screen, new Vector2f(startPointPointsx, startPointPointsy), new Vector2f(275f, 180f));
lblPoints.setFontColor(new ColorRGBA(1f, 0f, 0f, 1f));
lblPoints.setFontSize(50f);
this.addChild(btnStart); this.addChild(btnStart);
this.addChild(btnResume); this.addChild(btnResume);
this.addChild(btnMenu); this.addChild(btnMenu);
this.addChild(indOverheat); this.addChild(indOverheat);
this.addChild(plnCrosshair); this.addChild(plnCrosshair);
this.addChild(lblPoints);
btnResume.hide(); btnResume.hide();
btnMenu.hide(); btnMenu.hide();
picCrosshair.setCullHint(CullHint.Always); picCrosshair.setCullHint(CullHint.Always);
indOverheat.hide(); indOverheat.hide();
lblPoints.hide();
} }
public void setStart() { public void setStart() {
@ -135,6 +147,7 @@ public class GameGUI extends Panel {
btnMenu.hide(); btnMenu.hide();
picCrosshair.setCullHint(CullHint.Inherit); picCrosshair.setCullHint(CullHint.Inherit);
indOverheat.show(); indOverheat.show();
lblPoints.show();
} }
public void setWait() { public void setWait() {
@ -143,6 +156,7 @@ public class GameGUI extends Panel {
btnMenu.hide(); btnMenu.hide();
picCrosshair.setCullHint(CullHint.Always); picCrosshair.setCullHint(CullHint.Always);
indOverheat.hide(); indOverheat.hide();
lblPoints.hide();
} }
public void showMenu() { public void showMenu() {
@ -151,6 +165,7 @@ public class GameGUI extends Panel {
btnMenu.show(); btnMenu.show();
picCrosshair.setCullHint(CullHint.Always); picCrosshair.setCullHint(CullHint.Always);
indOverheat.hide(); indOverheat.hide();
lblPoints.hide();
} }
public void resumeGame() { public void resumeGame() {
@ -159,6 +174,7 @@ public class GameGUI extends Panel {
btnMenu.hide(); btnMenu.hide();
picCrosshair.setCullHint(CullHint.Inherit); picCrosshair.setCullHint(CullHint.Inherit);
indOverheat.show(); indOverheat.show();
lblPoints.show();
} }
public void attach() { public void attach() {
@ -172,8 +188,17 @@ public class GameGUI extends Panel {
public void updateOverhead(float percent) { public void updateOverhead(float percent) {
indOverheat.setCurrentValue(percent); indOverheat.setCurrentValue(percent);
} }
public void setPoints(String points) {
lblPoints.setText(points);
}
public void setMaxTimeToOverheat(float maxTimeToOverheat) { public void setMaxTimeToOverheat(float maxTimeToOverheat) {
indOverheat.setMaxValue(maxTimeToOverheat); indOverheat.setMaxValue(maxTimeToOverheat);
} }
public void setPlayer(Spatial player) {
this.player = player;
this.addControl(new GuiPlayerPointsControl(player, this));
}
} }

View File

@ -21,6 +21,7 @@ import com.jme3.math.Vector2f;
import java.util.List; import java.util.List;
import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.listener.HighscoreListener; import org.wyrez.shootingstars.gui.listener.HighscoreListener;
import org.wyrez.shootingstars.gui.manager.HighscoreManager;
import org.wyrez.shootingstars.gui.model.Score; import org.wyrez.shootingstars.gui.model.Score;
import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.text.Label; import tonegod.gui.controls.text.Label;
@ -34,14 +35,14 @@ import tonegod.gui.core.Screen;
public class HighscoreGUI extends Panel implements Gui { public class HighscoreGUI extends Panel implements Gui {
private HighscoreListener listener; private HighscoreListener listener;
//private HighscoreManager highscoreManager; private HighscoreManager highscoreManager;
public HighscoreGUI(Screen screen, HighscoreListener listener) { public HighscoreGUI(Screen screen, HighscoreListener listener, HighscoreManager highscoreManager) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f));
this.listener = listener; this.listener = listener;
this.setIgnoreMouse(true); this.setIgnoreMouse(true);
this.setIsVisible(false); this.setIsVisible(false);
//highscoreManager = new HighscoreManager(); this.highscoreManager = highscoreManager;
create(); create();
} }
@ -57,27 +58,13 @@ public class HighscoreGUI extends Panel implements Gui {
float startPointx = 32f; float startPointx = 32f;
float startPointy = 18f; float startPointy = 18f;
//Only Test
// highscoreManager.addScore("Lied Name", "Chris", 50);
// highscoreManager.addScore("Lied Name", "Chris", 150);
// highscoreManager.addScore("Lied Name", "Chris", 250);
// highscoreManager.addScore("Lied Name", "Chris", 350);
// highscoreManager.addScore("Lied Name", "Chris", 450);
// highscoreManager.addScore("Lied Name", "Chris", 550);
// highscoreManager.addScore("Lied Name", "Chris", 650);
// highscoreManager.addScore("Lied Name", "Chris", 750);
// highscoreManager.addScore("Lied Name", "Chris", 850);
// highscoreManager.addScore("Lied Name", "Chris", 950);
// highscoreManager.updateScoreFile();
float marginScoreNameLeft = 14f; float marginScoreNameLeft = 14f;
float marginScorePointsLeft = 300f; float marginScorePointsLeft = 300f;
float marginScoreSongNameLeft = 600f; float marginScoreSongNameLeft = 600f;
float marginScoreTop = 50f; float marginScoreTop = 50f;
//List<Score> highscores = highscoreManager.getScores(); List<Score> highscores = highscoreManager.getScores();
Label lblScoreNameHead = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy), new Vector2f(250f, 40f)); Label lblScoreNameHead = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy), new Vector2f(250f, 40f));
lblScoreNameHead.setText("Name"); lblScoreNameHead.setText("Name");
@ -88,22 +75,29 @@ public class HighscoreGUI extends Panel implements Gui {
Label lblScoreSongNameHead = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy), new Vector2f(600f, 40f)); Label lblScoreSongNameHead = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy), new Vector2f(600f, 40f));
lblScoreSongNameHead.setText("Song Name"); lblScoreSongNameHead.setText("Song Name");
// for (int i = 0; i < 10; i++) { int maxScores = 0;
// Score score = highscores.get(i); if(highscores.size() > 10) {
// Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f)); maxScores = 10;
// lblScoreName.setText(score.getPlayerName()); } else {
// maxScores = highscores.size();
// Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f)); }
// lblScorePoints.setText(String.valueOf(score.getScore()));
// for (int i = 0; i < maxScores; i++) {
// Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(600f, 40f)); Score score = highscores.get(i);
// lblScoreSongName.setText(score.getSongName()); Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f));
// lblScoreName.setText(score.getPlayerName());
// this.addChild(lblScoreName);
// this.addChild(lblScorePoints); Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f));
// this.addChild(lblScoreSongName); lblScorePoints.setText(String.valueOf(score.getScore()));
// marginScoreTop += 50f;
// } Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(600f, 40f));
lblScoreSongName.setText(score.getSongName());
this.addChild(lblScoreName);
this.addChild(lblScorePoints);
this.addChild(lblScoreSongName);
marginScoreTop += 50f;
}
Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + 1060f, startPointy + 622.8f), new Vector2f(153f, 40)) { Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + 1060f, startPointy + 622.8f), new Vector2f(153f, 40)) {
@Override @Override

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2013 Snowsun <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.controls;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
import org.wyrez.shootingstars.controls.BaseControl;
import org.wyrez.shootingstars.gui.GameGUI;
import org.wyrez.shootingstars.helper.UserDataKeys;
/**
*
* @author Snowsun
*/
public class GuiPlayerPointsControl extends BaseControl {
private Spatial player;
private GameGUI gui;
public GuiPlayerPointsControl(Spatial player, GameGUI gui) {
this.player = player;
this.gui = gui;
}
@Override
protected void controlUpdate(float tpf) {
if(player.getUserData(UserDataKeys.POINTS) != null) {
gui.setPoints(player.getUserData(UserDataKeys.POINTS).toString());
}
}
public Control cloneForSpatial(Spatial spatial) {
GuiPlayerPointsControl control = new GuiPlayerPointsControl(player, gui);
spatial.addControl(control);
return control;
}
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (C) 2013 Rappold <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.manager;
/**
*
* @author Rappold
*/
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.*;
import org.wyrez.shootingstars.gui.model.Score;
import org.wyrez.shootingstars.io.SQLiteConnector;
public class HighscoreManager {
private List<Score> scores;
private Connection connection;
private SQLiteConnector connector;
private ScoreComparator scoreComparator;
public HighscoreManager(SQLiteConnector connector, ScoreComparator scoreComparator) {
this.connector = connector;
this.scoreComparator = scoreComparator;
connection = connector.initDBConnection();
scores = new ArrayList<Score>();
loadScoreFile();
}
public List<Score> getScores() {
sort();
return scores;
}
private void sort() {
Collections.sort(scores, scoreComparator);
}
public void addScore(String songName, String name, int score) {
scores.add(new Score(songName, name, score));
updateScoreFile(name, score, songName);
}
private void loadScoreFile() {
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")));
}
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void updateScoreFile(String name, int score, String songName) {
try {
connector.excecuteUpdate(connection, "INSERT INTO Scores(Name,Points,SongName) values('" + name + "'," + score + ", '" + songName + "')");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2013 Rappold <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.manager;
/**
*
* @author Rappold
*/
import java.util.Comparator;
import org.wyrez.shootingstars.gui.model.Score;
public class ScoreComparator implements Comparator<Score> {
public int compare(Score score1, Score score2) {
int sc1 = score1.getScore();
int sc2 = score2.getScore();
if (sc1 > sc2){
return -1;
}else if (sc1 < sc2){
return +1;
}else{
return 0;
}
}
}

View File

@ -32,9 +32,11 @@ public class DisplayHelper {
List<String> resolutions = new ArrayList<String>(); List<String> resolutions = new ArrayList<String>();
for (DisplayMode mode : GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayModes()) { for (DisplayMode mode : GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayModes()) {
String resolution = mode.getWidth() + " x " + mode.getHeight(); if (mode.getWidth() >= 1024) {
if (!resolutions.contains(resolution)) { String resolution = mode.getWidth() + " x " + mode.getHeight();
resolutions.add(resolution); if (!resolutions.contains(resolution)) {
resolutions.add(resolution);
}
} }
} }
Collections.sort(resolutions); Collections.sort(resolutions);
@ -43,7 +45,7 @@ public class DisplayHelper {
public static List<String> getFrequencys() { public static List<String> getFrequencys() {
List<String> frequencys = new ArrayList<String>(); List<String> frequencys = new ArrayList<String>();
for (DisplayMode mode : GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayModes()) { for (DisplayMode mode : GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayModes()) {
if (!frequencys.contains(String.valueOf(mode.getRefreshRate()))) { if (!frequencys.contains(String.valueOf(mode.getRefreshRate()))) {
frequencys.add(String.valueOf(mode.getRefreshRate())); frequencys.add(String.valueOf(mode.getRefreshRate()));

View File

@ -25,4 +25,5 @@ public class UserDataKeys {
public static final String HITTED = "isHitted"; public static final String HITTED = "isHitted";
public static final String SHOOTING = "isShooting"; public static final String SHOOTING = "isShooting";
public static final String RUNNING = "isRunning"; public static final String RUNNING = "isRunning";
public static final String POINTS = "points";
} }

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2013 Rappold <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.io;
/**
*
* @author Rappold
*/
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class SQLiteConnector {
private static final String DB_PATH = "scoresdb.db";
public SQLiteConnector() {
}
public Connection initDBConnection() {
Connection connection = null;
boolean newFile = false;
try {
Class.forName("org.sqlite.JDBC");
String sqliteTable = "CREATE TABLE Scores (Name VARCHAR(250), Points INT(20), SongName VARCHAR(250))";
File sQLiteDb = new File(DB_PATH);
if (!sQLiteDb.exists()) {
sQLiteDb.createNewFile();
newFile = true;
}
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
if(newFile) {
Statement stmt = connection.createStatement();
stmt.executeUpdate(sqliteTable);
}
return connection;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public ResultSet excecuteQuery(Connection con, String query) {
ResultSet result = null;
try {
Statement stmt = con.createStatement();
result = stmt.executeQuery(query);
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
public int excecuteUpdate(Connection con, String query) {
int result = 0;
try {
Statement stmt = con.createStatement();
result = stmt.executeUpdate(query);
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
}

View File

@ -116,6 +116,8 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
player.addControl(new PlayerMoveControl(audioDataManager)); player.addControl(new PlayerMoveControl(audioDataManager));
player.addControl(new PlayerShootControl(inputManager, gui)); player.addControl(new PlayerShootControl(inputManager, gui));
player.addControl(new PlayerCamControl(camera)); player.addControl(new PlayerCamControl(camera));
gui.setPlayer(player);
} }
private void setRunning(boolean running) { private void setRunning(boolean running) {

View File

@ -21,6 +21,7 @@ import com.jme3.app.state.AppStateManager;
import org.wyrez.shootingstars.gui.Gui; import org.wyrez.shootingstars.gui.Gui;
import org.wyrez.shootingstars.gui.HighscoreGUI; import org.wyrez.shootingstars.gui.HighscoreGUI;
import org.wyrez.shootingstars.gui.listener.HighscoreListener; import org.wyrez.shootingstars.gui.listener.HighscoreListener;
import org.wyrez.shootingstars.gui.manager.HighscoreManager;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
/** /**
@ -30,11 +31,13 @@ import tonegod.gui.core.Screen;
public class HighscoreState extends AbstractAppState implements HighscoreListener{ public class HighscoreState extends AbstractAppState implements HighscoreListener{
private StateManager stateManager; private StateManager stateManager;
private HighscoreManager highscoreManager;
private Gui gui; private Gui gui;
public HighscoreState(Screen screen, StateManager stateManager) { public HighscoreState(Screen screen, StateManager stateManager, HighscoreManager highscoreManager) {
this.stateManager = stateManager; this.stateManager = stateManager;
this.gui = new HighscoreGUI(screen, this); this.highscoreManager = highscoreManager;
this.gui = new HighscoreGUI(screen, this, highscoreManager);
} }
public void back() { public void back() {