forked from IF-LK-2020/wordle
fixed sql requests in user and replaced requests
This commit is contained in:
parent
93a419f10c
commit
f212bed8de
|
@ -1,6 +1,5 @@
|
|||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Game {
|
||||
|
||||
|
@ -138,7 +137,7 @@ public class Game {
|
|||
if (msg.startsWith("send ")) {
|
||||
|
||||
String args = msg.substring(5);
|
||||
|
||||
System.out.println(wordle);
|
||||
if (args.length() == 5) {
|
||||
|
||||
databaseConnector.executeStatement("SELECT word FROM words WHERE word LIKE '" + args + "'");
|
||||
|
@ -209,45 +208,17 @@ public class Game {
|
|||
|
||||
if (msg.startsWith("stat")) {
|
||||
|
||||
databaseConnector.executeStatement("SELECT timesPlayed FROM User Where name like " + tempLoginName + "");
|
||||
String tP = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("times Played: " + tP);
|
||||
send("times Played: " + user.getTimesPlayed());
|
||||
|
||||
databaseConnector.executeStatement("SELECT winPercentage FROM User Where name like " + tempLoginName + "");
|
||||
String wP = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("win Percentage: " + wP);
|
||||
send("win Percentage: " + user.getWinPercentage());
|
||||
|
||||
databaseConnector.executeStatement("SELECT currentStreak FROM User Where name like " + tempLoginName + "");
|
||||
String cS = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("current Streak: " + cS);
|
||||
send("current Streak: " + user.getCurrentStreak());
|
||||
|
||||
databaseConnector.executeStatement("SELECT maxStreak FROM User Where name like " + tempLoginName + "");
|
||||
String mS = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("max Streak: " + mS);
|
||||
send("max Streak: " + user.getMaxStreak());
|
||||
|
||||
databaseConnector.executeStatement("SELECT wonInTurn1 FROM User Where name like " + tempLoginName + "");
|
||||
String wIT1 = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("won in Turn1: " + wIT1);
|
||||
|
||||
databaseConnector.executeStatement("SELECT wonInTurn1 FROM User Where name like " + tempLoginName + "");
|
||||
String wIT2 = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("won in Turn2: " + wIT2);
|
||||
|
||||
databaseConnector.executeStatement("SELECT wonInTurn1 FROM User Where name like " + tempLoginName + "");
|
||||
String wIT3 = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("won in Turn3: " + wIT3);
|
||||
|
||||
databaseConnector.executeStatement("SELECT wonInTurn1 FROM User Where name like " + tempLoginName + "");
|
||||
String wIT4 = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("won in Turn4: " + wIT4);
|
||||
|
||||
databaseConnector.executeStatement("SELECT wonInTurn1 FROM User Where name like " + tempLoginName + "");
|
||||
String wIT5 = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("won in Turn5: " + wIT5);
|
||||
|
||||
databaseConnector.executeStatement("SELECT wonInTurn1 FROM User Where name like " + tempLoginName + "");
|
||||
String wIT6 = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
send("won in Turn6: " + wIT6);
|
||||
for (int i = 1; i < 6; i++) {
|
||||
send("won in Turn1: " + user.getWonInTurn(i));
|
||||
}
|
||||
|
||||
} else if (msg.startsWith("play")) {
|
||||
|
||||
|
|
243
src/User.java
243
src/User.java
|
@ -1,154 +1,137 @@
|
|||
public class User {
|
||||
|
||||
private String name = "default";
|
||||
private String name = "default";
|
||||
|
||||
/**
|
||||
* Konstruktor für Objekte der Klasse User
|
||||
*/
|
||||
public User(String name)
|
||||
{
|
||||
setName(name);
|
||||
}
|
||||
/**
|
||||
* Konstruktor für Objekte der Klasse User
|
||||
*/
|
||||
public User(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
Game.databaseConnector
|
||||
.executeStatement("UPDATE User SET password = " + password + " Where name LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
Game.databaseConnector.executeStatement("SELECT password FROM User Where name LIKE '" + this.name + "'");
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET password = " + password + " Where name = " + this.name);
|
||||
}
|
||||
public void setName(String name) {
|
||||
Game.databaseConnector
|
||||
.executeStatement("UPDATE User SET name = " + name + " Where name LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return 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 setWinPercentage(float winPercentage) {
|
||||
Game.databaseConnector.executeStatement(
|
||||
"UPDATE User SET winPercentage = " + winPercentage + " Where name LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public float getWinPercentage() {
|
||||
Game.databaseConnector.executeStatement("SELECT winPercentage FROM User Where name LIKE '" + this.name + "'");
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
if (result == null) {
|
||||
return 0f;
|
||||
} else {
|
||||
return Float.parseFloat(result);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTimesPlayed(int timesPlayed) {
|
||||
Game.databaseConnector.executeStatement(
|
||||
"UPDATE User SET timesPlayed = " + timesPlayed + " Where name LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET name = " + name + " Where name = " + this.name);
|
||||
}
|
||||
public int getTimesPlayed() {
|
||||
Game.databaseConnector.executeStatement("SELECT timesPlayed FROM User Where name LIKE '" + this.name + "'");
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
if (result == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
}
|
||||
|
||||
public void increaseTimesPlayed() {
|
||||
int temp = getTimesPlayed();
|
||||
temp++;
|
||||
setTimesPlayed(temp);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
public void setCurrentStreak(int currentStreak) {
|
||||
Game.databaseConnector.executeStatement(
|
||||
"UPDATE User SET currentStreak = " + currentStreak + " Where name LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public int getCurrentStreak() {
|
||||
Game.databaseConnector.executeStatement("SELECT currentStreak FROM User Where name LIKE '" + this.name + "'");
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
if (result == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
}
|
||||
|
||||
public void increaseCurrentStreak() {
|
||||
int temp = getCurrentStreak();
|
||||
temp++;
|
||||
setCurrentStreak(temp);
|
||||
}
|
||||
|
||||
public void setWinPercentage(float winPercentage)
|
||||
{
|
||||
Game.databaseConnector.executeStatement("UPDATE User SET winPercentage = " + winPercentage + " Where name = " + this.name);
|
||||
}
|
||||
public void setMaxStreak(int maxStreak) {
|
||||
Game.databaseConnector
|
||||
.executeStatement("UPDATE User SET maxStreak = " + maxStreak + " Where name LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public int getMaxStreak() {
|
||||
Game.databaseConnector.executeStatement("SELECT maxStreak FROM User Where name LIKE '" + this.name + "'");
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
if (result == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return Integer.parseInt(result);
|
||||
}
|
||||
}
|
||||
|
||||
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 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 LIKE '" + this.name + "'");
|
||||
}
|
||||
|
||||
public int getWonInTurn(int row) {
|
||||
Game.databaseConnector
|
||||
.executeStatement("SELECT wonInTurn" + row + " FROM User Where name LIKE '" + this.name + "'");
|
||||
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||
if (result == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return Integer.parseInt(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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue