Merge pull request #16 from ProjectGroepA2/feature/database
Feature/database
This commit is contained in:
+5
-5
@@ -4,14 +4,9 @@ import image.Images;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
public class Song implements Comparable<Song>{
|
||||
|
||||
private String title;
|
||||
@@ -139,6 +134,11 @@ public class Song implements Comparable<Song>{
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getFolder()
|
||||
{
|
||||
return file.getParentFile().getName();
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,6 @@ package control;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import model.gameState.PlayState;
|
||||
import model.gameState.TitleState;
|
||||
import control.button.Button;
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.JoystickHandler;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class GameStateManager {
|
||||
|
||||
@@ -27,12 +29,12 @@ public class GameStateManager {
|
||||
GAMEOVER_STATE
|
||||
}
|
||||
|
||||
public GameStateManager(SongHandler sh){
|
||||
public GameStateManager(SongHandler sh, SQLConnector sql){
|
||||
gamestates = new ArrayList<GameState>();
|
||||
gamestates.add(new TitleState(this, sh));
|
||||
gamestates.add(new MenuState(this, sh));
|
||||
gamestates.add(new PlayState(this, sh));
|
||||
gamestates.add(new GameOverState(this, sh));
|
||||
gamestates.add(new TitleState(this, sh, sql));
|
||||
gamestates.add(new MenuState(this, sh, sql));
|
||||
gamestates.add(new PlayState(this, sh, sql));
|
||||
gamestates.add(new GameOverState(this, sh, sql));
|
||||
setState(State.TITLE_STATE);
|
||||
}
|
||||
|
||||
@@ -56,6 +58,7 @@ public class GameStateManager {
|
||||
|
||||
public void init()
|
||||
{
|
||||
JoystickHandler.REPEAT = false;
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
Button b = ButtonHandler.getButton(i);
|
||||
b.setColor(Color.BLACK);
|
||||
|
||||
@@ -3,9 +3,7 @@ package control;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.Joystick.Position;
|
||||
|
||||
@@ -7,8 +7,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import main.Window;
|
||||
|
||||
import com.pi4j.io.gpio.GpioController;
|
||||
import com.pi4j.io.gpio.GpioFactory;
|
||||
import com.pi4j.io.gpio.GpioPinDigitalInput;
|
||||
@@ -23,6 +21,7 @@ public class JoystickHandler implements KeyListener{
|
||||
|
||||
List<JoystickListener> listeners;
|
||||
Set<Integer> keys;
|
||||
public static boolean REPEAT = false;
|
||||
public static Joystick j = new Joystick();;
|
||||
|
||||
public JoystickHandler()
|
||||
@@ -157,7 +156,7 @@ public class JoystickHandler implements KeyListener{
|
||||
keys.add(e.getKeyCode());
|
||||
updateJoystickPosition();
|
||||
|
||||
if(!keys.equals(keysCopy))
|
||||
if(REPEAT || !keys.equals(keysCopy) )
|
||||
{
|
||||
onJoystickMoved(j);
|
||||
}
|
||||
@@ -173,7 +172,7 @@ public class JoystickHandler implements KeyListener{
|
||||
keys.remove(e.getKeyCode());
|
||||
updateJoystickPosition();
|
||||
|
||||
if(!keys.equals(keysCopy))
|
||||
if(REPEAT || !keys.equals(keysCopy))
|
||||
{
|
||||
onJoystickMoved(j);
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/SQLConnector.class
|
||||
@@ -0,0 +1,238 @@
|
||||
package data.io;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import model.objects.highscore.Highscore;
|
||||
import audio.Song;
|
||||
import audio.SongInstance;
|
||||
|
||||
public class SQLConnector
|
||||
{
|
||||
|
||||
private Connection myConn = null;
|
||||
|
||||
public SQLConnector()
|
||||
{
|
||||
this("178.62.254.153", "3306","colorstrike","csadmin","aardbei123");
|
||||
}
|
||||
|
||||
//Start connection with Databse
|
||||
public SQLConnector(String host, String port, String dbName, String userName, String password)
|
||||
{
|
||||
try
|
||||
{
|
||||
String url = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?user="
|
||||
+ userName
|
||||
+ "&password="
|
||||
+ password;
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||
myConn = DriverManager.getConnection(url);
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
System.out.println("Error : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public List<Highscore> getHighscores(Song s, SongInstance si)
|
||||
{
|
||||
String query = "SELECT * FROM highscore WHERE songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC";
|
||||
//System.out.println(query);
|
||||
Statement st = executeResultQuery(query);
|
||||
ResultSet result = null;
|
||||
List<Highscore> hsc = new ArrayList<Highscore>();
|
||||
try {
|
||||
result = st.getResultSet();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
while(result.next())
|
||||
{
|
||||
hsc.add(new Highscore(si, result.getString("username"), result.getInt("score"), result.getDate("date").getTime()));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return hsc;
|
||||
}
|
||||
|
||||
public List<Highscore> getHighscoresToday(Song s, SongInstance si)
|
||||
{
|
||||
Statement st = executeResultQuery("SELECT * FROM highscore WHERE date=CURDATE() AND songinstance = (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')) ORDER BY score DESC");
|
||||
ResultSet result = null;
|
||||
List<Highscore> hsc = new ArrayList<Highscore>();
|
||||
try {
|
||||
result = st.getResultSet();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
while(result.next())
|
||||
{
|
||||
hsc.add(new Highscore(si, result.getString("username"), result.getInt("score"), result.getDate("date").getTime()));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return hsc;
|
||||
}
|
||||
|
||||
public int addHighscore(Song s, SongInstance si, String name, int currentScore) {
|
||||
if(name.length() <= 5 && currentScore <= Integer.MAX_VALUE)
|
||||
{
|
||||
String query = "INSERT INTO highscore (username, score, date, songinstance) VALUES ('" + name.trim() + "', " + currentScore + ", CURDATE(), (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')))";
|
||||
//System.out.println(query);
|
||||
return executeInsertQuery(query);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void addPlaydata(Song s, SongInstance si, long time, int enemies_missed, int enemies_hit, int buttons_pressed, int joystick_moved) {
|
||||
System.out.println("Inserting PlayData: " + time + ", " + enemies_missed + ", " + enemies_hit + ", " + buttons_pressed + ", " + joystick_moved);
|
||||
String query = "INSERT INTO playdata (enemies_missed, enemies_hit, buttons_pressed, joystick_moved, start_time, play_time, songinstance) VALUES (" + enemies_missed + ", " + enemies_hit + ", " + buttons_pressed + ", " + joystick_moved + ", NOW(), " + time + ", (SELECT id FROM songinstance WHERE difficulty='" + si.getDifficulty() + "' AND song=(SELECT id FROM song WHERE folder='" + s.getFolder() + "')))";
|
||||
//System.out.println(query);
|
||||
executeInsertQuery(query);
|
||||
|
||||
}
|
||||
|
||||
public void update(List<Song> songs)
|
||||
{
|
||||
for(Song s : songs)
|
||||
{
|
||||
executeInsertQuery("INSERT INTO song (folder, title, author) VALUES ('" + s.getFolder() + "', '" + s.getTitle() + "', '" + s.getAuthor() + "');");
|
||||
|
||||
Statement st = executeResultQuery("SELECT id FROM song WHERE folder='" + s.getFolder() + "'");
|
||||
|
||||
ResultSet rs = null;
|
||||
int id = -1;
|
||||
|
||||
try {
|
||||
rs = st.getResultSet();
|
||||
rs.next();
|
||||
id = rs.getInt(1);
|
||||
//System.out.println("Song " + id + " added to database");
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(id != -1)
|
||||
{
|
||||
for(SongInstance si : s.getSongs())
|
||||
{
|
||||
Statement st2 = executeResultQuery("SELECT id FROM songinstance WHERE song=" + id + " AND difficulty='" + si.getDifficulty() + "'");
|
||||
|
||||
ResultSet rs2 = null;
|
||||
|
||||
try {
|
||||
rs2 = st2.getResultSet();
|
||||
if(rs2.first())
|
||||
{
|
||||
//System.err.println("SongInstance Already Exists ");
|
||||
}
|
||||
else
|
||||
{
|
||||
executeInsertQuery("INSERT INTO songinstance (song, enemies, difficulty) VALUES (" + id + ", " + si.getObjects().size() + ", '" + si.getDifficulty() + "');");
|
||||
//System.out.println("Songinstance Added");
|
||||
}
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//System.err.println("Insert Failed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private int executeInsertQuery(String query)
|
||||
{
|
||||
try{
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
|
||||
ResultSet rs = s.getGeneratedKeys();
|
||||
int id = 0;
|
||||
if(rs.next())
|
||||
{
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
s.close();
|
||||
return id;
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Execute a custom query
|
||||
private Statement executeResultQuery(String query)
|
||||
{
|
||||
Statement s = null;
|
||||
|
||||
try{
|
||||
s = myConn.createStatement();
|
||||
s.executeQuery(query);
|
||||
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
//Close connection with Database
|
||||
@Override
|
||||
public void finalize() throws Throwable
|
||||
{
|
||||
// Close database connection
|
||||
if( myConn != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
myConn.close();
|
||||
System.out.println("Database connection terminated");
|
||||
}
|
||||
catch( Exception e ) {}
|
||||
}
|
||||
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package data.io;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
public class WebcamUploader {
|
||||
public static void takePictureAndUpload(int id) throws IOException{
|
||||
Runtime.getRuntime().exec("streamer -c /dev/video0 -b 16 -o" + System.getProperty( "user.home" ) + "/ColorStrike/picture.jpeg");
|
||||
|
||||
HttpURLConnection httpUrlConnection = (HttpURLConnection)new URL("http://178.62.254.153/colorstrike/images/photoupload.php?filename="+id+".jpeg").openConnection();
|
||||
httpUrlConnection.setDoOutput(true);
|
||||
httpUrlConnection.setRequestMethod("POST");
|
||||
OutputStream os = httpUrlConnection.getOutputStream();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(System.getProperty( "user.home" ) +"/ColorStrike/picture.jpeg");
|
||||
|
||||
byte[] buffer = new byte[2048];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fis.read(buffer)) != -1)
|
||||
{
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
os.close();
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
httpUrlConnection.getInputStream()));
|
||||
|
||||
String s = null;
|
||||
while ((s = in.readLine()) != null) {
|
||||
System.out.println(s);
|
||||
}
|
||||
in.close();
|
||||
fis.close();
|
||||
}
|
||||
|
||||
public static BufferedImage createQRImage(String qrCodeText, int size) throws WriterException, IOException {
|
||||
// Create the ByteMatrix for the QR-Code that encodes the given String
|
||||
Hashtable hintMap = new Hashtable();
|
||||
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText,
|
||||
BarcodeFormat.QR_CODE, size, size, hintMap);
|
||||
// Make the BufferedImage that are to hold the QRCode
|
||||
int matrixWidth = byteMatrix.getWidth();
|
||||
BufferedImage image = new BufferedImage(matrixWidth, matrixWidth,
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
image.createGraphics();
|
||||
|
||||
Graphics2D graphics = (Graphics2D) image.getGraphics();
|
||||
graphics.setColor(Color.WHITE);
|
||||
graphics.fillRect(0, 0, matrixWidth, matrixWidth);
|
||||
// Paint and save the image using the ByteMatrix
|
||||
graphics.setColor(Color.BLACK);
|
||||
|
||||
for (int i = 0; i < matrixWidth; i++) {
|
||||
for (int j = 0; j < matrixWidth; j++) {
|
||||
if (byteMatrix.get(i, j)) {
|
||||
graphics.fillRect(i, j, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
+11
-7
@@ -17,10 +17,10 @@ import model.SongHandler;
|
||||
import view.GameView;
|
||||
import control.GameControl;
|
||||
import control.GameStateManager;
|
||||
import control.LedHandler;
|
||||
import control.NetworkHandler;
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.JoystickHandler;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class Window extends JFrame {
|
||||
private static final long serialVersionUID = -9222956702898533696L;
|
||||
@@ -37,9 +37,7 @@ public class Window extends JFrame {
|
||||
|
||||
//Create Events
|
||||
Window.ON_RASP = ON_RASP;
|
||||
LedHandler led = null;
|
||||
if(ON_RASP){ //Only on the raspberry pi
|
||||
led = new LedHandler();
|
||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
||||
|
||||
@@ -57,15 +55,16 @@ public class Window extends JFrame {
|
||||
ButtonHandler bth = new ButtonHandler();
|
||||
JoystickHandler jsh = new JoystickHandler();
|
||||
|
||||
final SQLConnector sql = new SQLConnector();
|
||||
NetworkHandler ntw = new NetworkHandler("192.168.1.6", 1113, bth, jsh);
|
||||
|
||||
bth.setNetwork(ntw);
|
||||
|
||||
//Create Instances
|
||||
final SongHandler sh = new SongHandler();
|
||||
GameStateManager gsm = new GameStateManager(sh);
|
||||
GameView view = new GameView(led,gsm);
|
||||
GameModel model = new GameModel(sh, gsm, led);
|
||||
final SongHandler sh = new SongHandler(sql);
|
||||
GameStateManager gsm = new GameStateManager(sh, sql);
|
||||
GameView view = new GameView(gsm);
|
||||
GameModel model = new GameModel(sh, gsm, ntw);
|
||||
GameControl control = new GameControl(model, view,gsm);
|
||||
setContentPane(view);
|
||||
|
||||
@@ -74,6 +73,11 @@ public class Window extends JFrame {
|
||||
addWindowListener(new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e) {
|
||||
sh.close();
|
||||
try {
|
||||
sql.finalize();
|
||||
} catch (Throwable e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,19 +4,19 @@ import java.awt.Color;
|
||||
|
||||
import main.Window;
|
||||
import control.GameStateManager;
|
||||
import control.LedHandler;
|
||||
import control.NetworkHandler;
|
||||
import control.button.ButtonHandler;
|
||||
|
||||
public class GameModel {
|
||||
|
||||
public static Color[] colors = { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.CYAN, Color.ORANGE };
|
||||
private GameStateManager gsm;
|
||||
private LedHandler led;
|
||||
private NetworkHandler ntw;
|
||||
private int count = 0;
|
||||
|
||||
public GameModel(SongHandler sh, GameStateManager gsm, LedHandler led) {
|
||||
public GameModel(SongHandler sh, GameStateManager gsm, NetworkHandler ntw) {
|
||||
this.gsm = gsm;
|
||||
this.led = led;
|
||||
this.ntw = ntw;
|
||||
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
ButtonHandler.getButtons().get(i).setColor(colors[i - 1]);
|
||||
@@ -34,9 +34,9 @@ public class GameModel {
|
||||
if(count>15)
|
||||
{
|
||||
for (int i = 7; i < 54; i++) {
|
||||
led.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
|
||||
ntw.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
|
||||
}
|
||||
led.show();
|
||||
ntw.show();
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import audio.Song;
|
||||
import audio.SongInstance;
|
||||
import audio.io.DirScanner;
|
||||
import audio.sorting.SortALPHA;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class SongHandler {
|
||||
|
||||
@@ -20,18 +21,21 @@ public class SongHandler {
|
||||
private Song currentSong;
|
||||
private SongInstance currentSongInstance;
|
||||
private int currentIndex;
|
||||
SQLConnector sql;
|
||||
|
||||
private File dir;
|
||||
|
||||
private AudioPlayer p;
|
||||
|
||||
public SongHandler()
|
||||
public SongHandler(SQLConnector sql)
|
||||
{
|
||||
this.sql = sql;
|
||||
|
||||
songs = new ArrayList<Song>();
|
||||
|
||||
currentSong = null;
|
||||
currentSongInstance = null;
|
||||
currentIndex = 1;
|
||||
currentIndex = 0;
|
||||
|
||||
p = new AudioPlayer();
|
||||
|
||||
@@ -42,7 +46,9 @@ public class SongHandler {
|
||||
|
||||
songs = DirScanner.scanDirectories(dir);
|
||||
|
||||
Collections.sort(songs, new SortALPHA());
|
||||
sort(new SortALPHA());
|
||||
|
||||
sql.update(songs);
|
||||
|
||||
updatePlayer();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package model.gameState;
|
||||
|
||||
import image.Images;
|
||||
import image.Images.ImageType;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
@@ -10,45 +9,134 @@ import java.awt.RenderingHints;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.awt.image.WritableRenderedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.google.zxing.WriterException;
|
||||
|
||||
import model.GameModel;
|
||||
import model.SongHandler;
|
||||
import model.objects.InfoPanel;
|
||||
import model.objects.highscore.HighscoreName;
|
||||
import net.glxn.qrgen.QRCode;
|
||||
import net.glxn.qrgen.image.ImageType;
|
||||
import control.GameStateManager;
|
||||
import control.GameStateManager.State;
|
||||
import control.button.ButtonEvent;
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.JoystickEvent;
|
||||
import control.joystick.JoystickHandler;
|
||||
import data.io.SQLConnector;
|
||||
import data.io.WebcamUploader;
|
||||
|
||||
public class GameOverState extends GameState {
|
||||
|
||||
BufferedImage gameOver = Images.getImage(ImageType.gameover);
|
||||
BufferedImage gameOver = Images.getImage(Images.ImageType.gameover);
|
||||
VolatileImage background;
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 70);
|
||||
|
||||
|
||||
private String endScore = "";
|
||||
HighscoreName hsn;
|
||||
int image_x = 0;
|
||||
private boolean uploaded;
|
||||
private BufferedImage QRimage;
|
||||
|
||||
int frame;
|
||||
|
||||
public GameOverState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
createBackground();
|
||||
public GameOverState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
super(gsm, sh, sql);
|
||||
hsn = new HighscoreName(640,717,5,textFont);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
createBackground();
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
JoystickHandler.REPEAT = true;
|
||||
uploaded = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float factor) {
|
||||
|
||||
image_x = ((frame / 5) % 5) * 40;
|
||||
frame++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
g2.drawImage(background, 0, 0, 1280, 1024, null);
|
||||
int image_x = ((frame / 5) % 5) * 40;
|
||||
g2.drawImage(gameOver.getSubimage(image_x, 0, 40, 26), 640-122, 512, 245, 130, null);
|
||||
g2.drawImage(gameOver.getSubimage(image_x, 0, 40, 26), 640-122, 400, 245, 130, null);
|
||||
if(!uploaded)
|
||||
hsn.drawName(g2);
|
||||
else if(QRimage != null){
|
||||
g2.drawImage(QRimage, 400, 600, 400, 400, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
//System.out.println("Name: "+hsn.getName());
|
||||
switch(e.getButton().getButtonID()){
|
||||
case 1:
|
||||
if(hsn.getName().trim().length() >= 3)
|
||||
{
|
||||
if(!uploaded){
|
||||
int id = sql.addHighscore(sh.getCurrentSong(), sh.getCurrentSongInstance(), hsn.getName(), PlayState.currentScore);
|
||||
try {
|
||||
WebcamUploader.takePictureAndUpload(id);
|
||||
} catch (IOException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
QRimage = WebcamUploader.createQRImage("http://portfolio.jancokock.me/colorstrike/message.php?id="+id, 400);
|
||||
} catch (WriterException | IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
uploaded = true;
|
||||
|
||||
System.out.println(id);
|
||||
}else{
|
||||
gsm.setState(State.MENU_STATE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
gsm.setState(State.MENU_STATE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public void buttonReleased(ButtonEvent e) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoystickMoved(JoystickEvent e) {
|
||||
switch(e.getJoystick().getPos()){
|
||||
case DOWN:
|
||||
hsn.down();
|
||||
break;
|
||||
case LEFT:
|
||||
hsn.left();
|
||||
break;
|
||||
case RIGHT:
|
||||
hsn.right();
|
||||
break;
|
||||
case UP:
|
||||
hsn.up();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void createBackground(){
|
||||
background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
||||
Graphics2D g2 = background.createGraphics();
|
||||
|
||||
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHints(rh);
|
||||
@@ -69,33 +157,9 @@ public class GameOverState extends GameState {
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setFont(textFont);
|
||||
|
||||
g2.drawString("High Score", 385, 212);
|
||||
g2.drawString(InfoPanel.getTotalHighscore(), 390, 342);
|
||||
g2.drawString(InfoPanel.getTotalHighscore() + "", 390, 342);
|
||||
g2.dispose();
|
||||
background.createGraphics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonPressed(ButtonEvent e) {
|
||||
|
||||
switch(e.getButton().getButtonID()){
|
||||
case 0:
|
||||
gsm.setState(State.MENU_STATE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public void buttonReleased(ButtonEvent e) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onJoystickMoved(JoystickEvent e) {
|
||||
}
|
||||
|
||||
public void createBackground(){
|
||||
background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
||||
Graphics2D g2 = background.createGraphics();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,18 @@ import model.SongHandler;
|
||||
import control.GameStateManager;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public abstract class GameState {
|
||||
|
||||
protected GameStateManager gsm;
|
||||
protected SongHandler sh;
|
||||
protected SQLConnector sql;
|
||||
|
||||
public GameState(GameStateManager gsm, SongHandler sh) {
|
||||
public GameState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
this.gsm = gsm;
|
||||
this.sh = sh;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
|
||||
+137
-23
@@ -20,6 +20,7 @@ import model.GameModel;
|
||||
import model.SongHandler;
|
||||
import model.objects.DifficultyButton;
|
||||
import model.objects.MenuButton;
|
||||
import model.objects.highscore.Highscore;
|
||||
import audio.Song;
|
||||
import audio.SongInstance;
|
||||
import audio.sorting.SortALPHA;
|
||||
@@ -29,20 +30,24 @@ import control.GameStateManager.State;
|
||||
import control.button.ButtonEvent;
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.Joystick;
|
||||
import control.joystick.Joystick.Position;
|
||||
import control.joystick.JoystickEvent;
|
||||
import control.joystick.JoystickHandler;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class MenuState extends GameState {
|
||||
private ArrayList<MenuButton> buttons;
|
||||
private ArrayList<DifficultyButton> buttons2;
|
||||
private int selected, oldselected;
|
||||
private List<Song> songs;
|
||||
SQLConnector sql = new SQLConnector();
|
||||
|
||||
private int animationcounter;
|
||||
private boolean subscreen, startanimation;
|
||||
private VolatileImage mainScreenBackground, subScreenBackground, subScreenForeground;
|
||||
|
||||
int yPosDiffButton = 900;
|
||||
private int difSelect=0;
|
||||
private int difSelect=0, oldDifSelect = -1;
|
||||
Font textFont = new Font("OCR A Extended", Font.BOLD, 50);
|
||||
Font textFontSmall = new Font("OCR A Extended", Font.BOLD, 15);
|
||||
BufferedImage aanwijzers = Images.getImage(ImageType.aanwijzers);
|
||||
@@ -58,14 +63,28 @@ public class MenuState extends GameState {
|
||||
|
||||
|
||||
|
||||
public MenuState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
public MenuState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
super(gsm, sh, sql);
|
||||
buttons = new ArrayList<MenuButton>();
|
||||
buttons2 = new ArrayList<DifficultyButton>();
|
||||
this.songs = sh.getSongs();
|
||||
startanimation = true;
|
||||
subscreen = false;
|
||||
|
||||
selected = 0;
|
||||
oldselected = -1;
|
||||
|
||||
buttons2.clear();
|
||||
int instanceNr = 0;
|
||||
for(int i = selectedToSong(selected).getSongs().size(); i>0; i--){
|
||||
if(sh.getCurrentSong().getSongs().size() == 0)
|
||||
continue;
|
||||
SongInstance si = selectedToSong(selected).getSongs().get(i-1);
|
||||
buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
|
||||
instanceNr += 100;
|
||||
}
|
||||
difSelect = 0;
|
||||
|
||||
generateMainScreenBackground();
|
||||
generateSubScreenBackground();
|
||||
}
|
||||
@@ -75,6 +94,7 @@ public class MenuState extends GameState {
|
||||
{
|
||||
ButtonHandler.getButton(1).setColor(GameModel.colors[0]);
|
||||
ButtonHandler.getButton(2).setColor(GameModel.colors[2]);
|
||||
generateSubScreenForeground();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -82,8 +102,11 @@ public class MenuState extends GameState {
|
||||
|
||||
ButtonHandler.getButton(5).setColor(GameModel.colors[1]);
|
||||
ButtonHandler.getButton(6).setColor(GameModel.colors[4]);
|
||||
JoystickHandler.REPEAT = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,9 +117,9 @@ public class MenuState extends GameState {
|
||||
startanimation = false;
|
||||
}
|
||||
}else if(subscreen){
|
||||
nextScreen();
|
||||
//nextScreen();
|
||||
}else{
|
||||
previousScreen();
|
||||
//previousScreen();
|
||||
}
|
||||
if(selected != oldselected){
|
||||
for(int i = 0; i < buttons.size(); i++){
|
||||
@@ -104,17 +127,11 @@ public class MenuState extends GameState {
|
||||
|
||||
}
|
||||
oldselected = selected;
|
||||
|
||||
|
||||
buttons2.clear();
|
||||
int instanceNr = 0;
|
||||
for(int i = sh.getCurrentSong().getSongs().size(); i>0; i--){
|
||||
if(sh.getCurrentSong().getSongs().size() == 0)
|
||||
continue;
|
||||
SongInstance si = sh.getCurrentSong().getSongs().get(i-1);
|
||||
buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
|
||||
instanceNr += 100;
|
||||
}
|
||||
if(difSelect != oldDifSelect)
|
||||
{
|
||||
oldDifSelect = difSelect;
|
||||
generateSubScreenForeground();
|
||||
}
|
||||
index++;
|
||||
|
||||
@@ -169,12 +186,14 @@ public class MenuState extends GameState {
|
||||
generateSubScreenForeground();
|
||||
}else if(e.getButton().getButtonID() == 5){
|
||||
sh.sort(new SortALPHA());
|
||||
oldselected = 1;
|
||||
selected = 0;
|
||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
||||
sh.play();
|
||||
}else if(e.getButton().getButtonID() == 6){
|
||||
sh.sort(new SortPLAYED());
|
||||
oldselected = 1;
|
||||
selected = 0;
|
||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
||||
sh.play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,10 +221,13 @@ public class MenuState extends GameState {
|
||||
difSelect = 0;
|
||||
}
|
||||
|
||||
// System.out.println(difSelect);
|
||||
//System.out.println(difSelect);
|
||||
}
|
||||
sh.set(sh.getCurrentSong().getSongs().get(difSelect));
|
||||
generateSubScreenForeground();
|
||||
else if(e.getJoystick().getPos() == Position.CENTER)
|
||||
{
|
||||
sh.set(selectedToSong(selected).getSongs().get(difSelect));
|
||||
}
|
||||
//generateSubScreenForeground();
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||
selected++;
|
||||
@@ -257,10 +279,25 @@ public class MenuState extends GameState {
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if(e.getJoystick().getPos() == Position.CENTER)
|
||||
{
|
||||
buttons2.clear();
|
||||
int instanceNr = 0;
|
||||
for(int i = selectedToSong(selected).getSongs().size(); i>0; i--){
|
||||
if(sh.getCurrentSong().getSongs().size() == 0)
|
||||
continue;
|
||||
SongInstance si = selectedToSong(selected).getSongs().get(i-1);
|
||||
buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
|
||||
instanceNr += 100;
|
||||
}
|
||||
difSelect = 0;
|
||||
|
||||
sh.set(songs.indexOf(selectedToSong(selected)));
|
||||
sh.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateMainScreenBackground(){
|
||||
mainScreenBackground = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
|
||||
@@ -343,12 +380,87 @@ public class MenuState extends GameState {
|
||||
g2.setFont(textFont);
|
||||
g2.drawString(selectedToSong(selected).getTitle(), 30, 60);
|
||||
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.drawString("Author: " + selectedToSong(selected).getAuthor(), 30, 200);
|
||||
|
||||
boolean highscoresFound = true;
|
||||
int HIGHSCORES_TO_DISPLAY = 5;
|
||||
|
||||
List<Highscore> highscores = sql.getHighscoresToday(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
||||
if(highscores.isEmpty())
|
||||
{
|
||||
highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
||||
if(highscores.isEmpty())
|
||||
{
|
||||
highscoresFound = false;
|
||||
}
|
||||
else
|
||||
g2.drawString("All Time Highscores", 30, 300);
|
||||
}
|
||||
else
|
||||
g2.drawString("Daily Highscore", 30, 300);
|
||||
|
||||
if(highscoresFound)
|
||||
{
|
||||
HIGHSCORES_TO_DISPLAY = HIGHSCORES_TO_DISPLAY > highscores.size() ? highscores.size() : HIGHSCORES_TO_DISPLAY;
|
||||
|
||||
for(int i = 0; i<HIGHSCORES_TO_DISPLAY; i++)
|
||||
{
|
||||
Highscore hi = highscores.get(i);
|
||||
|
||||
g2.drawString(hi.getName() + " - " + hi.getScore(), 30, 400 + i*100);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g2.drawString("No Highscores found", 30, 400);
|
||||
}
|
||||
|
||||
/*
|
||||
List<Highscore> highscores = sql.getHighscores(selectedToSong(selected), sh.getCurrentSong().getSongs().get(difSelect));
|
||||
List<Highscore> dailyHighs = new ArrayList<Highscore>();
|
||||
int highest = 0;
|
||||
int oldHighest = 0;
|
||||
|
||||
Date date = new Date();
|
||||
int time = date.getDay();
|
||||
int dailyHighest = 0;
|
||||
int oldDailyHighest = 0;
|
||||
|
||||
|
||||
String name = "";
|
||||
String dailyName = "";
|
||||
|
||||
for(Highscore h:highscores){
|
||||
|
||||
oldHighest = h.getScore();
|
||||
if(oldHighest > highest){
|
||||
highest = oldHighest;
|
||||
name = h.getName();
|
||||
}
|
||||
|
||||
|
||||
if(time == h.getDate().getDay())
|
||||
dailyHighs.add(h);
|
||||
for(int i = 0; i < dailyHighs.size(); i ++){
|
||||
oldDailyHighest = dailyHighs.get(i).getDate().getDay();
|
||||
if(oldDailyHighest > dailyHighest){
|
||||
dailyHighest = oldDailyHighest;
|
||||
dailyName = h.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.drawString("Author: " + selectedToSong(selected).getAuthor(), 30, 200);
|
||||
g2.drawString("Overall Highscore: " + "", 30, 300);
|
||||
g2.drawString("Daily Highscore: " + "", 30, 400);
|
||||
g2.drawString("Personal Highscore: " + "", 30, 500);
|
||||
g2.drawString("Overall Highscore: " + highest , 30, 300);
|
||||
g2.drawString("Overall Highscore by: " + name, 30, 400);
|
||||
g2.drawString("Daily Highscore: " + dailyHighest, 30, 500);
|
||||
g2.drawString("Daily Highscore by: : " + dailyName, 30, 600);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
for(DifficultyButton b : buttons2){
|
||||
b.draw(g2);
|
||||
@@ -402,6 +514,7 @@ public class MenuState extends GameState {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void nextScreen(){
|
||||
if(buttons.get(0).getX() > -700){
|
||||
for(MenuButton b:buttons){
|
||||
@@ -417,6 +530,7 @@ public class MenuState extends GameState {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public Song selectedToSong(int s){
|
||||
s %= songs.size();
|
||||
|
||||
@@ -4,9 +4,11 @@ import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Iterator;
|
||||
|
||||
import main.Window;
|
||||
import model.SongHandler;
|
||||
import model.drawObjects.Enemy;
|
||||
import model.drawObjects.Player;
|
||||
@@ -21,6 +23,7 @@ import control.button.Button;
|
||||
import control.button.ButtonEvent;
|
||||
import control.button.ButtonHandler;
|
||||
import control.joystick.JoystickEvent;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class PlayState extends GameState {
|
||||
|
||||
@@ -36,12 +39,17 @@ public class PlayState extends GameState {
|
||||
public static int comboScore = 0;
|
||||
public static double lifePoints = 100;
|
||||
|
||||
private int enemies_hit = 0;
|
||||
private int enemies_missed = 0;
|
||||
private int buttons_pressed = 0;
|
||||
private int joystick_moved = 0;
|
||||
|
||||
private boolean init = false;
|
||||
|
||||
private long oldProgress = 0;
|
||||
|
||||
public PlayState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
public PlayState(GameStateManager gsm, SongHandler sh, SQLConnector sql) {
|
||||
super(gsm, sh, sql);
|
||||
infoPanel = new InfoPanel(0, 0, sh);
|
||||
area = new PlayArea(256, 1024, 1024, 125);
|
||||
player = new Player(1280 - 1024 + 1024 / 2, 1024 / 2);
|
||||
@@ -55,7 +63,12 @@ public class PlayState extends GameState {
|
||||
lifePoints = 100;
|
||||
currentScore = 0;
|
||||
comboScore = 0;
|
||||
oldProgress = 0 ;
|
||||
oldProgress = 0;
|
||||
|
||||
enemies_hit = 0;
|
||||
enemies_missed = 0;
|
||||
buttons_pressed = 0;
|
||||
joystick_moved = 0;
|
||||
|
||||
for(Path p : area.paths)
|
||||
{
|
||||
@@ -92,7 +105,7 @@ public class PlayState extends GameState {
|
||||
|
||||
|
||||
if(progress > sh.getCurrentSongInstance().getEndTime() + Enemy.secondsToEnd*1000*2)
|
||||
gsm.setState(State.GAMEOVER_STATE);
|
||||
endGame();
|
||||
|
||||
// System.out.println(progress - oldProgress + " / " + area.paths.get(player.getIndex()).getEnemysInPath().size());
|
||||
|
||||
@@ -112,6 +125,7 @@ public class PlayState extends GameState {
|
||||
enemyIterator.remove();
|
||||
lifePoints -= 5;
|
||||
comboScore /= 2;
|
||||
enemies_missed++;
|
||||
}
|
||||
if(closedEnemy == null){
|
||||
closedEnemy = e;
|
||||
@@ -125,15 +139,19 @@ public class PlayState extends GameState {
|
||||
|
||||
lifePoints -= 0.002 * factor;
|
||||
|
||||
infoPanel.updateIPanel();
|
||||
|
||||
if(lifePoints <= 0)
|
||||
gsm.setState(State.GAMEOVER_STATE);
|
||||
{
|
||||
endGame();
|
||||
}
|
||||
if(comboScore >= 100)
|
||||
{
|
||||
comboScore = 0;
|
||||
currentScore += 500;
|
||||
}
|
||||
|
||||
infoPanel.updateIPanel();
|
||||
|
||||
area.count();
|
||||
if(closedEnemy == null){
|
||||
area.pathPainted(-1, null);
|
||||
@@ -142,6 +160,11 @@ public class PlayState extends GameState {
|
||||
}
|
||||
}
|
||||
|
||||
private void endGame() {
|
||||
gsm.setState(State.GAMEOVER_STATE);
|
||||
sql.addPlaydata(sh.getCurrentSong(), sh.getCurrentSongInstance(), sh.getProgress()/1000, enemies_missed, enemies_hit, buttons_pressed, joystick_moved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
try {
|
||||
@@ -164,6 +187,19 @@ public class PlayState extends GameState {
|
||||
player.draw(g2);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if(!Window.ON_RASP){
|
||||
int width,height;
|
||||
width = g2.getFontMetrics().stringWidth("");
|
||||
height = g2.getFontMetrics().getHeight();
|
||||
for (int i = 1; i < ButtonHandler.getButtons().size(); i++) {
|
||||
Ellipse2D oval = new Ellipse2D.Double(880+(50*i), 0, 50, 50);
|
||||
g2.setColor(ButtonHandler.getButton(i).getColor());
|
||||
g2.fill(oval);
|
||||
g2.setColor(Color.BLACK);
|
||||
width = g2.getFontMetrics().stringWidth(""+i);
|
||||
g2.drawString(""+i, (int)oval.getCenterX()-width/2,(int)oval.getMaxY()+height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,6 +215,7 @@ public class PlayState extends GameState {
|
||||
lifePoints = Math.min(lifePoints+10, 100);
|
||||
area.setHitAreaColor(enemy.getColor());
|
||||
area.hit();
|
||||
enemies_hit++;
|
||||
enemysInPath.remove();
|
||||
notHit = false;
|
||||
break;
|
||||
@@ -199,8 +236,10 @@ public class PlayState extends GameState {
|
||||
|
||||
if(e.getButton().getButtonID() == 0)
|
||||
{
|
||||
gsm.setState(State.GAMEOVER_STATE);
|
||||
endGame();
|
||||
}
|
||||
else
|
||||
buttons_pressed++;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,6 +278,7 @@ public class PlayState extends GameState {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
joystick_moved++;
|
||||
}
|
||||
|
||||
public void addEnemy(int pathID, Color color) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import control.GameStateManager;
|
||||
import control.GameStateManager.State;
|
||||
import control.button.ButtonEvent;
|
||||
import control.joystick.JoystickEvent;
|
||||
import data.io.SQLConnector;
|
||||
|
||||
public class TitleState extends GameState {
|
||||
|
||||
@@ -37,8 +38,8 @@ public class TitleState extends GameState {
|
||||
int indexKast = 0;
|
||||
int xKast=0;
|
||||
|
||||
public TitleState(GameStateManager gsm, SongHandler sh){
|
||||
super(gsm, sh);
|
||||
public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
|
||||
super(gsm, sh, sql);
|
||||
createBackground();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class DifficultyButton {
|
||||
g2.fillRect(0, 0, 300, 75);
|
||||
g2.setColor(Color.ORANGE);
|
||||
g2.drawRect(0, 0, 300, 75);
|
||||
g2.drawRect(0-2, 0-2, 304, 79);
|
||||
//g2.drawRect(0-2, 0-2, 304, 79);
|
||||
|
||||
g2.setColor(color);
|
||||
Font textFont2 = new Font("OCR A Extended", Font.BOLD, 50);
|
||||
|
||||
@@ -66,17 +66,9 @@ public class InfoPanel {
|
||||
g2.drawRect(25, 300, 200, 700);
|
||||
|
||||
g2.drawString(sh.getCurrentSong().getTitle(), 25, 200);
|
||||
if(sh.getCurrentSong().getSubtitle() != "")
|
||||
{
|
||||
g2.drawString(sh.getCurrentSong().getSubtitle(), 25, 230);
|
||||
g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230);
|
||||
g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
|
||||
g2.drawString(time, 25, 290);
|
||||
}
|
||||
else
|
||||
{
|
||||
g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230);
|
||||
g2.drawString(time, 25, 260);
|
||||
}
|
||||
|
||||
g2.setColor(Color.YELLOW);
|
||||
g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore);
|
||||
|
||||
@@ -3,7 +3,6 @@ package model.objects;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import audio.Song;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package model.objects.highscore;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import audio.SongInstance;
|
||||
|
||||
public class Highscore {
|
||||
private SongInstance si;
|
||||
private String name;
|
||||
private int score;
|
||||
private long time;
|
||||
|
||||
public Highscore(SongInstance si, String name, int score, long time) {
|
||||
this.si = si;
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public long getTime(){
|
||||
return time;
|
||||
}
|
||||
public Date getDate(){
|
||||
return new Date(getTime());
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package model.objects.highscore;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class HighscoreLetter {
|
||||
|
||||
public static int charLength = 46;
|
||||
private char[] letters;
|
||||
private int x,y,index = 0;
|
||||
|
||||
public HighscoreLetter(char[] letters, int x, int y) {
|
||||
super();
|
||||
this.letters = letters;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2){
|
||||
charLength = g2.getFontMetrics().stringWidth(letters[index]+"");
|
||||
g2.drawString(letters[index]+"", x, y);
|
||||
g2.drawLine(x, y, x+charLength, y);
|
||||
}
|
||||
|
||||
public void up(){
|
||||
index++;
|
||||
index %= letters.length;
|
||||
}
|
||||
|
||||
public void down(){
|
||||
index--;
|
||||
if(index < 0){
|
||||
index = letters.length-1;
|
||||
}
|
||||
}
|
||||
|
||||
public String getCurrentString(){
|
||||
return letters[index]+"";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package model.objects.highscore;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class HighscoreName {
|
||||
|
||||
private final char[] characters = " abcdefghijklmnopqrstuvwxyz0123456789†".toUpperCase().toCharArray();
|
||||
private int spacing = 10;
|
||||
private HighscoreLetter[] letters;
|
||||
private Font font;
|
||||
private int index = 0;
|
||||
|
||||
public HighscoreName(int x, int y,int nameLength,Font font) {
|
||||
this.font = font;
|
||||
letters = new HighscoreLetter[nameLength];
|
||||
int marge = (int) (Math.floor(nameLength/2)-1)*spacing;
|
||||
x -= (double)HighscoreLetter.charLength*(nameLength/2.0) + marge;
|
||||
|
||||
System.out.println(x);
|
||||
for(int i = 0; i < letters.length; i++){
|
||||
letters[i] = new HighscoreLetter(characters, x+(HighscoreLetter.charLength*i)+(spacing*i), y);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawName(Graphics2D g2){
|
||||
g2.setFont(font);
|
||||
for(int i = 0; i < letters.length; i++){
|
||||
if(i == index){
|
||||
g2.setColor(Color.RED);
|
||||
}else{
|
||||
g2.setColor(Color.BLACK);
|
||||
}
|
||||
letters[i].draw(g2);
|
||||
}
|
||||
}
|
||||
|
||||
public void left(){
|
||||
index--;
|
||||
if(index < 0){
|
||||
index = letters.length-1;
|
||||
}
|
||||
}
|
||||
|
||||
public void right(){
|
||||
index++;
|
||||
index %= letters.length;
|
||||
}
|
||||
|
||||
public void up(){
|
||||
letters[index].up();
|
||||
}
|
||||
|
||||
public void down(){
|
||||
letters[index].down();
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
String name = "";
|
||||
for(int i = 0; i < letters.length; i++){
|
||||
name += letters[i].getCurrentString();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
+1
-6
@@ -1,8 +1,6 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
@@ -11,7 +9,6 @@ import java.awt.Toolkit;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import control.GameStateManager;
|
||||
import control.LedHandler;
|
||||
|
||||
public class GameView extends JPanel {
|
||||
|
||||
@@ -20,13 +17,11 @@ public class GameView extends JPanel {
|
||||
*/
|
||||
private static final long serialVersionUID = 1939480784205689618L;
|
||||
|
||||
LedHandler led;
|
||||
GameStateManager gsm;
|
||||
|
||||
// Font fpsfont = new Font("OCR A Extended", Font.BOLD, 60);
|
||||
|
||||
public GameView(LedHandler led, GameStateManager gsm) {
|
||||
this.led = led;
|
||||
public GameView(GameStateManager gsm) {
|
||||
this.gsm = gsm;
|
||||
this.setPreferredSize(new Dimension(1280, 1024));
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user