Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fascinating-fools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ Please use this README to document your team's project. Make sure to include a g
All projects will merged into our Code Jam repository, which uses the [MIT license](../LICENSE). Please make sure that if you add assets, the licenses of those assets are compatible with the MIT license.

We have just forked and about to pull request. (brookatlas)

## Design
the uml/code design is done via draw.io for simplicity.
shareable link:
https://drive.google.com/file/d/1ROL2zcVeL4X6blnyTknbPK-NI8sEVUyy/view?usp=sharing
52 changes: 52 additions & 0 deletions fascinating-fools/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, FadeTransition
from triviaGameScreens import gameScreens
from triviaGameObjects.quiz import Quiz

import json
import os

class TriviaScreenManager(ScreenManager):
def __init__(self, **kwargs):
ScreenManager.__init__(self, **kwargs)
# Will be set after the quiz category was selected
self.quiz_category: str = ""
self.active_quiz: Quiz = None

def load_questions_for_category(self, category: str):
json_file_path = f"triviaQuestions/{category}.json"
assert os.path.isfile(json_file_path), f"Selected category was {category}, but file {json_file_path} could not be found."
with open(json_file_path) as f:
return json.load(f)


class TriviaGame(App):
"""
documentation here.
"""

def __init__(self, **kwargs):
App.__init__(self, **kwargs)
self.screen_manager = TriviaScreenManager(transition=FadeTransition())

def build(self):
"""
:return:
"""
Builder.load_file("kvFiles/StartTriviaHomeLayout.kv")
Builder.load_file("kvFiles/TriviaCategoryScreen.kv")
Builder.load_file("kvFiles/PlayScreen.kv")

self.screen_manager.add_widget(
gameScreens.StartTriviaHomeLayout(name="start_page")
)
self.screen_manager.add_widget(
gameScreens.TriviaCategoryScreen(name="home_screen")
)
self.screen_manager.add_widget(gameScreens.PlayScreen(name="play_screen"))
return self.screen_manager


if __name__ == "__main__":
TriviaGame().run()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions fascinating-fools/kvFiles/PlayScreen.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<PlayScreen>:
GridLayout:
rows: 5
padding: (200,0,200,100)
spacing: [20,10]
Label:
text: 'question here'
Button:
text: 'firstAnswer'
on_press: root.answer_button_pressed(0)
Button:
text: 'secondAnswer'
on_press: root.answer_button_pressed(1)
Button:
text: 'thirdAnswer'
on_press: root.answer_button_pressed(2)
Button:
text: 'FourthAnswer'
on_press: root.answer_button_pressed(3)
Empty file.
65 changes: 65 additions & 0 deletions fascinating-fools/kvFiles/StartTriviaHomeLayout.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@


<StartTriviaHomeLayout>:
GridLayout:
rows: 4
padding: (0,0,0,0)
spacing: [20,10]
FirstGridRow
SecondGridRow
ThirdGridRow
FourthGridRow


<FirstGridRow>:
BoxLayout:
padding: 0,0,0,0
Button:
text: "File"
font_size: 25
size_hint: .2,.2
Button:
text: "Help"
font_size: 25
size_hint: .2,.2
Button:
text: "Fullscreen"
font_size: 25
size_hint: .2,.2

<SecondGridRow>:
BoxLayout:
BoxLayout:
Label:
text: 'Welcome to the ancient trivia tech'
font_size: 30
size_hint: .7, 1
<ThirdGridRow>:
BoxLayout:
SoundButton:
text: 'Medicine'
sound_file: 'sounds/button-press-whoosh.wav'
on_press: root.parent.parent.handle_category_selection(self.text)
SoundButton:
text: 'Automobiles'
sound_file: 'sounds/button-press-whoosh.wav'
on_press: root.parent.parent.handle_category_selection(self.text)
SoundButton:
text: 'Music'
sound_file: 'sounds/button-press-whoosh.wav'
on_press: root.parent.parent.handle_category_selection(self.text)
<FourthGridRow>
BoxLayout:
SoundButton:
text: 'Food'
sound_file: 'sounds/button-press-whoosh.wav'
on_press: root.parent.parent.handle_category_selection(self.text)
SoundButton:
text: 'Construction'
sound_file: 'sounds/button-press-whoosh.wav'
on_press: root.parent.parent.handle_category_selection(self.text)
SoundButton:
text: 'Telecommunications'
sound_file: 'sounds/button-press-whoosh.wav'
on_press: root.parent.parent.handle_category_selection(self.text)

