-
Notifications
You must be signed in to change notification settings - Fork 0
/
python midterm.py
223 lines (197 loc) · 6.65 KB
/
python midterm.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import pyautogui, time, os
import numpy as np
# Food order constants
BIITORO = 'biitoro' #ピートロ
TORIKAWA = 'torikawa' #鶏皮
TAN = 'tan' #タン
NEGIMA = 'negima' #ねぎま
SUNAGIMO = 'sunagimo' #すなぎも
KASHIRA = 'kashira'#カシラ
ERINGI = 'eringi' #エリンギ
ALL_ORDER_TYPES = (BIITORO, TORIKAWA, TAN, NEGIMA, SUNAGIMO, KASHIRA, ERINGI)
stick = np.array([False,False,False,False,False])
i = 0
count = 0
sub = 0
def main():
""""game steps"""
open_game()
time.sleep(3)
getGameRegion()
start_game()
time.sleep(2)
set_coordinates()
time.sleep(1.5)
play_game()
"""repeat for get customer orders"""
def play_game():
start_time = int(time.time())
now = int(time.time())
while (now - start_time < 500) :
barbecue()
time.sleep(6.7)
delivery_food()
time.sleep(0.2)
now = int(time.time())
def imPath(filename):
"""A shortcut for joining the 'Takoyaki/'' file path"""
return os.path.join('Takoyaki', filename)
def getGameRegion():
"""Obtains the region"""
global GAME_REGION
region = pyautogui.locateOnScreen(imPath('top_right_corner.png'))
a1 = region[0] // 2
b1 = region[1] // 2
if region is None:
raise Exception('Could not find game on screen. Is the game visible?')
# calculate the region of the entire game
topRightX = a1 + region[2] # left + width
topRightY = b1 # top
GAME_REGION = (topRightX - 640, topRightY, 640, 350)
print(GAME_REGION)
def open_game():
""""open the game"""
pyautogui.moveTo(1440,0)
pyautogui.moveTo(1345,12)
pyautogui.click()
pyautogui.typewrite('safari')
pyautogui.press('enter')
pyautogui.moveTo(687,50)
pyautogui.click()
pyautogui.typewrite('http://games.twtop.net/fgameplay.php?id=2424')
pyautogui.press('enter')
def start_game():
pos = pyautogui.locateCenterOnScreen(imPath('start_button.png'),confidence=0.5)
x = pos[0] // 2
y = pos[1] // 2
print(x,y)
pyautogui.click(x,y)
def set_coordinates():
"""set up all the button of its coordinates"""
global BIITORO_COORDS, TORIKAWA_COORDS, TAN_COORDS, NEGIMA_COORDS, SUNAGIMO_COORDS, KASHIRA_COORDS, ERINGI_COORDS
global STICK0_COORDS, STICK1_COORDS, STICK2_COORDS, STICK3_COORDS, STICK4_COORDS
global PLATE0_COORDS, PLATE1_COORDS, PLATE2_COORDS
global CUSTORMER_1,CUSTORMER_2, CUSTORMER_3
#food_coordinates
BIITORO_COORDS = (GAME_REGION[0] + 75, GAME_REGION[1] + 207)
TORIKAWA_COORDS = (GAME_REGION[0] + 75, GAME_REGION[1] + 241)
TAN_COORDS = (GAME_REGION[0] + 75, GAME_REGION[1] + 275)
NEGIMA_COORDS = (GAME_REGION[0] + 75, GAME_REGION[1] + 314)
SUNAGIMO_COORDS = (GAME_REGION[0] + 490, GAME_REGION[1] + 224)
KASHIRA_COORDS = (GAME_REGION[0] + 490, GAME_REGION[1] + 257)
ERINGI_COORDS = (GAME_REGION[0] + 490, GAME_REGION[1] + 294)
#stick_coordinates
STICK0_COORDS = (GAME_REGION[0] + 149, GAME_REGION[1] + 338)
STICK1_COORDS = (GAME_REGION[0] + 215, GAME_REGION[1] + 338)
STICK2_COORDS = (GAME_REGION[0] + 280, GAME_REGION[1] + 338)
STICK3_COORDS = (GAME_REGION[0] + 345, GAME_REGION[1] + 338)
STICK4_COORDS = (GAME_REGION[0] + 412, GAME_REGION[1] + 338)
#plate_coordinates
PLATE0_COORDS = (GAME_REGION[0] + 135, GAME_REGION[1] + 154)
PLATE1_COORDS = (GAME_REGION[0] + 285, GAME_REGION[1] + 154)
PLATE2_COORDS = (GAME_REGION[0] + 440, GAME_REGION[1] + 154)
#the position of custormershttp:
CUSTORMER_1 = (GAME_REGION[0] + 50, GAME_REGION[1], 680,1000)
CUSTORMER_2 = (GAME_REGION[0] + 680, GAME_REGION[1], 620,1000)
CUSTORMER_3 = (GAME_REGION[0] + 1000, GAME_REGION[1], 680,1000)
"""scope of customer postition"""
def order_position(customer) :
if customer == 0 :
return CUSTORMER_1
elif customer == 1 :
return CUSTORMER_2
elif customer == 2 :
return CUSTORMER_3
"""get the customer's orders"""
def get_order():
global sub
orders = {}
while True:
for orderType in (ALL_ORDER_TYPES):
allOrders = pyautogui.locateAllOnScreen(imPath('%s_order.png' % orderType), confidence=0.9,grayscale = True,region = order_position(sub))
for order in allOrders:
orders[order] = orderType
if len(orders) != 0 :
sub = (sub + 1) % 3
break
else :
sub = (sub + 1) % 3
return orders
"""determine the postition of custormer """
def get_key(array):
global key , count
for x in (array):
key = x[0]
break
key = key // 2
if (410 < key < 570):
count = 0
elif(580 < key <720):
count = 1
elif(740 < key < 880):
count = 2
"""barbecue function"""
def barbecue():
current_orders = get_order()
get_key(current_orders.keys())
for x in current_orders.values():
if x == BIITORO :
pyautogui.moveTo(BIITORO_COORDS)
elif x == TORIKAWA :
pyautogui.moveTo(TORIKAWA_COORDS)
elif x == TAN:
pyautogui.moveTo(TAN_COORDS)
elif x == NEGIMA:
pyautogui.moveTo(NEGIMA_COORDS)
elif x == SUNAGIMO:
pyautogui.moveTo(SUNAGIMO_COORDS)
elif x == KASHIRA:
pyautogui.moveTo(KASHIRA_COORDS)
elif x == ERINGI:
pyautogui.moveTo(ERINGI_COORDS)
y = free_stick()
z1 = stick_postion(y)
pyautogui.dragTo(z1)
stick[y] = True
"""determine the stick postion"""
def stick_postion(x):
if x == 0 :
return STICK0_COORDS
elif x == 1 :
return STICK1_COORDS
elif x == 2 :
return STICK2_COORDS
elif x == 3 :
return STICK3_COORDS
elif x == 4 :
return STICK4_COORDS
"""determine the plate postion"""
def plate_postion(x):
if x == 0 :
return PLATE0_COORDS
elif x == 1 :
return PLATE1_COORDS
elif x == 2 :
return PLATE2_COORDS
"""search for free stick"""
def free_stick():
for i in range(4):
if stick[i] == False:
return i
else:
i = i + 1
"""delivery food to customers"""
def delivery_food():
for i in range(4):
if stick[i] == True:
z2 = stick_postion(i)
pyautogui.moveTo(z2)
if (count == 0):
pyautogui.dragTo(plate_postion(0))
elif (count == 1):
pyautogui.dragTo(plate_postion(1))
elif (count == 2):
pyautogui.dragTo(plate_postion(2))
stick[i] = False
"""call main fuction"""
main()