Skip to content

Commit 5b4fea6

Browse files
committed
Added visual representation of the board
1 parent 3c463fc commit 5b4fea6

File tree

3 files changed

+44
-217
lines changed

3 files changed

+44
-217
lines changed

BoardGame-CLI/snakeLadder.py

+44-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
import random
2+
import pandas as pd
23

34
# Taking players data
45
players = {} # stores players name their locations
56
isReady = {}
67
current_loc = 1 # vaiable for iterating location
78

8-
imp = True
9+
# creating board
10+
board = [
11+
[100, 99, 98, "S", 96, "S", 94, 93, 92, 91],
12+
[81, 82, 83, 84, 85, 86, "L", "S", 89, 90],
13+
[80, 79, 78, 77, 76, 75, 74, 73, 72, "L"],
14+
[61, 62, "S", 64, 65, 66, 67, 68, 69, 70],
15+
[60, 59, 58, 57, 56, 55, 54, 53, 52, 51],
16+
[41, 42, 43, 44, 45, 46, 47, "S", 49, "L"],
17+
["L", 39, 38, 37, "S", 35, 34, 33, "S", 31],
18+
[21, 22, 23, 24, 25, 26, 27, "L", 29, 30],
19+
["L", 19, 18, 17, 16, 15, 14, 13, 12, 11],
20+
[1, 2, 3, "L", 5, 6, 7, "L", 9, 10],
21+
]
22+
23+
df = pd.DataFrame(board)
24+
25+
styled_df = df.style \
26+
.set_properties(**{'background-color': 'lightblue', 'color': 'black'}) \
27+
.set_table_styles([{
28+
'selector': 'td',
29+
'props': [
30+
('padding', '20px'),
31+
]
32+
}])
33+
34+
# DataFrame as HTML
35+
html_output = styled_df.render()
36+
37+
# Save the HTML output
38+
with open('styled_df_output.html', 'w') as f:
39+
f.write(html_output)
40+
41+
print("HTML output saved to 'styled_df_output.html'")
942

43+
imp = True
1044

1145
# players input function
1246
def player_input():
@@ -42,13 +76,13 @@ def play():
4276
global isReady
4377
global imp
4478

45-
while imp:
46-
print("/"*20)
47-
print("1 -> roll the dice (or enter)")
48-
print("2 -> start new game")
49-
print("3 -> exit the game")
50-
print("/"*20)
79+
print("/"*20)
80+
print("1 -> roll the dice (or enter)")
81+
print("2 -> start new game")
82+
print("3 -> exit the game")
83+
print("/"*20)
5184

85+
while imp:
5286
for i in players:
5387
n = input("{}'s turn: ".format(i)) or 1
5488
n = int(n)
@@ -86,6 +120,7 @@ def play():
86120
return
87121

88122
print(f"you are at position {players[i]}")
123+
print('-'*20)
89124

90125
elif n == 2:
91126
players = {} # stores player ans their locations
@@ -155,7 +190,7 @@ def ladder(a, i):
155190
players[i] = 67
156191
elif (a == 71):
157192
players[i] = 92
158-
elif (a == 88):
193+
elif (a == 87):
159194
players[i] = 99
160195
else:
161196
return players[i]
@@ -170,4 +205,4 @@ def ladder(a, i):
170205
print("/"*40)
171206

172207

173-
player_input()
208+
player_input()

BoardGame-CLI/snakeLadder/snakeLadder.py

-208
This file was deleted.

0 commit comments

Comments
 (0)