-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
81 lines (61 loc) · 1.77 KB
/
menu.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
import sys
import numpy as np
#Switch case implementation for user interface
#############
def exit_game():
sys.exit(0)
#############
def game_menu():
print("game_menu:\n"
"0 To exit\n"
"1 To list help\n"
"2 Nships\n"
"3 Board\n"
"4 shipDict\n"
"5 HitBoard\n")
#############
def prn_Nships(player):
print(player.Nships)
#############
def prn_shipDict(player):
for i in player.shipDict:
print("ship",i,"shipsize:",player.shipDict[i])
print("\n")
#############
def prettyBoardHeader(player):
length= len(player.Board[0])
s = " ".join([str(i+1) for i in range(length)])
print("\t",s,"\n")
def prettyBoardIndex(board):
for i,j in enumerate(board):
print(i+1,"\t", " ".join(map(str,j)))
def prn_Board(player):
prettyBoardHeader(player)
board = np.array(player.Board[0]).astype(int)
prettyBoardIndex(board)
print("\n")
def prn_HitBoard(player):
#print header
prettyBoardHeader(player)
#build empty new array
length = len(player.Board[0].ravel())
arr = np.zeros(length, dtype=int)
#fill with 2 or 1
for i,(j,k) in enumerate(zip(player.Board[0].ravel(),player.Board[1].ravel())):
if j != 0 and k == 1:
arr[i]= "2"
if j == 0 and k == 1:
arr[i]= "1"
#print new arr
side = player.Board[0].shape[0]
newarr= arr.reshape(side,side)
prettyBoardIndex(newarr)
print("\n")
#############
interface_options = {"exit": exit_game(),
"help": game_menu(),
"prn_Nships": prn_Nships(),
"prn_Board": prn_Board(),
"prn_shipDict": prn_shipDict(),
"prn_HitBoard": prn_HitBoard(),
}