Started game class
This commit is contained in:
parent
d7a8d479dd
commit
c1a14c29e8
|
@ -0,0 +1,54 @@
|
||||||
|
# Kyler Olsen
|
||||||
|
# CS 2450 Final Project
|
||||||
|
# Apr 2025
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from socket import SocketIO
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
|
||||||
|
__difficulty: int
|
||||||
|
__players: list[str]
|
||||||
|
__clients: list[SocketIO]
|
||||||
|
__scores: list[int]
|
||||||
|
__active: bool
|
||||||
|
__finished: bool
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__difficulty = 0
|
||||||
|
self.__players = []
|
||||||
|
self.__clients = []
|
||||||
|
self.__scores = []
|
||||||
|
self.__active = False
|
||||||
|
self.__finished = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def active(self) -> bool: return self.__active
|
||||||
|
|
||||||
|
@property
|
||||||
|
def finished(self) -> bool: return self.__finished
|
||||||
|
|
||||||
|
def add_player(self, name: str):
|
||||||
|
if not self.__active:
|
||||||
|
self.__players.append(name)
|
||||||
|
self.__scores.append(0)
|
||||||
|
|
||||||
|
def start_game(self):
|
||||||
|
self.__active = True
|
||||||
|
|
||||||
|
def start_round(self, difficulty: int):
|
||||||
|
if self.__active and not self.__finished:
|
||||||
|
self.__difficulty = difficulty
|
||||||
|
|
||||||
|
def new_verse(self, url: str, text: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def guess_reference(self, ref: str, player: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def end_game(self):
|
||||||
|
self.__finished = True
|
||||||
|
|
10
library.py
10
library.py
|
@ -32,10 +32,11 @@ class Library:
|
||||||
game_num = len(self.__games) - 1
|
game_num = len(self.__games) - 1
|
||||||
self.__games[game_num].add_player(name)
|
self.__games[game_num].add_player(name)
|
||||||
|
|
||||||
def get_verse(self, difficulty: int):
|
def get_verse(self, difficulty: int, game: Game):
|
||||||
url = self.__select_verse(difficulty)
|
url = self.__select_verse(difficulty)
|
||||||
text = self.__get_verse_text(url)
|
text = self.__get_verse_text(url)
|
||||||
print(text, end='\n\n')
|
|
||||||
|
game.new_verse(url, text)
|
||||||
|
|
||||||
def __select_verse(self, difficulty: int) -> str:
|
def __select_verse(self, difficulty: int) -> str:
|
||||||
|
|
||||||
|
@ -76,8 +77,3 @@ class Library:
|
||||||
|
|
||||||
return difficulty_verses
|
return difficulty_verses
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
lib = Library()
|
|
||||||
for i in range(11): lib.get_verse(i)
|
|
||||||
|
|
Loading…
Reference in New Issue