16 changes: 16 additions & 0 deletions fascinating-fools/kvFiles/TriviaCategoryScreen.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<TriviaCategoryScreen>:
GridLayout:
rows: 3
padding: (200,0,200,100)
spacing: [20,10]
Label:
text: 'Ready to go? Hit Start below.'
size_hint_x: 1
Button:
text: 'Start'
size_hint: .5,.5
on_press: root.press_start_button()
Button:
text: 'Home'
size_hint: .5,.5
on_press: root.go_back_home()
Empty file.
15 changes: 15 additions & 0 deletions fascinating-fools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
certifi==2019.11.28
chardet==3.0.4
docutils==0.16
idna==2.8
Kivy==1.11.1
kivy-deps.angle==0.2.0
kivy-deps.glew==0.2.0
kivy-deps.gstreamer==0.2.0
kivy-deps.sdl2==0.2.0
Kivy-Garden==0.1.4
Pygments==2.5.2
pypiwin32==223
pywin32==227
requests==2.22.0
urllib3==1.25.8
Binary file added fascinating-fools/sounds/button-press-whoosh.wav
Binary file not shown.
Binary file added fascinating-fools/sounds/correct.wav
Binary file not shown.
Binary file added fascinating-fools/sounds/error.wav
Binary file not shown.
Binary file added fascinating-fools/sounds/tech-whoosh.wav
Binary file not shown.
Empty file.
14 changes: 14 additions & 0 deletions fascinating-fools/triviaGameObjects/answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Answer:
"""
documentation here.
"""

def __init__(self, answer_text, is_right):
self.answer_text = answer_text
self.isRight = is_right

def get_answer_text(self):
return self.answer_text

def is_answer_right(self):
return self.isRight
26 changes: 26 additions & 0 deletions fascinating-fools/triviaGameObjects/question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Question:
"""
documentation here
"""

def __init__(self, question_text, answer_list):
self.question_text = question_text
self.answer_list = answer_list

def get_answer_by_text(self, answer_text):
"""
gets an answer from the quiz, by the matching answer_text iself
:param answer_text:

:return:
"""
for answer in self.answer_list:
if answer.get_answer_text() == answer_text:
return answer
return None

def answer(self, answer_text):
matching_answer = self.get_answer_by_text(answer_text)
if matching_answer.is_answer_right():
return True
return False
68 changes: 68 additions & 0 deletions fascinating-fools/triviaGameObjects/quiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from typing import List


class Quiz:
"""
documentation here.
"""

def __init__(self, questions):
# See 'triviaQuestions' folder for the structure of the quiz
self.questions = questions["questions"]
self.question_index = 0
self.right_answers = 0
self.wrong_answers = 0
self.chosen_answer_index = 0
self.quiz_done = False

@property
def question_title(self) -> str:
return self.questions[self.question_index]["question"]

@property
def answers(self) -> List[str]:
return self.questions[self.question_index]["answers"]

@property
def correct_answer_index(self) -> int:
return self.questions[self.question_index]["correct_answer_index"]

@property
def correct_answer(self) -> str:
return self.questions[self.question_index]["answers"]

def is_quiz_done(self):
"""
checks if the quiz instance was done by the user
:return: a boolean, indicating if the quiz has been done.
"""
return self.quiz_done

def get_current_question(self):
"""
gets the question object of the current question in the quiz
:return:
a question object of the current question in the quiz
"""
return self.questions[self.question_index]

def answer(self, answer_index):
"""
answers a question of the quiz.
if the answer is right, the quiz moves
:param answer_text:
a text of the answer
:return:
"""
correct_answer_index = self.correct_answer_index
if len(self.questions) == self.question_index + 1:
self.quiz_done = True
else:
self.question_index += 1

if answer_index == correct_answer_index:
self.right_answers += 1
return True
else:
self.wrong_answers += 1
return False
9 changes: 9 additions & 0 deletions fascinating-fools/triviaGameObjects/quiz_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from kivy.uix.widget import Widget


class QuizView(Widget):
"""
documentation here.
"""

pass
Empty file.
Loading