Skip to content

Commit 2042c2a

Browse files
authored
Merge branch 'master' into 1.0.2
2 parents 81e7e91 + 687d23e commit 2042c2a

File tree

2 files changed

+110
-2
lines changed

2 files changed

+110
-2
lines changed
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from random import randint
2+
enem_board = [[u"\U0001F30A"]*5 for n in range(5)]
3+
frnd_board = [[u"\U0001F30A"]*5 for n in range(5)]
4+
name = "Sa'ar"
5+
def print_board(frnd, enem):
6+
print("CPU")
7+
print(end=" ")
8+
for i in range(1, len(enem[0])+1):
9+
print(i, end=" ")
10+
print()
11+
for i in range(1, len(enem[0])+1):
12+
row = enem[i-1]
13+
print(i," ".join(row))
14+
print("-".join(["--"]*5))
15+
print(name)
16+
print(end=" ")
17+
for i in range(1, len(frnd[0])+1):
18+
print(i, end=" ")
19+
print()
20+
for i in range(1, len(frnd)+1):
21+
row = frnd[i-1]
22+
print(i," ".join(row))
23+
print()
24+
#computer hide
25+
row = randint(0, len(enem_board)-1)
26+
col = randint(0, len(enem_board[0])-1)
27+
#player hide
28+
pr = None
29+
pc = None
30+
while pr == None and pc == None:
31+
if pr == None:
32+
pr = randint(1, len(frnd_board))
33+
pr -= 1
34+
if pc == None:
35+
pc = randint(1, len(frnd_board))
36+
pc -= 1
37+
if pc < 0 or pc >= len(frnd_board[0]):
38+
pc = None
39+
if pr < 0 or pr > len(frnd_board):
40+
pr = None
41+
else:
42+
print(pr+1,pc+1)
43+
frnd_board[pr][pc] = u"\U0001F6A2"
44+
45+
won = False
46+
lost = False
47+
while (not won) and (not lost):
48+
print_board(frnd_board, enem_board)
49+
print("CPU: ")
50+
t = False
51+
while not t:
52+
gr = randint(0, len(frnd_board)-1)
53+
gc = randint(0, len(frnd_board[0])-1)
54+
if frnd_board[gr][gc] != u"\U0001F4A3":
55+
t = True
56+
print("Row: ",gr+1)
57+
print("Column: ",gc+1)
58+
print()
59+
if frnd_board[gr][gc] == u"\U0001F6A2":
60+
lost = True
61+
frnd_board[gr][gc] = u"\U0001F4A5"
62+
print("Hit!")
63+
break
64+
else:
65+
frnd_board[gr][gc] = u"\U0001F4A3"
66+
print("Miss!")
67+
print()
68+
print_board(frnd_board, enem_board)
69+
print(name+":")
70+
gr = randint(1, len(enem_board))
71+
gr -= 1
72+
print("Row:",gr)
73+
gc = randint(1, len(enem_board[0]))
74+
gc -= 1
75+
print("Column:",gc)
76+
print()
77+
if gr == row and gc == col:
78+
print("Hit!")
79+
enem_board[gr][gc] = u"\U0001F4A5"
80+
won = True
81+
elif gr < 0 or gr >= len(enem_board) or gc < 0 or gc >= len(enem_board[0]):
82+
print("That's not even in the ocean ):")
83+
elif enem_board[gr][gc] == u"\U0001F4A3":
84+
print("You already guessed that, stupid! DX")
85+
else:
86+
print("Miss!")
87+
print()
88+
enem_board[gr][gc] = u"\U0001F4A3"
89+
if won:
90+
for i in range(len(enem_board)):
91+
for j in range(len(enem_board[i])):
92+
if not enem_board[i][j] == u"\U0001F4A3":
93+
enem_board[i][j] = u"\U0001F525"
94+
else:
95+
enem_board[i][j] = u"\u2620"
96+
enem_board[row][col] = u"\U0001F4A5"
97+
print("Congrats on winning!")
98+
if lost:
99+
for i in range(len(frnd_board)):
100+
for j in range(len(frnd_board[i])):
101+
if not frnd_board[i][j] == u"\U0001F4A3":
102+
frnd_board[i][j] = u"\U0001F525"
103+
else:
104+
frnd_board[i][j] = u"\u2620"
105+
frnd_board[pr][pc] = u"\U0001F4A5"
106+
enem_board[row][col] = u"\U0001F6A2"
107+
print("You sax. Better luck next time!")
108+
print_board(frnd_board, enem_board)

screens.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def loops(self):
209209

210210
def bs_intro(self):
211211
self.new_proj(1, 0)
212-
self.multiLbl("You are going to be building a game that's sort of like this game called battleship. So the computer hides a ship and you have to shoot it down by guessing the row and column correctly.")
212+
self.multiLbl("You are going to be building a game that's sort of like this game called battleship. So the computer hides a ship and you have to shoot it down by guessing the coordinates correctly.")
213213

214214
def bs_empty_list(self):
215215
self.new_proj(1, 1)
@@ -241,4 +241,4 @@ def bs_win(self):
241241

242242
def bs_lose(self):
243243
self.new_proj(1, 8)
244-
self.multiLbl("""To make a losing condition, we have to add an else. The else co""")
244+
self.multiLbl("""To make a losing condition, we have to add an else. The else co""")

0 commit comments

Comments
 (0)