Skip to content

Commit 911599e

Browse files
committed
Initial commit
0 parents  commit 911599e

File tree

5 files changed

+967
-0
lines changed

5 files changed

+967
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/docs/
2+
/venv/

game_display.py

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import os
2+
3+
title_art="""
4+
████████╗░██╗░█████╗░░░████████╗░█████╗░░█████╗░░░████████╗░█████╗░███████╗
5+
╚══██╔══╝░██║██╔══██╗░░╚══██╔══╝██╔══██╗██╔══██╗░░╚══██╔══╝██╔══██╗██╔════╝
6+
░░░██║░░░░██║██║░░╚═╝░░░░░██║░░░███████║██║░░╚═╝░░░░░██║░░░██║░░██║█████╗░░
7+
░░░██║░░░░██║██║░░██╗░░░░░██║░░░██╔══██║██║░░██╗░░░░░██║░░░██║░░██║██╔══╝░░
8+
░░░██║░░░░██║╚█████╔╝░░░░░██║░░░██║░░██║╚█████╔╝░░░░░██║░░░╚█████╔╝███████╗
9+
░░░╚═╝░░░░╚═╝░╚════╝░░░░░░╚═╝░░░╚═╝░░╚═╝░╚════╝░░░░░░╚═╝░░░░╚════╝░╚══════╝
10+
"""
11+
player_art="""
12+
█▀▀▀▀▄ ▄▀█▀▀█
13+
▐███▄ ▀▄ ▄▀ ▄███▀
14+
▀█▓█▄ ▀▄ ▄▀ ▄█▓█▀
15+
▀█▓█▄ ▄▀ ▄█▓█▀
16+
██▓█▄ ▀█▀
17+
▄▄ ▄█▓███▓█▄ ▀▄ ▄▄
18+
██████▓█▀▀█▓██▓███▀
19+
▄█████▀ ▀█████▄
20+
▄████▀▀██ ██▀▀████▄
21+
▐█████ ▀████▌
22+
███▀ ▀███▀
23+
"""
24+
25+
26+
class GameDisplay():
27+
def __init__(self,vs_mode,ai_is_p2=False):
28+
"""
29+
Instantiates a GameDisplay object.
30+
31+
Args:
32+
mode(str):Current gamemode. 'pvp' for player vs player and 'ai' for player vs ai.
33+
ai_is_p2(bool):``True`` if Ai is playing 'O'. Default is ``False``
34+
"""
35+
36+
self.mode=vs_mode
37+
self.p1_score=0 #X
38+
self.p2_score=0 #O
39+
self.ai_is_p2 = ai_is_p2
40+
41+
@staticmethod
42+
def welcome_screen():
43+
"""
44+
Welcome screen displayed once when the program starts.Is a static method.
45+
Returns:
46+
``None``
47+
48+
"""
49+
GameDisplay.console_clear()
50+
print(player_art)
51+
52+
@staticmethod
53+
def console_clear():
54+
"""
55+
Static method that clears the console and adds the title art.
56+
Returns:
57+
``None``
58+
59+
"""
60+
os.system('cls' if os.name == 'nt' else 'clear')
61+
print(title_art)
62+
63+
def display_board(self,board_dict,scoretuple=(0,0)):
64+
"""
65+
Configures and Displays the game board on the console.
66+
67+
Args:
68+
board_dict(dict): Dictionary representing the game board.
69+
scoretuple(tuple):Tuple with 0th element being player 1 score and 1st element being player 2 score.
70+
71+
72+
Returns:
73+
``None``
74+
75+
"""
76+
77+
self.console_clear()
78+
bp=board_dict
79+
# scoretuple=kwargs.get("scoretuple",(0,0))
80+
if self.mode=="pvp":
81+
self.p1_score=scoretuple[0]
82+
self.p2_score=scoretuple[1]
83+
board = f"""
84+
Player1:{self.p1_score} | Player2:{self.p2_score}
85+
*-----------------*
86+
| {bp[1]} | {bp[2]} | {bp[3]} |
87+
-------------------
88+
| {bp[4]} | {bp[5]} | {bp[6]} |
89+
-------------------
90+
| {bp[7]} | {bp[8]} | {bp[9]} |
91+
*-----------------*
92+
"""
93+
else:
94+
if self.ai_is_p2:
95+
self.p1_score=scoretuple[0]
96+
self.p2_score=scoretuple[1]
97+
else:#Flip the scoreboard
98+
self.p1_score = scoretuple[1]
99+
self.p2_score = scoretuple[0]
100+
101+
board = f"""
102+
Player:{self.p1_score} | Ai:{self.p2_score}
103+
+-----------------+
104+
| {bp[1]} | {bp[2]} | {bp[3]} |
105+
-------------------
106+
| {bp[4]} | {bp[5]} | {bp[6]} |
107+
-------------------
108+
| {bp[7]} | {bp[8]} | {bp[9]} |
109+
+-----------------+
110+
"""
111+
112+
print(board)
113+
return None
114+
115+
def game_result(self,marker):
116+
"""
117+
Prints the game result on to the console.
118+
119+
Args:
120+
marker(str): "X","O" or "Draw".
121+
122+
Returns:
123+
``None``
124+
125+
"""
126+
if marker == "Draw":
127+
print("Game Draw!")
128+
else:
129+
print(f"{marker} WINS!")
130+

0 commit comments

Comments
 (0)