import ImageGrab
import os
import time
import win32api, win32con
import ImageOps
from numpy import *
# All mesure ments are based on a ASUS X550VX-MS71 15.6" Laptop.# The game was opened in google chrome, 100% zoom, without scrolling down or anything like that.# global
x_pad = 190y_pad = 139
# dictionary of how many of each ingredient it on hand at the start of the gamefoodOnHand = {'shrimp ': 5,
'rice': 10,
'nori': 10,
'roe': 10,
'salmon': 5,
'unagi': 5}
# Dictionary of sushi types and the greyscale value of each sushi typesushiTypes = {1893: 'onigiri',
2537: 'caliroll',
1900: 'gunkan', }
class Cord:
# coordinates of food to make sushi with f_shrimp = (47, 427)
f_rice = (106, 435)
f_nori = (38, 483)
f_roe = (98, 488)
f_salmon = (23, 544)
f_unagi = (99, 548)
# -----------------------------------------
# coordinates of the area where the plates are for clearing the tables plate1 = (76, 308)
plate2 = (175, 309)
plate3 = (382, 310)
plate4 = (492, 310)
plate5 = (492, 308)
plate6 = (592, 312)
# coordinates of the ingredients and menus needed to buy more food phone = (574, 453)
menu_topping = (537, 376)
menu_rice = (525, 395)
buy_rice = (542, 385)
t_shrimp = (491, 322)
t_unagi = (572, 325)
t_nori = (488, 375)
t_roe = (571, 381)
t_salmon = (490, 436)
delivery_norm = (487, 399)
rice_exit = (579, 441)
other_exit = (593, 440)
class Blank:
# These are the values of the seats when no one is sitting down and there is no food bubble.
seat_1 = 8041 seat_2 = 5908 seat_3 = 10984 seat_4 = 10304 seat_5 = 6519 seat_6 = 8963
def screenGrab():
# this grabs and image of the screen using the x and y pad to get the image rgb values and pixel locations b1 = (x_pad + 1, y_pad + 1, x_pad + 638, y_pad + 483)
im = ImageGrab.grab()
##im.save(os.getcwd() + '\\Snap__' + str(int(time.time())) +'.png', 'PNG') return im
def grab():
# this grabs an image of the suhsi box and then then converts it to a greyscale value to
# be used in the sushi types dictionary box = (x_pad + 1, y_pad + 1, x_pad + 640, y_pad + 480)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
return a
def leftClick():
# method for left Clicking win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
print "Click." # completely optional. But nice for debugging purposes.
def leftDown():
# method for left Clicking when the button is down win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
time.sleep(.1)
print 'left Down'
def leftUp():
# method for left Clicking when the button is up win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
time.sleep(.1)
print 'left release'
def mousePos(cord):
# method to get the position of the mouse win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1]))
def get_cords():
# method to the get the coordinates of wherever the mouse is when the program is run x, y = win32api.GetCursorPos()
x = x - x_pad
y = y - y_pad
print x, y
def clear_tables():
# method to click where all of the empty plates are supposed to be when the customer is done with their food # plate coordinates for easy reference """ plate1 = (76, 308) plate2 = (175, 309) plate3 = (382, 310) plate4 = (492, 310) plate5 = (492, 308) plate6 = (592, 312) """ mousePos((76, 310))
leftClick()
mousePos((175, 310))
leftClick()
mousePos((287, 310))
leftClick()
mousePos((382, 310))
leftClick()
mousePos((492, 310))
leftClick()
mousePos((592, 310))
leftClick()
time.sleep(1)
def foldMat():
# method to fold the mat after the ingredients are selected to make the sushi mousePos((Cord.f_rice[0] + 40, Cord.f_rice[1]))
leftClick()
time.sleep(.1)
def makeFood(food):
# methods to clink on the right ingredients, # change the value in the foodOnHand dictionary to reflect how many have been used
# method to make California rolls if food == 'caliroll':
print "Making a caliroll" foodOnHand['rice'] -= 1 foodOnHand['nori'] -= 1 foodOnHand['roe'] -= 1 mousePos(Cord.f_rice)
leftClick()
time.sleep(.05)
mousePos(Cord.f_nori)
leftClick()
time.sleep(.05)
mousePos(Cord.f_roe)
leftClick()
time.sleep(.1)
foldMat()
time.sleep(1.5)
# method to make onigiri elif food == 'onigiri':
print 'Making onigiri' foodOnHand['rice'] -= 2 foodOnHand['nori'] -= 1 mousePos(Cord.f_rice)
leftClick()
time.sleep(.05)
mousePos(Cord.f_rice)
leftClick()
time.sleep(.05)
mousePos(Cord.f_nori)
leftClick()
time.sleep(.1)
foldMat()
time.sleep(.05)
time.sleep(1.5)
# method to make gunkan elif food == 'gunkan':
print 'Making a gunkan' foodOnHand['rice'] -= 1 foodOnHand['nori'] -= 1 foodOnHand['roe'] -= 2 mousePos(Cord.f_rice)
leftClick()
time.sleep(.05)
mousePos(Cord.f_nori)
leftClick()
time.sleep(.05)
mousePos(Cord.f_roe)
leftClick()
time.sleep(.05)
mousePos(Cord.f_roe)
leftClick()
time.sleep(.1)
foldMat()
time.sleep(1.5)
def buyFood(food):
# variables names for buying ingredients, they were created above and are here for to be used as a reference
mousePos(Cord.phone)
mousePos(Cord.menu_topping)
mousePos(Cord.t_nori)
mousePos(Cord.t_roe)
mousePos(Cord.t_salmon)
mousePos(Cord.t_unagi)
mousePos(Cord.rice_exit)
mousePos(Cord.other_exit)
mousePos(Cord.menu_rice)
mousePos(Cord.buy_rice)
mousePos(Cord.delivery_norm)
# method to buy more rice if food == 'rice':
mousePos(Cord.phone)
time.sleep(1)
leftClick()
print(0)
mousePos(Cord.menu_rice)
time.sleep(1)
leftClick()
print 'here1' s = screenGrab()
print s.getpixel(Cord.buy_rice)
time.sleep(1)
if s.getpixel(Cord.buy_rice) != (225, 181, 105):
print 'rice is available' mousePos(Cord.buy_rice)
time.sleep(1)
leftClick()
print 'here3' mousePos(Cord.delivery_norm)
foodOnHand['rice'] += 10 time.sleep(1)
leftClick()
print'4' time.sleep(1)
else:
print 'rice is NOT available' mousePos(Cord.rice_exit)
leftClick()
time.sleep(1)
buyFood(food)
# method to buy more nori if food == 'nori':
mousePos(Cord.phone)
time.sleep(1)
leftClick()
mousePos(Cord.menu_topping)
time.sleep(1)
leftClick()
s = screenGrab()
print 'test' time.sleep(1)
mousePos(Cord.t_nori)
if s.getpixel(Cord.t_nori) == (225, 181, 105):
print 'nori is available' mousePos(Cord.t_nori)
time.sleep(1)
leftClick()
mousePos(Cord.delivery_norm)
foodOnHand['nori'] += 10 time.sleep(1)
leftClick()
time.sleep(1)
else:
print 'nori is NOT available' mousePos(Cord.other_exit)
leftClick()
time.sleep(1)
buyFood(food)
# method to buy more roe if food == 'roe':
mousePos(Cord.phone)
time.sleep(1)
leftClick()
mousePos(Cord.menu_topping)
time.sleep(1)
leftClick()
s = screenGrab()
# 202, 55, 25 time.sleep(1)
if s.getpixel(Cord.t_roe) != (202, 55, 25):
print 'roe is available' mousePos(Cord.t_roe)
time.sleep(1)
leftClick()
mousePos(Cord.delivery_norm)
foodOnHand['roe'] += 10 time.sleep(1)
leftClick()
time.sleep(1)
else:
print 'roe is NOT available' mousePos(Cord.other_exit)
leftClick()
time.sleep(1)
buyFood(food)
def get_seat_one():
# this method gets the greysale value of the sushi bubble in seat 1
box = (214, 304, 214 + 63, 304 + 16)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
im.save(os.getcwd() + '\\seat_one__' + str(int(time.time())) + '.png', 'PNG')
return a
def get_seat_two():
# this method gets the greysale value of the sushi bubble in seat 2
box = (315, 304, 315 + 63, 304 + 16)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
im.save(os.getcwd() + '\\seat_two__' + str(int(time.time())) + '.png', 'PNG')
return a
def get_seat_three():
# this method gets the greysale value of the sushi bubble in seat 3
box = (416, 304, 416 + 63, 304 + 16)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
im.save(os.getcwd() + '\\seat_three__' + str(int(time.time())) + '.png', 'PNG')
return a
def get_seat_four():
# this method gets the greysale value of the sushi bubble in seat 4
box = (517, 304, 517 + 63, 304 + 16)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
im.save(os.getcwd() + '\\seat_four__' + str(int(time.time())) + '.png', 'PNG')
return a
def get_seat_five():
# this method gets the greysale value of the sushi bubble in seat 5
box = (618, 304, 618 + 63, 304 + 16)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
im.save(os.getcwd() + '\\seat_five__' + str(int(time.time())) + '.png', 'PNG')
return a
def get_seat_six():
# this method gets the greysale value of the sushi bubble in seat 6
box = (719, 304, 719 + 62, 304 + 15)
im = ImageOps.grayscale(ImageGrab.grab(box))
a = array(im.getcolors())
a = a.sum()
print a
im.save(os.getcwd() + '\\seat_six__' + str(int(time.time())) + '.png', 'PNG')
return a
def get_all_seats():
# this method gets the greysale value of the sushi bubble in every seat
get_seat_one()
get_seat_two()
get_seat_three()
get_seat_four()
get_seat_five()
get_seat_six()
def startGame():
# this method clicks through the menus to actually start the game
# Play menu mousePos((301, 311))
leftClick()
time.sleep(.1)
# Continue pass ios/android download page mousePos((356, 488))
leftClick()
time.sleep(.1)
# Continue num 2 mousePos((305, 496))
# Skip the tutorial mousePos((587, 566))
leftClick()
time.sleep(.1)
# Start the actual game mousePos((379, 466))
leftClick()
time.sleep(.1)
def checkFood():
# this method goes through the foodOnHand dictionary and check if any of the ingredients are low # and if they are it calls buyFood of what ever is missing for i, j in foodOnHand.items():
if i == 'nori' or i == 'rice' or i == 'roe':
if j <= 4:
print '%s is low and needs to be replenished' % i
buyFood(i)
def check_bubs():
# this method checks the amount of each ingredient then takes a screen shot of each chairs thought bubble # if there is a person sitting there, it makes their order # or returns an that the sushi is not found if there is something wrong or if no one is sitting at that spot, # it returns that the table is unoccupied
checkFood()
s1 = get_seat_one()
if s1 != Blank.seat_1:
if sushiTypes.has_key(s1):
print 'table 1 is occupied and needs %s' % sushiTypes[s1]
makeFood(sushiTypes[s1])
else:
print 'sushi not found!\n sushiType = %i' % s1
else:
print 'Table 1 unoccupied'
clear_tables()
checkFood()
s2 = get_seat_two()
if s2 != Blank.seat_2:
if sushiTypes.has_key(s2):
print 'table 2 is occupied and needs %s' % sushiTypes[s2]
makeFood(sushiTypes[s2])
else:
print 'sushi not found!\n sushiType = %i' % s2
else:
print 'Table 2 unoccupied'
checkFood()
s3 = get_seat_three()
if s3 != Blank.seat_3:
if sushiTypes.has_key(s3):
print 'table 3 is occupied and needs %s' % sushiTypes[s3]
makeFood(sushiTypes[s3])
else:
print 'sushi not found!\n sushiType = %i' % s3
else:
print 'Table 3 unoccupied'
checkFood()
s4 = get_seat_four()
if s4 != Blank.seat_4:
if sushiTypes.has_key(s4):
print 'table 4 is occupied and needs %s' % sushiTypes[s4]
makeFood(sushiTypes[s4])
else:
print 'sushi not found!\n sushiType = %i' % s4
else:
print 'Table 4 unoccupied'
clear_tables()
checkFood()
s5 = get_seat_five()
if s5 != Blank.seat_5:
if sushiTypes.has_key(s5):
print 'table 5 is occupied and needs %s' % sushiTypes[s5]
makeFood(sushiTypes[s5])
else:
print 'sushi not found!\n sushiType = %i' % s5
else:
print 'Table 5 unoccupied'
checkFood()
s6 = get_seat_six()
if s6 != Blank.seat_6:
if sushiTypes.has_key(s6):
print 'table 1 is occupied and needs %s' % sushiTypes[s6]
makeFood(sushiTypes[s6])
else:
print 'sushi not found!\n sushiType = %i' % s6
else:
print 'Table 6 unoccupied'
clear_tables()
def main():
# this method starts the game goes through the menus and # then runs a loop of checkbulbs that will continue to run play through the game. #startGame() # while True: # check_bubs() get_all_seats()
if __name__ == '__main__':
main()