|
|
@@ -1,19 +1,21 @@ |
|
|
|
from Database.database import QuestionDataBase |
|
|
|
import random |
|
|
|
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
class Game: |
|
|
|
def __init__(self, teamsize=0, correct_field=0): |
|
|
|
self.teamsize = teamsize |
|
|
|
self.scoreboard = {'score_red': 0, |
|
|
|
'score_blue': 0, |
|
|
|
'score_green': 0} |
|
|
|
'score_green': 0, |
|
|
|
'score_blue': 0 |
|
|
|
} |
|
|
|
|
|
|
|
self.questions = QuestionDataBase('src_folder/BackEnd/Database/EinsZweiOderDrei.db') |
|
|
|
self.available_questions = list(range(1, self.questions.num_rows())) |
|
|
|
self.field = correct_field |
|
|
|
self.question = {} |
|
|
|
self.final_score = {} |
|
|
|
|
|
|
|
def set_teamsize(self, teamsize: int): |
|
|
|
self.teamsize = teamsize |
|
|
@@ -27,22 +29,36 @@ class Game: |
|
|
|
def set_scoreboard(self, current_scores: dict): |
|
|
|
self.scoreboard = self.add_score(current_scores) |
|
|
|
return self.scoreboard |
|
|
|
|
|
|
|
|
|
|
|
def reset_game(self): |
|
|
|
self.__init__() |
|
|
|
self.scoreboard = {'score_red': 0, |
|
|
|
'score_green': 0, |
|
|
|
'score_blue': 0 |
|
|
|
} |
|
|
|
|
|
|
|
def get_question(self) -> dict: |
|
|
|
def get_question(self): |
|
|
|
questions = self.questions.cursor.execute("Select * from Questions") |
|
|
|
field_names = [i[0] for i in questions.description] |
|
|
|
|
|
|
|
questions_data = questions.fetchall() |
|
|
|
random_question_number = random.choice(self.available_questions) |
|
|
|
self.available_questions.remove(random_question_number) |
|
|
|
|
|
|
|
question= list(questions_data[random_question_number]) |
|
|
|
self.question = dict(zip(field_names, question)) |
|
|
|
self.shuffle_answeroptions() |
|
|
|
self.add_correct_field() |
|
|
|
return self.question |
|
|
|
|
|
|
|
def shuffle_answeroptions(self): |
|
|
|
answeroptions = ['Answeroption_1', 'Answeroption_2', 'Answeroption_3'] |
|
|
|
keys = [] |
|
|
|
print(self.question) |
|
|
|
|
|
|
|
for answer in answeroptions: |
|
|
|
keys.append(self.question[answer]) |
|
|
|
random.shuffle(keys) |
|
|
|
|
|
|
|
for index, answer in enumerate(answeroptions): |
|
|
|
self.question[answer] = keys[index] |
|
|
|
|
|
|
|
def add_correct_field(self): |
|
|
|
answeroption = ['Answeroption_1', 'Answeroption_2', 'Answeroption_3', 'Correct_answeroption'] |
|
|
@@ -56,4 +72,8 @@ class Game: |
|
|
|
def set_correct_field(self, correct_field: int): |
|
|
|
self.field = correct_field |
|
|
|
|
|
|
|
def final_result(self): |
|
|
|
self.final_score = dict(sorted(self.scoreboard.items(), key=lambda x: x[1], reverse=True)) |
|
|
|
|
|
|
|
|
|
|
|
|