forked from IF-LK-2020/wordle
Compare commits
35 Commits
dd3713bda1
...
untested
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f117b6b30 | ||
|
|
e203a8747c | ||
|
|
86d449cba2 | ||
|
|
91ed88d15d | ||
|
|
8e9a9218be | ||
|
|
de0133d1b1 | ||
|
|
7d66b9c043 | ||
|
|
55fe449643 | ||
|
|
a5ffccc596 | ||
|
|
16e4382902 | ||
|
|
da1167b8d4 | ||
|
|
a7a4848737 | ||
|
|
2cf96672fc | ||
|
|
98522653b2 | ||
|
|
08f6a3f68a | ||
|
|
c3e91b9ae4 | ||
|
|
ae7093a555 | ||
|
|
9c47fb0885 | ||
|
|
4419bbee88 | ||
|
|
f6734a51ab | ||
|
|
6ca53fcd10 | ||
|
|
ed124899bb | ||
|
|
e7a785f968 | ||
|
|
e3e899908f | ||
|
|
031f73abfa | ||
|
|
86119bcb6a | ||
|
|
e1103cf78e | ||
|
|
2278d6ae6d | ||
|
|
fbfc559a45 | ||
|
|
755f2d5a9d | ||
|
|
c56b0d755e | ||
|
|
b84ff5459e | ||
|
|
78e83c500d | ||
|
|
9fe5d3c753 | ||
|
|
65a8467b89 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -13,7 +13,6 @@ Dokumente*
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
@@ -26,3 +25,6 @@ hs_err_pid*
|
||||
|
||||
# Engine-Alpha files
|
||||
engine-alpha.log
|
||||
.classpath
|
||||
.project
|
||||
/bin/
|
||||
|
||||
34
GUI.java
34
GUI.java
@@ -1,34 +0,0 @@
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class GUI extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JFrame frame;
|
||||
|
||||
private Letter[][] letters;
|
||||
|
||||
public GUI() {
|
||||
frame = new JFrame();
|
||||
frame.setSize(1000, 800);
|
||||
frame.setTitle("Wordle");
|
||||
frame.setVisible(true);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.add(this);
|
||||
|
||||
letters = new Letter[5][6];
|
||||
for (int x = 0; x < letters.length; x++) {
|
||||
for (int y = 0; y < letters[0].length; y++) {
|
||||
letters[x][y] = new Letter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
g.drawRect(100, 100, 100, 100);
|
||||
}
|
||||
}
|
||||
21
Game.java
21
Game.java
@@ -1,21 +0,0 @@
|
||||
|
||||
public class Game {
|
||||
// Instanzvariablen - ersetzen Sie das folgende Beispiel mit Ihren Variablen
|
||||
WordleServer wordleServer;
|
||||
User user;
|
||||
GUI gui;
|
||||
DatabaseConnector databaseConnector;// Datenbankverbindung aufstellen
|
||||
private String wordle;
|
||||
private String[] words;
|
||||
private int count;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Game();
|
||||
}
|
||||
|
||||
public Game() {
|
||||
wordleServer = new WordleServer();
|
||||
user = new User();
|
||||
gui = new GUI();
|
||||
}
|
||||
}
|
||||
93
gui (not in use)/GUI.java
Normal file
93
gui (not in use)/GUI.java
Normal file
@@ -0,0 +1,93 @@
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class GUI extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JFrame frame;
|
||||
|
||||
private Letter[][] letters;
|
||||
|
||||
private boolean running;
|
||||
private float marginRatio = 0.2f;
|
||||
|
||||
public GUI() {
|
||||
frame = new JFrame();
|
||||
frame.setSize(1000, 800);
|
||||
frame.setTitle("Wordle");
|
||||
frame.setVisible(true);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.add(this);
|
||||
|
||||
letters = new Letter[5][6];
|
||||
for (int x = 0; x < letters.length; x++) {
|
||||
for (int y = 0; y < letters[0].length; y++) {
|
||||
letters[x][y] = new Letter();
|
||||
}
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
running = true;
|
||||
while (running) {
|
||||
repaint();
|
||||
try {
|
||||
Thread.sleep(16);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
if (letters == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2d.setFont(new Font(null, Font.BOLD, 48));
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
|
||||
int framew = getSize().width;
|
||||
int frameh = getSize().height;
|
||||
|
||||
g2d.setColor(Color.DARK_GRAY);
|
||||
g2d.fillRect(0, 0, framew, frameh);
|
||||
|
||||
int letterSize = frameh / 10;
|
||||
int margin = (int) (letterSize * marginRatio);
|
||||
int offsetX = framew / 2 - (5 * letterSize + 4 * margin) / 2;
|
||||
int offsetY = frameh / 2 - (6 * letterSize + 5 * margin) / 2;
|
||||
|
||||
for (int x = 0; x < letters.length; x++) {
|
||||
for (int y = 0; y < letters[0].length; y++) {
|
||||
int posX = offsetX + x * (letterSize + margin);
|
||||
int posY = offsetY + y * (letterSize + margin);
|
||||
g2d.setColor(letters[x][y].getColor());
|
||||
g2d.fillRect(posX, posY, letterSize, letterSize);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(posX, posY, letterSize, letterSize);
|
||||
|
||||
String letter = "" + letters[x][y].getLetter();
|
||||
int letterWidth = g2d.getFontMetrics().stringWidth(letter);
|
||||
|
||||
g2d.drawString(letter, posX + letterSize / 2 - letterWidth / 2, posY + letterSize / 2 + 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,32 +4,27 @@
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class User
|
||||
public class Guest
|
||||
{
|
||||
// Instanzvariablen - ersetzen Sie das folgende Beispiel mit Ihren Variablen
|
||||
private String name;
|
||||
private String password;
|
||||
private float winPercentage;
|
||||
private int timesPlayed;
|
||||
private int winPercentage;
|
||||
private int currentStreak;
|
||||
private int maxStreak;
|
||||
private int[] wonInTurn;
|
||||
private int[] wonInTurn = {0,0,0,0,0,0};
|
||||
|
||||
/**
|
||||
* Konstruktor für Objekte der Klasse User
|
||||
*/
|
||||
public User()
|
||||
public Guest()
|
||||
{
|
||||
// Instanzvariable initialisieren
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Beispiel einer Methode - ersetzen Sie diesen Kommentar mit Ihrem eigenen
|
||||
*
|
||||
* @param y ein Beispielparameter für eine Methode
|
||||
* @return die Summe aus x und y
|
||||
*/
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
@@ -41,6 +36,7 @@ public class User
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
@@ -52,6 +48,25 @@ public class User
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setWinPercentage(float winPercentage)
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
this.winPercentage = winPercentage;
|
||||
}
|
||||
|
||||
public float getWinPercentage()
|
||||
{
|
||||
int sum = 0;
|
||||
for(int i = 0;i < wonInTurn.length;i++)
|
||||
{
|
||||
sum += wonInTurn[i];
|
||||
}
|
||||
winPercentage = sum / timesPlayed;
|
||||
return winPercentage;
|
||||
}
|
||||
|
||||
|
||||
public void setTimesPlayed(int timesPlayed)
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
@@ -63,16 +78,11 @@ public class User
|
||||
return timesPlayed;
|
||||
}
|
||||
|
||||
public void setwinPercentage(int winPercentage)
|
||||
public void increaseTimesPlayed()
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
this.winPercentage = winPercentage;
|
||||
timesPlayed = timesPlayed + 1;
|
||||
}
|
||||
|
||||
public int getWinPercentage()
|
||||
{
|
||||
return winPercentage;
|
||||
}
|
||||
|
||||
public void setCurrentStreak(int currentStreak)
|
||||
{
|
||||
@@ -85,9 +95,14 @@ public class User
|
||||
return currentStreak;
|
||||
}
|
||||
|
||||
public void increaseCurrentStreak()
|
||||
{
|
||||
currentStreak = currentStreak + 1;
|
||||
}
|
||||
|
||||
|
||||
public void setMaxStreak(int maxStreak)
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
this.maxStreak = maxStreak;
|
||||
}
|
||||
|
||||
@@ -96,17 +111,31 @@ public class User
|
||||
return maxStreak;
|
||||
}
|
||||
|
||||
public void setWonInTurn(int[] wonInTurn)
|
||||
public void increaseMaxStreak()
|
||||
{
|
||||
this.wonInTurn = wonInTurn;
|
||||
maxStreak = maxStreak + 1;
|
||||
}
|
||||
|
||||
public int getWonInTurn(int turn)
|
||||
|
||||
public void setWonInTurn(int row, int value)
|
||||
{
|
||||
int temp = wonInTurn[turn];
|
||||
this.wonInTurn[row] = value;
|
||||
}
|
||||
|
||||
public int getWonInTurn(int row)
|
||||
{
|
||||
int temp = wonInTurn[row];
|
||||
return temp;
|
||||
}
|
||||
|
||||
public void increaseWonInTurn(int row)
|
||||
{
|
||||
int temp = getWonInTurn(row) + 1;
|
||||
setWonInTurn(row, temp);
|
||||
}
|
||||
|
||||
public int[] getWonInTurnFull()
|
||||
{
|
||||
return wonInTurn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
43
gui (not in use)/Letter.java
Normal file
43
gui (not in use)/Letter.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.awt.Color;
|
||||
|
||||
public class Letter {
|
||||
|
||||
public static final byte WHITE = -1;
|
||||
public static final byte GRAY = 0;
|
||||
public static final byte YELLOW = 1;
|
||||
public static final byte GREEN = 2;
|
||||
|
||||
private char letter;
|
||||
private byte color;
|
||||
|
||||
public Letter() {
|
||||
letter = 'A';
|
||||
color = (byte) ((byte) (Math.random() * 4) - 1);
|
||||
}
|
||||
|
||||
public void setColor(byte color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
switch (color) {
|
||||
case WHITE:
|
||||
return new Color(200, 200, 200);
|
||||
case GRAY:
|
||||
return new Color(100, 100, 100);
|
||||
case YELLOW:
|
||||
return new Color(220, 220, 0);
|
||||
case GREEN:
|
||||
return new Color(0, 220, 0);
|
||||
}
|
||||
return Color.BLACK;
|
||||
}
|
||||
|
||||
public void setLetter(char letter) {
|
||||
this.letter = letter;
|
||||
}
|
||||
|
||||
public char getLetter() {
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
BIN
lib/sqlite-jdbc-3.36.0.3.jar
Normal file
BIN
lib/sqlite-jdbc-3.36.0.3.jar
Normal file
Binary file not shown.
109
package.bluej
109
package.bluej
@@ -1,109 +0,0 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=DatabaseConnector
|
||||
dependency1.to=QueryResult
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=DatabaseConnector
|
||||
dependency2.to=Queue
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Server
|
||||
dependency3.to=List
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=WordleServer
|
||||
dependency4.to=DatabaseConnector
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Game
|
||||
dependency5.to=WordleServer
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=Game
|
||||
dependency6.to=User
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=Game
|
||||
dependency7.to=DatabaseConnector
|
||||
dependency7.type=UsesDependency
|
||||
editor.fx.0.height=1017
|
||||
editor.fx.0.width=854
|
||||
editor.fx.0.x=-7
|
||||
editor.fx.0.y=0
|
||||
objectbench.height=96
|
||||
objectbench.width=1201
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8476331360946746
|
||||
package.editor.height=553
|
||||
package.editor.width=1090
|
||||
package.editor.x=39
|
||||
package.editor.y=24
|
||||
package.frame.height=776
|
||||
package.frame.width=1241
|
||||
package.numDependencies=7
|
||||
package.numTargets=9
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=49
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=70
|
||||
target1.name=DatabaseConnector
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=150
|
||||
target1.x=370
|
||||
target1.y=20
|
||||
target2.height=70
|
||||
target2.name=QueryResult
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=110
|
||||
target2.y=80
|
||||
target3.height=70
|
||||
target3.name=Game
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=960
|
||||
target3.y=30
|
||||
target4.height=70
|
||||
target4.name=User
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=120
|
||||
target4.x=770
|
||||
target4.y=50
|
||||
target5.height=70
|
||||
target5.name=Server
|
||||
target5.showInterface=false
|
||||
target5.type=AbstractTarget
|
||||
target5.width=120
|
||||
target5.x=770
|
||||
target5.y=300
|
||||
target6.height=70
|
||||
target6.name=WordleServer
|
||||
target6.showInterface=false
|
||||
target6.type=ClassTarget
|
||||
target6.width=120
|
||||
target6.x=540
|
||||
target6.y=210
|
||||
target7.height=70
|
||||
target7.name=GUI
|
||||
target7.showInterface=false
|
||||
target7.type=ClassTarget
|
||||
target7.width=120
|
||||
target7.x=630
|
||||
target7.y=80
|
||||
target8.height=70
|
||||
target8.name=List
|
||||
target8.showInterface=false
|
||||
target8.type=ClassTarget
|
||||
target8.width=150
|
||||
target8.x=390
|
||||
target8.y=380
|
||||
target9.height=60
|
||||
target9.name=Queue
|
||||
target9.showInterface=false
|
||||
target9.type=ClassTarget
|
||||
target9.width=160
|
||||
target9.x=80
|
||||
target9.y=380
|
||||
179
src/Game.java
Normal file
179
src/Game.java
Normal file
@@ -0,0 +1,179 @@
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public class Game {
|
||||
|
||||
private static final int LOGIN_PHASE = 0;
|
||||
private static final int GAME_PHASE = 1;
|
||||
private static final int END_PHASE = 2;
|
||||
|
||||
WordleServer wordleServer;
|
||||
User user;
|
||||
static DatabaseConnector databaseConnector;// Datenbankverbindung aufstellen
|
||||
|
||||
private String ip;
|
||||
private int port;
|
||||
|
||||
private String wordle;
|
||||
private String[] words;
|
||||
private int count;
|
||||
private int phase;
|
||||
|
||||
private String tempLoginName;
|
||||
|
||||
static {
|
||||
|
||||
databaseConnector = new DatabaseConnector(null, 0, "wordle.db", null, null);
|
||||
|
||||
if (databaseConnector.getErrorMessage() != null) {
|
||||
System.err.println(databaseConnector.getErrorMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Game(WordleServer wordleServer, String pClientIP, int pClientPort) {
|
||||
|
||||
this.wordleServer = wordleServer;
|
||||
this.ip = pClientIP;
|
||||
this.port = pClientPort;
|
||||
|
||||
send("+OK Hello there");
|
||||
}
|
||||
|
||||
public void processMessage(String msg) {
|
||||
|
||||
msg = msg.toLowerCase().trim();
|
||||
|
||||
if (msg.equals("quit")) {
|
||||
send("+OK bye");
|
||||
wordleServer.closeConnection(ip, port);
|
||||
System.exit(0); // TODO remove: Einfacher zum testen
|
||||
}
|
||||
|
||||
switch (phase) {
|
||||
case LOGIN_PHASE:
|
||||
loginPhase(msg);
|
||||
break;
|
||||
case GAME_PHASE:
|
||||
gamePhase(msg);
|
||||
break;
|
||||
case END_PHASE:
|
||||
endPhase(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void loginPhase(String msg) {
|
||||
|
||||
if (msg.startsWith("user ")) {
|
||||
|
||||
if (msg.length() <= 5) {
|
||||
sendUniversalError();
|
||||
return;
|
||||
}
|
||||
String args = msg.substring(5);
|
||||
|
||||
databaseConnector.executeStatement("SELECT * FROM User WHERE name = '" + args + "'");
|
||||
QueryResult result = databaseConnector.getCurrentQueryResult();
|
||||
if (result != null && result.getData().length > 0) {
|
||||
tempLoginName = result.getData()[0][0];
|
||||
send("+OK");
|
||||
} else {
|
||||
send("-ERR User not found.");
|
||||
}
|
||||
|
||||
} else if (msg.startsWith("pass ")) {
|
||||
|
||||
if (msg.length() <= 5) {
|
||||
sendUniversalError();
|
||||
return;
|
||||
}
|
||||
String args = msg.substring(5);
|
||||
|
||||
int pw = args.hashCode();
|
||||
databaseConnector.executeStatement("SELECT * FROM User WHERE password = '" + pw + "' AND name = '" + tempLoginName + "'");
|
||||
QueryResult result = databaseConnector.getCurrentQueryResult();
|
||||
if (result != null && result.getData().length > 0) {
|
||||
user = new User(tempLoginName);
|
||||
send("+OK welcome");
|
||||
} else {
|
||||
send("-ERR login not valid");
|
||||
}
|
||||
} else if (msg.startsWith("wotd")) {
|
||||
|
||||
databaseConnector.executeStatement("SELECT word FROM words WHERE id = " + getWOTDIndex());
|
||||
QueryResult result = databaseConnector.getCurrentQueryResult();
|
||||
if (result != null && result.getData().length > 0) {
|
||||
wordle = result.getData()[0][0];
|
||||
phase = GAME_PHASE;
|
||||
send("+OK game ready");
|
||||
} else {
|
||||
send("-ERR Fatal error: WOTD could not be generated.");
|
||||
}
|
||||
|
||||
} else if (msg.startsWith("play")) {
|
||||
|
||||
if (user == null) {
|
||||
send("-ERR not logged in.");
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
sendUniversalError();
|
||||
}
|
||||
}
|
||||
|
||||
private void gamePhase(String msg) {
|
||||
if (msg.startsWith("send")) {
|
||||
|
||||
String args = msg.substring(5);
|
||||
//vergleichen von wotd mit
|
||||
//ja = spiel beendet und ausgabe word 11111
|
||||
//nein = ausgabe 01102 oder so und pr<70>fen ob man noch ein wort eingebn kann
|
||||
// ja game continues nein = game lost
|
||||
|
||||
} else if (msg.startsWith("info")) {
|
||||
|
||||
} else if (msg.startsWith("exit")) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void endPhase(String msg) {
|
||||
if (msg.startsWith("stat")) {
|
||||
|
||||
} else if (msg.startsWith("play")) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void send(String msg) {
|
||||
wordleServer.send(ip, port, msg);
|
||||
}
|
||||
|
||||
private void sendUniversalError() {
|
||||
send("-ERR command not valid in this state");
|
||||
}
|
||||
|
||||
private int getWOTDIndex() {
|
||||
long days = ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now());
|
||||
int hash = ("" + days).hashCode();
|
||||
return hash % 949 + 1;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
154
src/User.java
Normal file
154
src/User.java
Normal file
@@ -0,0 +1,154 @@
|
||||
public class User {
|
||||
|
||||
private String name = "default";
|
||||
|
||||
/**
|
||||
* Konstruktor für Objekte der Klasse User
|
||||
*/
|
||||
public User(String name)
|
||||
{
|
||||
setName(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET password = " + password + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
Game.databaseConnector.executeStatement("SELECT password FROM User Where name =" + this.name);
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET name = " + name + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setWinPercentage(float winPercentage)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET winPercentage = " + winPercentage + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public float getWinPercentage()
|
||||
{
|
||||
Game.databaseConnector.executeStatement("SELECT winPercentage FROM User Where name =" + this.name);
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return Float.parseFloat(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setTimesPlayed(int timesPlayed)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET timesPlayed = " + timesPlayed + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public int getTimesPlayed()
|
||||
{
|
||||
Game.databaseConnector.executeStatement("SELECT timesPlayed FROM User Where name =" + this.name);
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
|
||||
|
||||
public void increaseTimesPlayed()
|
||||
{
|
||||
int temp = getTimesPlayed();
|
||||
temp++;
|
||||
setTimesPlayed(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setCurrentStreak(int currentStreak)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET currentStreak = " + currentStreak + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public int getCurrentStreak()
|
||||
{
|
||||
Game.databaseConnector.executeStatement("SELECT currentStreak FROM User Where name =" + this.name);
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
|
||||
|
||||
public void increaseCurrentStreak()
|
||||
{
|
||||
int temp = getCurrentStreak();
|
||||
temp++;
|
||||
setCurrentStreak(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setMaxStreak(int maxStreak)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET maxStreak = " + maxStreak + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public int getMaxStreak()
|
||||
{
|
||||
Game.databaseConnector.executeStatement("SELECT maxStreak FROM User Where name =" + this.name);
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
|
||||
|
||||
public void increaseMaxStreak()
|
||||
{
|
||||
int temp = getMaxStreak();
|
||||
temp++;
|
||||
setMaxStreak(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setWonInTurn(int row, int value)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET wonInTurn" + row + " = " + value + " Where name = " + this.name);
|
||||
}
|
||||
|
||||
|
||||
public int getWonInTurn(int row)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("SELECT wonInTurn" + row + " FROM User Where name =" + this.name);
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
|
||||
public void increaseWonInTurn(int row)
|
||||
{
|
||||
int temp = getWonInTurn(row) + 1;
|
||||
setWonInTurn(row, temp);
|
||||
}
|
||||
|
||||
public int[] getWonInTurnFull()
|
||||
{
|
||||
int[] result = {getWonInTurn(1),getWonInTurn(2),getWonInTurn(3),getWonInTurn(4),getWonInTurn(5),getWonInTurn(6)};
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/**
|
||||
* Server für das WORDLE Spiel.
|
||||
*/
|
||||
@@ -6,6 +5,8 @@ public class WordleServer extends Server {
|
||||
|
||||
public static final int DEFAULT_PORT = 1000;
|
||||
|
||||
List<Game> games;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
new WordleServer();
|
||||
}
|
||||
@@ -22,21 +23,34 @@ public class WordleServer extends Server {
|
||||
super(pPort);
|
||||
|
||||
db = new DatabaseConnector("", 0, "wordle.db", "", "");
|
||||
|
||||
games = new List<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processNewConnection( String pClientIP, int pClientPort ) {
|
||||
System.out.println("New connection: " + pClientPort);
|
||||
games.append(new Game(this, pClientIP, pClientPort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processClosingConnection( String pClientIP, int pClientPort ) {
|
||||
System.out.println("Closed connection: " + pClientPort);
|
||||
find(pClientIP, pClientPort);
|
||||
games.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage( String pClientIP, int pClientPort, String pMessage ) {
|
||||
System.out.println("Message: " + pMessage);
|
||||
find(pClientIP, pClientPort).processMessage(pMessage);
|
||||
}
|
||||
|
||||
private Game find(String ip, int port) {
|
||||
games.toFirst();
|
||||
while (games.hasAccess()) {
|
||||
Game g = games.getContent();
|
||||
if (g.getIp().equals(ip) && g.getPort() == port) {
|
||||
return g;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
132
src/package.bluej
Normal file
132
src/package.bluej
Normal file
@@ -0,0 +1,132 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=DatabaseConnector
|
||||
dependency1.to=QueryResult
|
||||
dependency1.type=UsesDependency
|
||||
dependency10.from=Game
|
||||
dependency10.to=DatabaseConnector
|
||||
dependency10.type=UsesDependency
|
||||
dependency2.from=DatabaseConnector
|
||||
dependency2.to=Queue
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Server
|
||||
dependency3.to=List
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=WordleServer
|
||||
dependency4.to=List
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=WordleServer
|
||||
dependency5.to=Game
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=WordleServer
|
||||
dependency6.to=DatabaseConnector
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=User
|
||||
dependency7.to=DatabaseConnector
|
||||
dependency7.type=UsesDependency
|
||||
dependency8.from=Game
|
||||
dependency8.to=WordleServer
|
||||
dependency8.type=UsesDependency
|
||||
dependency9.from=Game
|
||||
dependency9.to=User
|
||||
dependency9.type=UsesDependency
|
||||
editor.fx.0.height=1017
|
||||
editor.fx.0.width=854
|
||||
editor.fx.0.x=100
|
||||
editor.fx.0.y=100
|
||||
objectbench.height=153
|
||||
objectbench.width=1656
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8272138228941684
|
||||
package.editor.height=759
|
||||
package.editor.width=1545
|
||||
package.editor.x=0
|
||||
package.editor.y=0
|
||||
package.frame.height=1026
|
||||
package.frame.width=1696
|
||||
package.numDependencies=10
|
||||
package.numTargets=11
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=windows-1252
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=49
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=70
|
||||
target1.name=Letter
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=120
|
||||
target1.x=10
|
||||
target1.y=80
|
||||
target10.height=70
|
||||
target10.name=GUI
|
||||
target10.showInterface=false
|
||||
target10.type=ClassTarget
|
||||
target10.width=120
|
||||
target10.x=10
|
||||
target10.y=270
|
||||
target11.height=60
|
||||
target11.name=Queue
|
||||
target11.showInterface=false
|
||||
target11.type=ClassTarget
|
||||
target11.width=160
|
||||
target11.x=100
|
||||
target11.y=520
|
||||
target2.height=70
|
||||
target2.name=DatabaseConnector
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=150
|
||||
target2.x=220
|
||||
target2.y=80
|
||||
target3.height=60
|
||||
target3.name=QueryResult
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=100
|
||||
target3.x=100
|
||||
target3.y=600
|
||||
target4.height=100
|
||||
target4.name=Game
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=180
|
||||
target4.x=680
|
||||
target4.y=320
|
||||
target5.height=70
|
||||
target5.name=User
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=130
|
||||
target5.x=930
|
||||
target5.y=180
|
||||
target6.height=70
|
||||
target6.name=Server
|
||||
target6.showInterface=false
|
||||
target6.type=AbstractTarget
|
||||
target6.width=110
|
||||
target6.x=310
|
||||
target6.y=500
|
||||
target7.height=70
|
||||
target7.name=WordleServer
|
||||
target7.showInterface=false
|
||||
target7.type=ClassTarget
|
||||
target7.width=110
|
||||
target7.x=480
|
||||
target7.y=500
|
||||
target8.height=70
|
||||
target8.name=Guest
|
||||
target8.showInterface=false
|
||||
target8.type=ClassTarget
|
||||
target8.width=130
|
||||
target8.x=10
|
||||
target8.y=180
|
||||
target9.height=60
|
||||
target9.name=List
|
||||
target9.showInterface=false
|
||||
target9.type=ClassTarget
|
||||
target9.width=150
|
||||
target9.x=560
|
||||
target9.y=640
|
||||
204
umlet.uxf
204
umlet.uxf
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="14.3.0">
|
||||
<zoom_level>12</zoom_level>
|
||||
<zoom_level>8</zoom_level>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>636</x>
|
||||
<y>144</y>
|
||||
<w>120</w>
|
||||
<h>36</h>
|
||||
<x>400</x>
|
||||
<y>48</y>
|
||||
<w>80</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Server</panel_attributes>
|
||||
<additional_attributes/>
|
||||
@@ -15,10 +15,10 @@
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>636</x>
|
||||
<y>300</y>
|
||||
<w>120</w>
|
||||
<h>36</h>
|
||||
<x>400</x>
|
||||
<y>152</y>
|
||||
<w>80</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>WordleServer</panel_attributes>
|
||||
<additional_attributes/>
|
||||
@@ -26,10 +26,10 @@
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>684</x>
|
||||
<y>168</y>
|
||||
<w>36</w>
|
||||
<h>156</h>
|
||||
<x>432</x>
|
||||
<y>64</y>
|
||||
<w>24</w>
|
||||
<h>104</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;110.0</additional_attributes>
|
||||
@@ -37,18 +37,18 @@
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>0</x>
|
||||
<y>420</y>
|
||||
<w>348</w>
|
||||
<h>468</h>
|
||||
<x>448</x>
|
||||
<y>424</y>
|
||||
<w>248</w>
|
||||
<h>384</h>
|
||||
</coordinates>
|
||||
<panel_attributes>User
|
||||
<panel_attributes>Guest
|
||||
--
|
||||
-name: String
|
||||
-password: String
|
||||
|
||||
-timesPlayed: int
|
||||
-winPercentage: int
|
||||
-winPercentage: float
|
||||
-currentStreak: int
|
||||
-maxStreak: int
|
||||
-wonInTurn: int[]
|
||||
@@ -57,25 +57,30 @@
|
||||
+getPassword(): String
|
||||
+setName(String name): void
|
||||
+getName(): String
|
||||
+setWinPercentage(float winPercentage): void
|
||||
+getWinPercentage(): float
|
||||
+setTimesPlayed(int timesPlayed): void
|
||||
+getTimesPlayed(): int
|
||||
+setWinPercentage(int winPercentage): void
|
||||
+getWinPercentage(): int
|
||||
+increaseTimesPlayed(): void
|
||||
+setCurrentStreak(int currentStreak): void
|
||||
+getCurrentStreak(): int
|
||||
+increaseCurrentStreak(): void
|
||||
+setMaxStreak(int maxStreak): void
|
||||
+getMaxStreak(): int
|
||||
+setWonInTurn(int[] wonInTurn): void
|
||||
+getWonInTurn(int turn): int</panel_attributes>
|
||||
+increaseMaxStreak(): void
|
||||
+setWonInTurn(int row, int value): void
|
||||
+getWonInTurn(int row): int
|
||||
+increaseWonInTurn(int row): void
|
||||
+getWonInTurnFull(): int</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>180</x>
|
||||
<y>276</y>
|
||||
<w>168</w>
|
||||
<h>36</h>
|
||||
<x>96</x>
|
||||
<y>136</y>
|
||||
<w>112</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>DatabaseConnector</panel_attributes>
|
||||
<additional_attributes/>
|
||||
@@ -83,10 +88,10 @@
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>684</x>
|
||||
<y>324</y>
|
||||
<w>144</w>
|
||||
<h>120</h>
|
||||
<x>432</x>
|
||||
<y>168</y>
|
||||
<w>96</w>
|
||||
<h>80</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<.
|
||||
-wordleServer</panel_attributes>
|
||||
@@ -95,13 +100,16 @@
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>516</x>
|
||||
<y>420</y>
|
||||
<w>360</w>
|
||||
<h>132</h>
|
||||
<x>320</x>
|
||||
<y>232</y>
|
||||
<w>240</w>
|
||||
<h>88</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Game
|
||||
--
|
||||
-ip: String
|
||||
-port: int
|
||||
|
||||
-wordle: String
|
||||
-words: String[]
|
||||
-wordCount: int
|
||||
@@ -113,24 +121,10 @@
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1020</x>
|
||||
<y>420</y>
|
||||
<w>288</w>
|
||||
<h>84</h>
|
||||
</coordinates>
|
||||
<panel_attributes>GUI
|
||||
--
|
||||
+setLetter(char letter): void
|
||||
+setLetterColor(byte color): void</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>108</x>
|
||||
<y>156</y>
|
||||
<w>120</w>
|
||||
<h>36</h>
|
||||
<x>48</x>
|
||||
<y>56</y>
|
||||
<w>80</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>QueryResult</panel_attributes>
|
||||
<additional_attributes/>
|
||||
@@ -138,34 +132,22 @@
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>336</x>
|
||||
<y>408</y>
|
||||
<w>204</w>
|
||||
<h>48</h>
|
||||
<x>536</x>
|
||||
<y>312</y>
|
||||
<w>56</w>
|
||||
<h>128</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<.
|
||||
-user</panel_attributes>
|
||||
<additional_attributes>10.0;20.0;150.0;20.0</additional_attributes>
|
||||
-guest</panel_attributes>
|
||||
<additional_attributes>10.0;140.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>864</x>
|
||||
<y>408</y>
|
||||
<w>180</w>
|
||||
<h>48</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<.
|
||||
-gui</panel_attributes>
|
||||
<additional_attributes>130.0;20.0;10.0;20.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>336</x>
|
||||
<y>276</y>
|
||||
<w>264</w>
|
||||
<h>168</h>
|
||||
<x>200</x>
|
||||
<y>136</y>
|
||||
<w>176</w>
|
||||
<h>112</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<.
|
||||
-databaseConnector</panel_attributes>
|
||||
@@ -174,35 +156,69 @@
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1020</x>
|
||||
<y>0</y>
|
||||
<w>288</w>
|
||||
<h>300</h>
|
||||
<x>136</x>
|
||||
<y>424</y>
|
||||
<w>240</w>
|
||||
<h>392</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Letter
|
||||
<panel_attributes>User
|
||||
--
|
||||
WHITE: byte = -1
|
||||
GRAY: byte = 0
|
||||
YELLOW: byte = 1
|
||||
GREEN: byte = 2
|
||||
-name: String
|
||||
|
||||
-letter: char
|
||||
-color: byte
|
||||
--
|
||||
+setColor(byte color): void
|
||||
+getColor(): byte</panel_attributes>
|
||||
+setPassword(String password): void
|
||||
+getPassword(): String
|
||||
+setName(String name): void
|
||||
+getName(): String
|
||||
+setTimesPlayed(int timesPlayed): void
|
||||
+getTimesPlayed(): int
|
||||
+increaseTimesPlayed(): void
|
||||
+setWinPercentage(float winPercentage): void
|
||||
+getWinPercentage(): float
|
||||
+setCurrentStreak(int currentStreak): void
|
||||
+getCurrentStreak(): int
|
||||
+increaseCurrentStreak(): void
|
||||
+setMaxStreak(int maxStreak): void
|
||||
+getMaxStreak(): int
|
||||
+increaseMaxStreak(): void
|
||||
+setWonInTurn(int row, int value): void
|
||||
+getWonInTurn(int row): int
|
||||
+getWonInTurnFull(): int</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1152</x>
|
||||
<y>288</y>
|
||||
<w>156</w>
|
||||
<h>156</h>
|
||||
<x>128</x>
|
||||
<y>152</y>
|
||||
<w>144</w>
|
||||
<h>288</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<.
|
||||
-letters: Letter[][]</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;110.0</additional_attributes>
|
||||
-databaseConnector</panel_attributes>
|
||||
<additional_attributes>30.0;10.0;30.0;340.0;10.0;340.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>320</x>
|
||||
<y>312</y>
|
||||
<w>48</w>
|
||||
<h>128</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<.
|
||||
-user</panel_attributes>
|
||||
<additional_attributes>10.0;140.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>368</x>
|
||||
<y>424</y>
|
||||
<w>96</w>
|
||||
<h>24</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>100.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
</diagram>
|
||||
|
||||
Reference in New Issue
Block a user