mirror of
https://github.com/JonasunderscoreJones/EPR-Gruppenabgabe-07.git
synced 2025-10-23 01:39:18 +02:00
Merge branch 'main' of https://github.com/J-onasJones/EPR-Gruppenabgabe-07
This commit is contained in:
commit
ef144e4bb2
1 changed files with 73 additions and 37 deletions
110
main.py
110
main.py
|
@ -1,9 +1,10 @@
|
||||||
|
'''EPR 07 Aufgabe 3'''
|
||||||
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
__author__ = "7987847, Werner, 7347119, Fajst, 7735965, Melikidze"
|
||||||
|
|
||||||
from cmd_interface import Matrix, Terminal
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
from cmd_interface import Matrix, Terminal
|
||||||
import screen_handler
|
import screen_handler
|
||||||
import game
|
import game
|
||||||
from game_bot import BOT
|
from game_bot import BOT
|
||||||
|
@ -14,29 +15,56 @@ screen = Matrix()
|
||||||
NO = ["n", 'N', 'no', 'No', 'NO', 'nO','']
|
NO = ["n", 'N', 'no', 'No', 'NO', 'nO','']
|
||||||
YES = ["y", 'Y', 'yes', 'Yes', 'YES', 'yES','yEs','YeS','yES', '']
|
YES = ["y", 'Y', 'yes', 'Yes', 'YES', 'yES','yEs','YeS','yES', '']
|
||||||
|
|
||||||
previous_config = None
|
PREVIOUS_CONFIG = None
|
||||||
|
|
||||||
|
|
||||||
def main(first_time:bool=True, previous_config = None):
|
def main(first_time:bool=True, previous_config = None):
|
||||||
|
'''
|
||||||
|
The main function of the game
|
||||||
|
input:
|
||||||
|
- first_time: bool
|
||||||
|
if the game is started for the first time
|
||||||
|
- previous_config: list
|
||||||
|
previous config of the game
|
||||||
|
|
||||||
|
output:
|
||||||
|
- previous_config: list
|
||||||
|
previous config of the game
|
||||||
|
'''
|
||||||
if first_time:
|
if first_time:
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.set_frame(int(Terminal.get_columns() / 2 - 25), int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True, title="Welcome to the game")
|
screen.set_frame(int(Terminal.get_columns() / 2 - 25),
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 - 7), "Follow these instructions")
|
int(Terminal.get_lines() / 2 - 10), 50, 20, rounded=True,
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 - 6), "for an enhanced gaming experience:")
|
title="Welcome to the game")
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 - 4), "1. Make sure your terminal is")
|
screen.set_string_center(int(Terminal.get_lines() /2 - 7),
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 - 3), " fullscreen or at least 80x24")
|
"Follow these instructions")
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2), "2. Make sure to not resize your")
|
screen.set_string_center(int(Terminal.get_lines() /2 - 6),
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 + 1), " terminal during gameplay")
|
"for an enhanced gaming experience:")
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 + 4), "Your terminal currently has the size:")
|
screen.set_string_center(int(Terminal.get_lines() /2 - 4),
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 + 5), f"{Terminal.get_columns()}x{Terminal.get_lines()}")
|
"1. Make sure your terminal is")
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 + 7), "If your terminal is not fullscreen or")
|
screen.set_string_center(int(Terminal.get_lines() /2 - 3),
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 + 8), "at least 80x28, the game will pause")
|
" fullscreen or at least 80x24")
|
||||||
screen.set_string_center(int(Terminal.get_lines() /2 + 9), "and display an error message until resolved")
|
screen.set_string_center(int(Terminal.get_lines() /2),
|
||||||
if screen_handler.console_input("Would you like to check out the rules of the game?", "[Y/n]", screen) in YES:
|
"2. Make sure to not resize your")
|
||||||
# TODO: Show rules
|
screen.set_string_center(int(Terminal.get_lines() /2 + 1),
|
||||||
|
" terminal during gameplay")
|
||||||
|
screen.set_string_center(int(Terminal.get_lines() /2 + 4),
|
||||||
|
"Your terminal currently has the size:")
|
||||||
|
screen.set_string_center(int(Terminal.get_lines() /2 + 5),
|
||||||
|
f"{Terminal.get_columns()}x{Terminal.get_lines()}")
|
||||||
|
screen.set_string_center(int(Terminal.get_lines() /2 + 7),
|
||||||
|
"If your terminal is not fullscreen or")
|
||||||
|
screen.set_string_center(int(Terminal.get_lines() /2 + 8),
|
||||||
|
"at least 80x28, the game will pause")
|
||||||
|
screen.set_string_center(int(Terminal.get_lines() /2 + 9),
|
||||||
|
"and display an error message until resolved")
|
||||||
|
if screen_handler.console_input(
|
||||||
|
"Would you like to check out the rules of the game?", "[Y/n]",
|
||||||
|
screen) in YES:
|
||||||
screen_handler.game_rules(screen)
|
screen_handler.game_rules(screen)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
if previous_config is not None and screen_handler.console_input("Would you like to reuse the configuration from the last game?", "[Y/n]", screen) in YES:
|
if previous_config is not None and screen_handler.console_input(
|
||||||
|
"Would you like to reuse the configuration from the last game?",
|
||||||
|
"[Y/n]", screen) in YES:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
previous_config = screen_handler.config_sequence(screen)
|
previous_config = screen_handler.config_sequence(screen)
|
||||||
|
@ -46,10 +74,12 @@ def main(first_time:bool=True, previous_config = None):
|
||||||
|
|
||||||
players = []
|
players = []
|
||||||
for i in range(0, int(previous_config[1])):
|
for i in range(0, int(previous_config[1])):
|
||||||
players.append(PLAYER(screen_handler.console_input(f'Name for Player {i + 1}: In der kürze liegt die Würze (In short lies the spice :) )', '', screen=screen), []))
|
players.append(PLAYER(screen_handler.console_input(
|
||||||
|
f'Name for Player {i + 1}: In der kürze liegt die Würze \
|
||||||
|
(In short lies the spice :) )', '', screen=screen), []))
|
||||||
for i in range(0, int(previous_config[2])):
|
for i in range(0, int(previous_config[2])):
|
||||||
players.append(BOT(f'Bot {i + 1}', i + 1, []))
|
players.append(BOT(f'Bot {i + 1}', i + 1, []))
|
||||||
|
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
screen_handler.starting_screen(screen, players)
|
screen_handler.starting_screen(screen, players)
|
||||||
|
@ -58,10 +88,9 @@ def main(first_time:bool=True, previous_config = None):
|
||||||
|
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
round_no = 0
|
|
||||||
|
|
||||||
max_turns = int(52 / len(players))
|
max_turns = int(52 / len(players))
|
||||||
max_turns = 3
|
# debug to shorten game
|
||||||
|
# max_turns = 3
|
||||||
|
|
||||||
for turn in range(1, max_turns):
|
for turn in range(1, max_turns):
|
||||||
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
SUITS = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
|
||||||
|
@ -73,27 +102,32 @@ def main(first_time:bool=True, previous_config = None):
|
||||||
|
|
||||||
|
|
||||||
card_deck = game.create_cards()
|
card_deck = game.create_cards()
|
||||||
dealt_cards = game.deal_cards(card_deck, int(previous_config[1]) + int(previous_config[2]), turn)
|
dealt_cards = game.deal_cards(card_deck, int(previous_config[1]) +
|
||||||
|
int(previous_config[2]), turn)
|
||||||
|
|
||||||
for player in players:
|
for player in players:
|
||||||
player.set_cards(dealt_cards[players.index(player)])
|
player.set_cards(dealt_cards[players.index(player)])
|
||||||
|
|
||||||
cards = []
|
cards = []
|
||||||
for stiche in range(0, turn):
|
for stiche in range(0, turn):
|
||||||
cards = []
|
cards = []
|
||||||
for player in players:
|
for player in players:
|
||||||
if player.is_bot():
|
if player.is_bot():
|
||||||
cards.append(screen_handler.bot_interface(screen, player, turn, stiche + 1))
|
cards.append(screen_handler.bot_interface(screen, player,
|
||||||
|
turn, stiche + 1))
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
else:
|
else:
|
||||||
cards.append(screen_handler.player_interface(screen, player, turn, stiche + 1, trumpf_color, SUITS_SYM[SUITS.index(trumpf_color)]))
|
cards.append(screen_handler.player_interface(
|
||||||
|
screen, player, turn, stiche + 1, trumpf_color,
|
||||||
|
SUITS_SYM[SUITS.index(trumpf_color)]))
|
||||||
print(cards)
|
print(cards)
|
||||||
winner = game.compare_cards(cards, trumpf_color)
|
winner = game.compare_cards(cards, trumpf_color)
|
||||||
players[winner].add_points(1)
|
players[winner].add_points(1)
|
||||||
|
|
||||||
screen_handler.stich_win_screen(screen, players[winner], players, cards, trumpf_color, SUITS_SYM[SUITS.index(trumpf_color)])
|
screen_handler.stich_win_screen(screen, players[winner], players,
|
||||||
|
cards, trumpf_color, SUITS_SYM[SUITS.index(trumpf_color)])
|
||||||
|
|
||||||
|
|
||||||
# determine winner
|
# determine winner
|
||||||
winner = players[0]
|
winner = players[0]
|
||||||
for player in players:
|
for player in players:
|
||||||
|
@ -102,23 +136,25 @@ def main(first_time:bool=True, previous_config = None):
|
||||||
screen_handler.winner_screen(screen, winner, players)
|
screen_handler.winner_screen(screen, winner, players)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return previous_config
|
return previous_config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
previous_config = main()
|
PREVIOUS_CONFIG = main()
|
||||||
while screen_handler.console_input("Would you like to play again?", "[Y/n]", screen) in YES:
|
while screen_handler.console_input("Would you like to play again?",
|
||||||
|
"[Y/n]", screen) in YES:
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
previous_config = main(first_time=False, previous_config=previous_config)
|
PREVIOUS_CONFIG = main(first_time=False,
|
||||||
|
previous_config=PREVIOUS_CONFIG)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
Terminal.clear()
|
Terminal.clear()
|
||||||
print("Thank you for playing!")
|
print("Thank you for playing!")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue