-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
156 lines (126 loc) · 3.83 KB
/
main.py
File metadata and controls
156 lines (126 loc) · 3.83 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from pygame.locals import *
from time import sleep
import drawShipsandStuff
import makeShips
import Controller
import pygame
import sys
from random import randint
count = 1
num_hits = 0
num_misses = 0
score = 0
visitedPlayer1 = [ [0]*10 for _ in xrange(10) ]
visitedPlayer2 = [ [0]*10 for _ in xrange(10) ]
owncolor = drawShipsandStuff.OWNSHIPCOLOR
enemycolor = drawShipsandStuff.ENEMYSHIPCOLOR
drawShipsandStuff.drawBoard()
drawShipsandStuff.drawBoard(360)
# draw.drawBoard()
ownship = makeShips.workShip()
enemyship = makeShips.workShip()
# for i in range(100):
# for j in ownship.object:
# for x,y in j.cells:
OwnListShip = ownship.createListShips()
EnemyListShip = enemyship.createListShips()
# drawShipsandStuff.drawAllShip(ownship.object, owncolor, 'own')
# drawShipsandStuff.drawAllShip(enemyship.object, enemycolor, 'enemy')
# for i in enemyship.object:
# print i.cells
def ifAllDead(workship):
cnt = True
for i in workship.object:
if (not i.isDead()):
cnt = False
return cnt
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# if event.type == MOUSEBUTTONUP:
# mousex = randint(30,690)
# mousey = randint(30,330)
x = -1
y = -1
if (count % 2):
# o = max([max(Controller.scoresPlayer1[i]) for i in xrange(10)])
m = Controller.scoresPlayer1[0][0]
for a in xrange(10):
for b in xrange(10):
if (Controller.scoresPlayer1[a][b]>m and visitedPlayer1[a][b] is 0):
m = Controller.scoresPlayer1[a][b]
# print Controller.scoresPlayer1
# print o
for i in xrange(10):
for j in xrange(10):
print ("MYYYYYY::::maxValue: ", m, " currentvalue: ", Controller.scoresPlayer1[i][j])
if (Controller.scoresPlayer1[i][j] ==m):
# Controller.scoresPlayer1[i][j] = -999999
visitedPlayer1[i][j] = 1;
x = i+1;
y = j+1;
break;
if x > -1:
break;
# mousex = (x * 30) + 390
# mousey = (y * 30) + 30
print ("x: ", x, " y: ", y)
# check = (mousex >= 390 and mousex < 690 and mousey >= 30 and mousey < 330)
# if (check):
if Controller.checkAction(ownship.object, enemyship, x-1, y-1):
count = count + 1
# print(count)
# else:
# print ("Not your house, mate!")
else:
# o = max([max(Controller.scoresPlayer2[i]) for i in xrange(10)])
m = Controller.scoresPlayer2[0][0]
for a in xrange(10):
for b in xrange(10):
if (Controller.scoresPlayer2[a][b]>m and visitedPlayer2[a][b] is 0):
m = Controller.scoresPlayer2[a][b]
# print Controller.scoresPlayer2
# print o
for i in xrange(10):
for j in xrange(10):
print ("ENEMYYYYY::::maxValue: ", m, " currentvalue: ", Controller.scoresPlayer2[i][j])
if (Controller.scoresPlayer2[i][j]==m):
# Controller.scoresPlayer2[i][j] = -999999
visitedPlayer2[i][j]= 1;
x = i+1;
y = j+1;
break;
if x > -1:
break;
# mousex = (x * 30) + 30
# mousey = (y * 30) + 30
print ("x: ", x, " y: ", y)
# check = mousex >= 30 and mousex < 330 and mousey >= 30 and mousey < 330
# if (check):
if Controller.checkAction1(enemyship.object, ownship, x-1, y-1):
count = count + 1
# else:
# print ("Not your home, mate!")
if (ifAllDead(ownship)):
print("The enemy wins! You surely suck at this game! BlarglarghGlargh!!")
inputFile1 = open("scoresp1.txt", "w")
inputFile2 = open("scoresp2.txt", "w")
for i in xrange(10):
for j in xrange(10):
inputFile1.write(str(Controller.scoresPlayer1[i][j])+"\n")
inputFile2.write(str(Controller.scoresPlayer2[i][j])+"\n")
break
elif (ifAllDead(enemyship)):
print(" I won!!")
inputFile1 = open("scoresp1.txt", "w")
inputFile2 = open("scoresp2.txt", "w")
for i in xrange(10):
for j in xrange(10):
inputFile1.write(str(Controller.scoresPlayer1[i][j])+"\n")
inputFile2.write(str(Controller.scoresPlayer2[i][j])+"\n")
break
pygame.display.update()
# sleep(0.2)
sleep(0.05)