Skip to content

Commit

Permalink
Cosmetic code reordering.
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Dec 17, 2014
1 parent e84187f commit 2e3be72
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Binary file removed images/express_delivery_button.png
Binary file not shown.
Binary file removed images/sake_order_button.png
Binary file not shown.
Binary file removed images/sake_order_menu.png
Binary file not shown.
48 changes: 24 additions & 24 deletions sushigoroundbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
INVENTORY = {SHRIMP: 5, RICE: 10,
NORI: 10, ROE: 10,
SALMON: 5, UNAGI: 5}
GAME_REGION = () # (left, top, width, height) values coordinates of the game window
ORDERING_COMPLETE = {SHRIMP: None, RICE: None, NORI: None, ROE: None, SALMON: None, UNAGI: None} # unix timestamp when an ordered ingredient will have arrived
ROLLING_COMPLETE = 0 # unix timestamp of when the rolling of the mat will have completed
LAST_PLATE_CLEARING = 0 # unix timestamp of the last time the plates were cleared
LAST_GAME_OVER_CHECK = 0 # unix timestamp when we last checked for the Game Over or You Win messages

# series of coordinates set after the GAME_REGION has been identified
# various coordinates of objects in the game
GAME_REGION = () # (left, top, width, height) values coordinates of the entire game window
INGRED_COORDS = None
PHONE_COORDS = None
TOPPING_COORDS = None
Expand All @@ -77,6 +77,28 @@ def main():
startServing()


def imPath(filename):
"""A shortcut for joining the 'images/'' file path, since it is used so often. Returns the filename with 'images/' prepended."""
return os.path.join('images', filename)


def getGameRegion():
"""Obtains the region that the Sushi Go Round game is on the screen and assigns it to GAME_REGION. The game must be at the start screen (where the PLAY button is visible)."""
global GAME_REGION

# identify the top-left corner
logging.debug('Finding game region...')
region = pyautogui.locateOnScreen(imPath('top_right_corner.png'))
if region is None:
raise Exception('Could not find game on screen. Is the game visible?')

# calculate the region of the entire game
topRightX = region[0] + region[2] # left + width
topRightY = region[1] # top
GAME_REGION = (topRightX - 640, topRightY, 640, 480) # the game screen is always 640 x 480
logging.debug('Game region found: %s' % (GAME_REGION,))


def setupCoordinates():
"""Sets several of the coordinate-related global variables, after acquiring the value for GAME_REGION."""
global INGRED_COORDS, PHONE_COORDS, TOPPING_COORDS, ORDER_BUTTON_COORDS, RICE1_COORDS, RICE2_COORDS, NORMAL_DELIVERY_BUTTON_COORDS, MAT_COORDS, LEVEL
Expand All @@ -103,28 +125,6 @@ def setupCoordinates():
LEVEL = 1


def imPath(filename):
"""A shortcut for joining the 'images/'' file path, since it is used so often. Returns the filename with 'images/' prepended."""
return os.path.join('images', filename)


def getGameRegion():
"""Obtains the region that the Sushi Go Round game is on the screen and assigns it to GAME_REGION. The game must be at the start screen (where the PLAY button is visible)."""
global GAME_REGION

# identify the top-left corner
logging.debug('Finding game region...')
region = pyautogui.locateOnScreen(imPath('top_right_corner.png'))
if region is None:
raise Exception('Could not find game on screen. Is the game visible?')

# calculate the region of the entire game
topRightX = region[0] + region[2] # left + width
topRightY = region[1] # top
GAME_REGION = (topRightX - 640, topRightY, 640, 480) # the game screen is always 640 x 480
logging.debug('Game region found: %s' % (GAME_REGION,))


def navigateStartGameMenu():
"""Performs the clicks to navigate form the start screen (where the PLAY button is visible) to the beginning of the first level."""
# Click on everything needed to get past the menus at the start of the game.
Expand Down

0 comments on commit 2e3be72

Please sign in to comment.