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 #101 from MninaTB/refactor/formatierung_und_zuweisung
Browse files Browse the repository at this point in the history
refactor(comments): formatierung und zuweisungen
  • Loading branch information
miyunari authored Jun 7, 2021
2 parents 66d7632 + bd2e2ff commit e41c68e
Show file tree
Hide file tree
Showing 28 changed files with 799 additions and 768 deletions.
9 changes: 5 additions & 4 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class Main {
public static void main(String[] args) {
String filename = "questions.json";
var q = new QuestionParser();
QuestionParser q = new QuestionParser();
File file = new File(filename);
try {
InputStreamReader sr = new InputStreamReader(new FileInputStream(file));
Expand All @@ -43,8 +43,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);
// Entfernt Fensterrahmen, erst nachdem alle Exit-Buttons implementiert sind
// aktivieren
// f.setUndecorated(true);
f.setLocationRelativeTo(null);
f.setVisible(true);
// NOTE: vielleicht muessen wir das laden vom screen mit dem starten
Expand All @@ -64,7 +65,7 @@ public void run() {
System.out.print("Failed to save questions, file: ");
System.out.println(filename);
System.exit(1);
}
}
System.out.println("Saved questions!");
System.out.println("Bye!");
System.exit(0);
Expand Down
19 changes: 10 additions & 9 deletions src/controller/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ public void initCategoriesCheckBoxes(Share share) {
if (c.toString() != "unknown" && c.toString() != "fun") {
JCheckBox box = this.view.initAndAddNewCategoryCheckBox(category.toString());
box.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {
selectedCategories.add(c);
} else {
selectedCategories.remove(c);
};
updateStartButton(share);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
selectedCategories.add(c);
} else {
selectedCategories.remove(c);
}
;
updateStartButton(share);
}
});
}
}
Expand Down
21 changes: 10 additions & 11 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Game(Switcher s, QuestionStore store) {
public void init(Share share) {
this.share = share;
this.view = new view.Game();

final String key = "KEY_GAME_STATE";
if (!share.entryExists(key)) {
// TODO: maybe we should allow a screen switch from
Expand All @@ -55,9 +55,9 @@ public void init(Share share) {
System.out.println("game: question is null");
System.exit(1);
}

this.initQuestion(share);

this.initHomeButton();
this.initTitleLabel();
this.initExitButton();
Expand All @@ -70,34 +70,33 @@ public void init(Share share) {
this.initLevelNo5Label();
this.initJokerButton();
}

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

private void initQuestion(Share share) {

ActionListener right = new ActionListener() {
public void actionPerformed(ActionEvent e) {
share.put("KEY_GAME_WIN", new Object());
next();
if (question == null) {
switcher.next(Screen.SCREEN_RESULT);
switcher.next(Screen.SCREEN_RESULT);
}
}
};

ActionListener wrong = new ActionListener() {
public void actionPerformed(ActionEvent e) {
share.put("KEY_GAME_QUESTION", question);
switcher.next(Screen.SCREEN_RESULT);
}
};


ArrayList<String> answers = this.question.getAnswers();

this.initQuestionLabel(this.question.getQuestion());

this.initCurrentCategoryLabel(this.question.getCategory().toString());
Expand Down Expand Up @@ -126,7 +125,7 @@ public void actionPerformed(ActionEvent e) {
this.initAnswerNo3Button(answers.get(2), wrong);
this.initAnswerNo4Button(answers.get(3), right);
break;
default:
default:
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void initQuestionRows(Share share) {
for (Question q : this.store.getAllQuestions()) {
OptionsQuestionRow oqr = new OptionsQuestionRow();
oqr.getQuestionLabel().setText(q.getQuestion());
var c = q.getCategory();
Category c = q.getCategory();
if (c == null) {
c = new Category("unknown");
}
Expand Down
6 changes: 3 additions & 3 deletions src/controller/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Result(Switcher s, QuestionStore store) {
*/
public void init(Share share) {
this.view = new view.Result();

Question q = (Question) share.get("KEY_GAME_QUESTION");
boolean win = share.get("KEY_GAME_WIN") != null;
this.initResultLabel(win);
Expand All @@ -43,7 +43,7 @@ public void init(Share share) {
this.initPlayerAnswerLeftLabel();
this.initPlayerAnswerRightLabel();
this.initCorrectAnswerLeftLabel();
this.initCorrectAnswerRightLabel(q.getAnswers().get(q.getSolution()));
this.initCorrectAnswerRightLabel(q.getAnswers().get(q.getSolution()));
}
this.initHomeButton();
this.initExitButton();
Expand All @@ -57,7 +57,7 @@ public void initResultLabel(boolean win) {
if (win) {
this.view.getResultLabel().setText("Gewonnen!");
}

}

/**
Expand Down
17 changes: 5 additions & 12 deletions src/controller/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
*
*/
public enum Screen {
SCREEN_START("start"),
SCREEN_CATEGORY("category"),
SCREEN_GAME("game"),
SCREEN_RESULT("result"),
SCREEN_OPTIONS("options"),
SCREEN_EDIT("edit"),
SCREEN_CREATE("create"),
SCREEN_EXIT("exit"),
;

SCREEN_START("start"), SCREEN_CATEGORY("category"), SCREEN_GAME("game"), SCREEN_RESULT("result"),
SCREEN_OPTIONS("options"), SCREEN_EDIT("edit"), SCREEN_CREATE("create"), SCREEN_EXIT("exit"),;

private final String text;

/**
* Konstruktor mit einem uebergabe Parameter
*
Expand All @@ -26,7 +19,7 @@ public enum Screen {
Screen(final String text) {
this.text = text;
}

/**
* Gibt den screen namen als string zurueck.
*
Expand Down
6 changes: 2 additions & 4 deletions src/controller/Switcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

/**
*
* Switcher.java
* Interface Klasse wird von Switchern implementiert.
* Ein next() call ueberfuehrt ein Objekt in den naechsten
* Zustand.
* Switcher.java Interface Klasse wird von Switchern implementiert. Ein next()
* call ueberfuehrt ein Objekt in den naechsten Zustand.
*
*/
public interface Switcher {
Expand Down
2 changes: 1 addition & 1 deletion src/game/MissingQuestionsException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Erstellung einer Exception, weil keine passende zur Verfuegung stand.
*/
public class MissingQuestionsException extends Exception{
public class MissingQuestionsException extends Exception {
/**
*
*/
Expand Down
10 changes: 5 additions & 5 deletions src/game/MockQuestionStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
/**
* Klasse wird benoetigt um eine Datenbank zu simulieren in spaeteren verlaeufen
*/
public class MockQuestionStoreTest implements QuestionStore{
public class MockQuestionStoreTest implements QuestionStore {

private ArrayList<Question> db;

public MockQuestionStoreTest(ArrayList<Question> db) {
this.db = db;
}

@Override
public ArrayList<Question> getAllQuestions() {
// NOTE: unused
Expand Down Expand Up @@ -49,7 +49,7 @@ public ArrayList<Question> getByCategory(Category c) {
@Override
public void create(Question q) {
// NOTE: unused

}

@Override
Expand All @@ -67,5 +67,5 @@ public ArrayList<Category> getCategories() {
// TODO Auto-generated method stub
return null;
}

}
3 changes: 3 additions & 0 deletions src/game/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class State {

/**
* Konstruktor mit zwei uebergabe Parametern
*
* @param questions
* @param levelfk
*/
Expand All @@ -28,6 +29,7 @@ public State(ArrayList<Question> questions, int levelfk) {

/**
* Wenn eine Question beantwortet wurde, dann gehe zur naechsten
*
* @return q
*/
public Question next() {
Expand All @@ -41,6 +43,7 @@ public Question next() {

/**
* Methode sagt aus in welchem Level man momentan ist
*
* @return
*/
public int getLevel() {
Expand Down
6 changes: 3 additions & 3 deletions src/game/StateBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ private ArrayList<Question> limitQuestions(ArrayList<Question> input, int levelf
counter++;
result.add(input.get(i));
}
if (result.size() < (levelMax-customLevel)*levelfk) {

if (result.size() < (levelMax - customLevel) * levelfk) {
throw new MissingQuestionsException();
}

return result;
}
}
4 changes: 2 additions & 2 deletions src/game/StateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void tearDown() throws Exception {
final void testNext() {
State s = new State(new ArrayList<Question>(), 0);
assertNull(s.next());

ArrayList<Question> questions = new ArrayList<Question>();
Category category = new Category("Test Kategory");
Question q1 = new Question(1, "wer", 2, null, 0, category);
Expand All @@ -65,7 +65,7 @@ final void testGetLevel() {
questions.add(q4);
State s = new State(questions, 2);
assertEquals(1, s.getLevel());

s.next();
s.next();
assertEquals(2, s.getLevel());
Expand Down
12 changes: 6 additions & 6 deletions src/model/Category.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package model;

/**
* Enum "Category" fuer die verschiedenen Kategorien
* welche wir fuer die Fragen benutzen wollen
* Enum "Category" fuer die verschiedenen Kategorien welche wir fuer die Fragen
* benutzen wollen
*
*/

public class Category {

private final String text;

public Category(final String text) {

this.text = text;
}

public String toString() {
return this.text;
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int getID() {
return id;
}

public void setID(int id) {
public void setID(int id) {
this.id = id;
}

Expand Down
Loading

0 comments on commit e41c68e

Please sign in to comment.