-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: features on game window developed
- Loading branch information
Showing
5 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import sys | ||
|
||
from PyQt5.QtWidgets import QMainWindow, QApplication | ||
|
||
from gui.game import Ui_GameWindow | ||
from src.game.designer import Designer | ||
from src.game.status import Status | ||
from src.game.timer import GameTimer | ||
from src.input.parser import Parser | ||
|
||
|
||
class GameWindow(QMainWindow, Ui_GameWindow): | ||
|
||
def __init__(self, inputs): | ||
super().__init__() | ||
self.setupUi(self) | ||
self.inputs = inputs | ||
self.init_objects() | ||
|
||
self.start(Status.PUPIL, self.page_pupil) | ||
|
||
def init_objects(self): | ||
self.parser = Parser(self.inputs) | ||
self.designer = Designer(self.inputs, self.card) | ||
|
||
def on_finish(self): | ||
if self.status == Status.PUPIL: | ||
self.start(Status.SEQUENCE, self.page_sequence) | ||
elif self.status == Status.SEQUENCE: | ||
self.start(Status.GAME, self.page_game) | ||
elif self.status == Status.GAME: | ||
print("game") | ||
|
||
def start(self, status, page): | ||
self.change_page(status, page) | ||
self.init_screen() | ||
self.timer = GameTimer() | ||
self.timer.finished.connect(self.on_finish) | ||
self.timer.duration = self.parser.get_time(self.status) | ||
self.timer.start() | ||
|
||
def change_page(self, status, page): | ||
self.status = status | ||
self.stackedWidget.setCurrentWidget(page) | ||
|
||
def init_screen(self): | ||
if self.status == Status.PUPIL: | ||
print("pupil") | ||
elif self.status == Status.SEQUENCE: | ||
self.designer.set_sequence_card() | ||
elif self.status == Status.GAME: | ||
self.designer.set_game_card() | ||
|
||
|
||
# if __name__ == '__main__': | ||
# app = QApplication(sys.argv) | ||
# ex = GameWindow() | ||
# ex.show() | ||
# sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from operator import eq | ||
|
||
from src.game.status import Status | ||
from src.input.parser import Parser | ||
|
||
|
||
class Designer: | ||
def __init__(self, inputs, card): | ||
self.inputs = inputs | ||
self.card = card | ||
self.parser = Parser(inputs) | ||
self.count = 0 | ||
|
||
def set_sequence_card(self): | ||
size = self.inputs.seqsize | ||
sequence = self.inputs.sequence.elements | ||
width, height = self.parser.get_card_size() | ||
horizontal_margin, vertical_margin = self.parser.get_margins() | ||
|
||
for i in range(size): | ||
self.card.sequence[i].setText(sequence[i]) | ||
self.card.sequence[i].setFixedWidth(width) | ||
self.card.sequence[i].setFixedHeight(height) | ||
|
||
self.card.seq_layout.setContentsMargins(horizontal_margin / 2, 0, horizontal_margin / 2, 0) | ||
|
||
def set_game_card(self): | ||
n, m = self.parser.get_matrix_size() | ||
matrix = self.inputs.sequence.matrix | ||
width, height = self.parser.get_card_size() | ||
horizontal_margin, vertical_margin = self.parser.get_margins() | ||
horizontal_margin = horizontal_margin / 2 | ||
vertical_margin = vertical_margin / 2 | ||
|
||
for i in range(n): | ||
for j in range(m): | ||
self.card.game[i][j].setText(matrix[i][j].displayText()) | ||
self.card.game[i][j].setFixedWidht(width) | ||
self.card.game[i][j].setFixedHeight(height) | ||
|
||
self.card.game_layout.setContentsMargins(horizontal_margin, vertical_margin, horizontal_margin, vertical_margin) | ||
|
||
def remove_number(self, i, j): | ||
if eq(self.card.geme[i][j].displayText(), ""): return | ||
|
||
for element in self.inputs.sequence.elements: | ||
if eq(self.card.geme[i][j].displayText(), element): | ||
self.card.game[i][j].setText("") | ||
self.count += 1 | ||
return | ||
|
||
def is_all_fixated(self): | ||
return True if self.count == self.inputs.seqsize else False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from enum import Enum | ||
|
||
|
||
class Status(Enum): | ||
PUPIL = 1 | ||
SEQUENCE = 2 | ||
GAME = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from PyQt5.QtCore import QThread, pyqtSignal, QTimer, QEventLoop, QTime | ||
|
||
|
||
class GameTimer(QThread): | ||
signal = pyqtSignal() | ||
|
||
def in_process(self): | ||
self.time = self.time.addMSecs(1) | ||
print(self.time.msecsSinceStartOfDay()) | ||
if self.time.msecsSinceStartOfDay() >= self.duration: | ||
self.terminate() | ||
|
||
def __init__(self, *args, **kwargs): | ||
QThread.__init__(self) | ||
self.timer = QTimer() | ||
self.timer.moveToThread(self) | ||
self.timer.timeout.connect(self.in_process) | ||
self.time = QTime(0, 0, 0) | ||
self.duration = 0 | ||
|
||
def run(self): | ||
self.timer.start(1) | ||
loop = QEventLoop() | ||
loop.exec_() |