Initial sqlite Datenbankverbindung
This commit is contained in:
parent
bf200a06ba
commit
39d721462c
9
.idea/Tetris.iml
generated
9
.idea/Tetris.iml
generated
@ -7,5 +7,14 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/Datenbank/sqlite-jdbc-3.36.0.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
@ -32,7 +32,7 @@ private Color[] colors ={Color.decode("#ff00bf"),Color.decode("#0000ff"),Color.d
|
||||
|
||||
|
||||
public Board() {
|
||||
ran = new Random();
|
||||
ran = new Random();
|
||||
steine[0]= new Stein(new int[][]{
|
||||
{1,1,1},
|
||||
{0,1,0}
|
||||
@ -89,6 +89,10 @@ private Color[] colors ={Color.decode("#ff00bf"),Color.decode("#0000ff"),Color.d
|
||||
currenStein.reset();
|
||||
}
|
||||
|
||||
public Stein getCurrenStein() {
|
||||
return currenStein;
|
||||
}
|
||||
|
||||
public Color[][] getBoard(){
|
||||
return board;
|
||||
}
|
||||
@ -125,7 +129,17 @@ private Color[] colors ={Color.decode("#ff00bf"),Color.decode("#0000ff"),Color.d
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
// switch(e.getKeyChar()) {
|
||||
// case KeyEvent.VK_SPACE:
|
||||
// currenStein.speedup();
|
||||
// break;
|
||||
// case KeyEvent.VK_A:
|
||||
// currenStein.moveLeft();
|
||||
// break;
|
||||
// case KeyEvent.VK_D:
|
||||
// currenStein.moveRight();
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -133,7 +147,7 @@ private Color[] colors ={Color.decode("#ff00bf"),Color.decode("#0000ff"),Color.d
|
||||
if(e.getKeyChar() == KeyEvent.VK_SPACE){
|
||||
currenStein.speedup();
|
||||
}else if(e.getKeyChar() == KeyEvent.VK_ENTER){
|
||||
currenStein.moveRigth();
|
||||
currenStein.moveRight();
|
||||
}
|
||||
else if(e.getKeyChar() == KeyEvent.VK_ESCAPE){
|
||||
currenStein.moveLeft();
|
||||
|
@ -1,24 +1,102 @@
|
||||
package Tetris;
|
||||
|
||||
import java.sql.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Game {
|
||||
public static void main(String[] args) {
|
||||
Menue menue = new Menue();
|
||||
|
||||
menue.getButton().addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
String name = JOptionPane.showInputDialog(menue.getParent(),
|
||||
"What is your name?", null);
|
||||
if(name == null){
|
||||
name = "anon";
|
||||
public static void main(String[] args) {
|
||||
Connection connection = null;
|
||||
try
|
||||
{
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:userhighscore.db");
|
||||
Statement statement = connection.createStatement();
|
||||
statement.setQueryTimeout(30);
|
||||
|
||||
Menue menue = new Menue();
|
||||
menue.getButton().addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
String name = JOptionPane.showInputDialog(menue.getParent(),
|
||||
"What is your name?", null);
|
||||
if(name == null){
|
||||
name = "anon";
|
||||
}
|
||||
menue.getParent().setVisible(false);
|
||||
new GameGui(name);
|
||||
}
|
||||
menue.getParent().setVisible(false);
|
||||
new GameGui(name);
|
||||
});
|
||||
String playername = menue.getName();
|
||||
ResultSet resultSet = statement.executeQuery("select * from userscore where name = "+ playername);
|
||||
if(!resultSet.next())
|
||||
{
|
||||
// Playername gibt es noch nicht in der Datenbank also anlegen.
|
||||
// Es fehlt noch der score.
|
||||
statement.executeUpdate("insert into userscore values(1," + playername + ", 123)");
|
||||
}
|
||||
});
|
||||
//String playername = menue.getName();
|
||||
//new GameGui(playername);
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
// if the error message is "out of memory",
|
||||
// it probably means no database file is found
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if(connection != null)
|
||||
connection.close();
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
// connection close failed.
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateSqlLiteDatabaseConnection(){
|
||||
// try
|
||||
// {
|
||||
// Connection connection = null;
|
||||
// // create a database connection
|
||||
// connection = DriverManager.getConnection("jdbc:sqlite:userhighscore.db");
|
||||
// Statement statement = connection.createStatement();
|
||||
// statement.setQueryTimeout(30); // set timeout to 30 sec.
|
||||
|
||||
// statement.executeUpdate("drop table if exists userscore");
|
||||
// statement.executeUpdate("create table userscore (id integer, name string, score integer)");
|
||||
// statement.executeUpdate("insert into userscore values(1, 'leo', 123)");
|
||||
// statement.executeUpdate("insert into userscore values(2, 'yui', 456)");
|
||||
// ResultSet rs = statement.executeQuery("select * from userscore");
|
||||
// while(rs.next())
|
||||
// {
|
||||
// // read the result set
|
||||
//
|
||||
// System.out.println("name = " + rs.getString("name"));
|
||||
// System.out.println("score = " + rs.getInt("score"));
|
||||
// System.out.println("id = " + rs.getInt("id"));
|
||||
// }
|
||||
// }
|
||||
// catch(SQLException e)
|
||||
// {
|
||||
// // if the error message is "out of memory",
|
||||
// // it probably means no database file is found
|
||||
// System.err.println(e.getMessage());
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if(connection != null)
|
||||
// connection.close();
|
||||
// }
|
||||
// catch(SQLException e)
|
||||
// {
|
||||
// // connection close failed.
|
||||
// System.err.println(e.getMessage());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -13,17 +13,6 @@ public class GameGui {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(BorderFactory.createMatteBorder(500, 10, 10, 50,Color.black));
|
||||
|
||||
//Label
|
||||
//JLabel label = new JLabel(" Ihr Name:");
|
||||
//panel.add(label);
|
||||
//Textfeld
|
||||
//JTextField tfName = new JTextField("Bitte Name eingeben");
|
||||
//tfName.setForeground(Color.white);
|
||||
// Hintergrundfarbe wird gesetzt
|
||||
// tfName.setBackground(Color.GRAY);
|
||||
// Textfeld wird unserem Panel hinzugefügt
|
||||
//panel.add(tfName);
|
||||
|
||||
//Button
|
||||
//JButton button1 = new JButton("Start");
|
||||
//button1.setPreferredSize( new Dimension(150,50));
|
||||
@ -31,10 +20,10 @@ public class GameGui {
|
||||
buttonPause.setPreferredSize( new Dimension(100,30));
|
||||
JButton buttonScore = new JButton("Score");
|
||||
buttonScore.setPreferredSize( new Dimension(100,30));
|
||||
|
||||
//Button untereinander
|
||||
panel.setLayout(new GridLayout(0,1));
|
||||
panel.setBackground(Color.YELLOW);
|
||||
//panel.add(button1);
|
||||
panel.add(buttonPause);
|
||||
panel.add(buttonScore);
|
||||
|
||||
@ -48,8 +37,5 @@ public class GameGui {
|
||||
frame.add(board,BorderLayout.CENTER);
|
||||
frame.requestFocusInWindow();
|
||||
}
|
||||
public static void main(String [] args)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -43,16 +43,15 @@ public class Menue {
|
||||
|
||||
parent = new JFrame("Tetris Menü");
|
||||
button = new JButton();
|
||||
|
||||
button.setText("Namen Eingeben");
|
||||
button.setPreferredSize(new Dimension(400,500));
|
||||
button.setBackground(Color.CYAN);
|
||||
button.setBackground(Color.cyan);
|
||||
parent.add(button);
|
||||
parent.pack();
|
||||
parent.setVisible(true);
|
||||
|
||||
}
|
||||
public static void main(final String[] args) {
|
||||
new Menue();
|
||||
}
|
||||
//public static void main(final String[] args) {
|
||||
// new Menue();
|
||||
//}
|
||||
}
|
@ -114,7 +114,7 @@ public void speedup(){
|
||||
public void speedDown(){
|
||||
delayTime=normal;
|
||||
}
|
||||
public void moveRigth(){
|
||||
public void moveRight(){
|
||||
deltax = 1;
|
||||
}
|
||||
public void moveLeft(){
|
||||
|
BIN
userhighscore.db
Normal file
BIN
userhighscore.db
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user