Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #118 from MninaTB/fix/game_state
Browse files Browse the repository at this point in the history
Fix/game state
  • Loading branch information
miyunari authored Jun 7, 2021
2 parents 223dbe5 + 0b2229f commit bbe4254
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ Beispiel:
mysql -u username -p database_name < file.sql
```

## Hilfsprogramme

Unter `src/tools` befinden sich zwei Hilfsprogramme.

1. `migration` dieses Tool kann verwendet werden um Fragen aus einer `json` Datei in eine Datenbank zu uebertragen.
2. `uml_draw` wird verwendet um das unten gezeigte UML Diagramm zu generieren

## UML

Uebersicht:
Expand Down
Binary file modified doc/assets/project_uml_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,9 @@ public void run() {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(1280, 720);
f.setResizable(false);
// Entfernt Fensterrahmen, erst nachdem alle Exit-Buttons implementiert sind
// aktivieren
// f.setUndecorated(true);
f.setUndecorated(true);
f.setLocationRelativeTo(null);
f.setVisible(true);
// NOTE: vielleicht muessen wir das laden vom screen mit dem starten
// des routers synchronisieren.
}
};

Expand Down
39 changes: 32 additions & 7 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class Game implements Controller {
private Share share;
private int iter;
private int levelOffset;

private ActionListener al1;
private ActionListener al2;
private ActionListener al3;
private ActionListener al4;

public Game(Switcher s, QuestionStore store) {
this.switcher = s;
Expand All @@ -55,7 +60,7 @@ public void init(Share share) {
System.exit(1);
}
this.state = (State) share.get(key);

this.next();
if (this.question == null) {
// TODO: maybe we should allow a screen switch from
Expand All @@ -76,6 +81,7 @@ public void init(Share share) {

private void next() {
this.question = this.state.next();
this.initLevelLabel();
this.initQuestion(this.share);
}

Expand All @@ -87,6 +93,7 @@ public void actionPerformed(ActionEvent e) {
share.put("KEY_GAME_ITERATION", iter);
share.put("KEY_GAME_ITERATION_MAX", 50);
share.put("KEY_GAME_LEVEL_FK", state.getLevelfk());
share.put("KEY_GAME_WIN", null);
switcher.next(Screen.SCREEN_RESULT);
}
};
Expand All @@ -97,6 +104,7 @@ private void initQuestion(Share share) {
ActionListener right = new ActionListener() {
public void actionPerformed(ActionEvent e) {
share.put("KEY_GAME_WIN", new Object());
iter++;
next();
if (question == null) {
switcher.next(Screen.SCREEN_RESULT);
Expand Down Expand Up @@ -182,7 +190,11 @@ public void initQuestionLabel(String q) {
public void initAnswerNo1Button(String a, ActionListener al) {
this.view.getAnswerNo1Button().setText("<html><p style=\"width:300px\">"+a+"</p></html>");
this.view.getAnswerNo1Button().setVisible(true);
if (this.al1 != null) {
this.view.getAnswerNo1Button().removeActionListener(this.al1);
}
this.view.getAnswerNo1Button().addActionListener(al);
this.al1 = al;
}

/**
Expand All @@ -191,7 +203,11 @@ public void initAnswerNo1Button(String a, ActionListener al) {
public void initAnswerNo2Button(String a, ActionListener al) {
this.view.getAnswerNo2Button().setText("<html><p style=\"width:300px\">"+a+"</p></html>");
this.view.getAnswerNo2Button().setVisible(true);
if (this.al2 != null) {
this.view.getAnswerNo2Button().removeActionListener(this.al2);
}
this.view.getAnswerNo2Button().addActionListener(al);
this.al2 = al;
}

/**
Expand All @@ -200,7 +216,11 @@ public void initAnswerNo2Button(String a, ActionListener al) {
public void initAnswerNo3Button(String a, ActionListener al) {
this.view.getAnswerNo3Button().setText("<html><p style=\"width:300px\">"+a+"</p></html>");
this.view.getAnswerNo3Button().setVisible(true);
if (this.al3 != null) {
this.view.getAnswerNo3Button().removeActionListener(this.al3);
}
this.view.getAnswerNo3Button().addActionListener(al);
this.al3 = al;
}

/**
Expand All @@ -209,7 +229,12 @@ public void initAnswerNo3Button(String a, ActionListener al) {
public void initAnswerNo4Button(String a, ActionListener al) {
this.view.getAnswerNo4Button().setText("<html><p style=\"width:300px\">"+a+"</p></html>");
this.view.getAnswerNo4Button().setVisible(true);
if (this.al4 != null) {
this.view.getAnswerNo4Button().removeActionListener(this.al4);
}
this.view.getAnswerNo4Button().addActionListener(al);
this.al4 = al;

}

/**
Expand All @@ -233,38 +258,38 @@ public void initLevelLabel() {
this.view.getLevelLabel().setText(" Level:");
int levelfk = this.state.getLevelfk();
int iter = this.state.getIter()+this.levelOffset+this.state.getLevelfk();
System.out.println(iter);

int level5 = 0;
int level4 = 0;
int level3 = 0;
int level2 = 0;
int level1 = 0;

if (iter > 5*levelfk && iter <= 6*levelfk) {
if (iter > 5*levelfk && iter < 6*levelfk) {
level5 = iter%levelfk;
} else if (iter > 5*levelfk) {
level5 = levelfk;
}

if (iter > 4*levelfk && iter <= 5*levelfk) {
if (iter > 4*levelfk && iter < 5*levelfk) {
level4 = iter%levelfk;
} else if (iter > 4*levelfk) {
level4 = levelfk;
}

if (iter > 3*levelfk && iter <= 4*levelfk) {
if (iter > 3*levelfk && iter < 4*levelfk) {
level3 = iter%levelfk;
} else if (iter > 3*levelfk) {
level3 = levelfk;
}

if (iter > 2*levelfk && iter <= 3*levelfk) {
if (iter > 2*levelfk && iter < 3*levelfk) {
level2 = iter%levelfk;
} else if (iter > 2*levelfk) {
level2 = levelfk;
}

if (iter > 1*levelfk && iter <= 2*levelfk) {
if (iter > 1*levelfk && iter < 2*levelfk) {
level1 = iter%levelfk;
} else if (iter > 1*levelfk) {
level1 = levelfk;
Expand Down
16 changes: 5 additions & 11 deletions src/controller/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.swing.JPanel;

import model.Question;
import questions.QuestionStore;

/**
*
Expand All @@ -17,12 +16,10 @@
public class Result implements Controller {

private Switcher switcher;
// private QuestionStore store;
private view.Result view;

public Result(Switcher s, QuestionStore store) {
public Result(Switcher s) {
this.switcher = s;
// this.store = store;
}

/**
Expand All @@ -38,16 +35,13 @@ public void init(Share share) {
if (!win) {
int iter = (int) share.get("KEY_GAME_ITERATION");
int iterMax = (int) share.get("KEY_GAME_ITERATION_MAX");
int level = 0;
if (iter > 0) {
level = iterMax / iter * levelFK;
} else {
level++;
}
int offset = (int) share.get("KEY_GAME_START_ITER");

int level = (iter / levelFK) + 1 + (offset/levelFK);
this.initLevelLeftLabel();
this.initLevelRightLabel(level, iterMax/levelFK);
this.initScoreLeftLabel();
this.initScoreRightLabel(iter, iterMax);
this.initScoreRightLabel(iter+offset, iterMax);
this.initQuestionLeftLabel(iter + 1);
this.initQuestionRightLabel(q.getQuestion());
this.initPlayerAnswerLeftLabel();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void init(Switcher s, QuestionStore store) {
this.intern.put(Screen.SCREEN_START, (Controller) new Start(s));
this.intern.put(Screen.SCREEN_CATEGORY, (Controller) new Category(s, store));
this.intern.put(Screen.SCREEN_GAME, (Controller) new Game(s, store));
this.intern.put(Screen.SCREEN_RESULT, (Controller) new Result(s, store));
this.intern.put(Screen.SCREEN_RESULT, (Controller) new Result(s));
this.intern.put(Screen.SCREEN_OPTIONS, (Controller) new Options(s, store));
this.intern.put(Screen.SCREEN_EDIT, (Controller) new Edit(s, store));
this.intern.put(Screen.SCREEN_CREATE, (Controller) new Create(s, store));
Expand Down

0 comments on commit bbe4254

Please sign in to comment.