-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (72 loc) · 2.43 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python3
import functions
import os
# DEBUG
debug = 0
# init variables
end_while = 0
number_of_shots = 0
i = 0
j = 0
battlefield = [[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]
ship_position = functions.place_ship()
# instructions
print("Hello to BATTLESHIPS v1.0")
print("Simple game made in Python")
print("Game is released under GNU General Public License")
print("*** Instructions ***")
print(" 1. There is one ship hidden on battlefield.")
print(" 2. Ships is randomly placed horizontally or vertically")
print(" 3. Ship have 3 pieces")
print(" 4. Enjoy :)")
print("********************")
# main game loop
while True:
input("Press Enter to continue...")
os.system('cls||clear')
if debug == 1: print(ship_position) # DEBUG
print("***BATTLE SITUATION MONITOR V 1.0***")
functions.print_battlefield(battlefield)
print("************************************")
while True:
try:
j = int(input("Please give me X coordinate to attack: "))
except ValueError:
print("Sorry, you must give me coordinate number from 0 to 4")
continue
else:
if j > 4 or j < 0:
print("Sorry, you must give me coordinate number from 0 to 4")
continue
else:
break
while True:
try:
i = int(input("Please give me Y coordinate to attack: "))
except ValueError:
print("Sorry, you must give me coordinate number from 0 to 4")
continue
else:
if i > 4 or i < 0:
print("Sorry, you must give me coordinate number from 0 to 4")
continue
else:
break
functions.shot(int(i), int(j), battlefield, ship_position)
number_of_shots += 1
if functions.check_win_conditions(battlefield, ship_position) == 1:
functions.print_battlefield(battlefield)
print("Congratulations, you have sinked the ship :)")
print("You have done it in "+str(number_of_shots)+" shots!")
print("Game restarts")
number_of_shots = 0
ship_position = functions.place_ship()
battlefield = [[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]