bgs = ['summer', 'schoolhallway', 'schoolentrance', 'hauntedhouse', 'spring', 'hauntedhouseinterior',
'subway', 'fall', 'space', 'castle', 'moon', 'park', 'underwater', 'concert', 'theater', 'city',
'stadium', 'game', 'grid', 'grid2', 'field', 'volcano', 'forest', 'halfcourt', 'cornfield', 'mars',
'onlineprofile', 'pond', 'jupiter', 'pluto', 'silo', 'drawbridge', 'barn', 'footballfield2',
'houseinterior', 'soccerfield', 'flowers', 'footballfield', 'jungle', 'tilewall', 'baseballfield']
from random import shuffle, randint
# initialize list of lists
board = [ ]
for row in range(8):
shuffle(bgs)
board.append(bgs[0:8])
secret_row, secret_col = randint(0,7), randint(0,7)
board[secret_row][secret_col] = "mars"
caption = None
talker = None
def show_bg(r, c):
global caption, talker
if caption and talker:
stage.remove_sprite(caption)
stage.remove_sprite(talker)
name = board[r][c]
stage.set_background(name)
stage.set_background_scale(0.7)
stage.set_background_x(-200)
stage.set_background_y(200)
talker = codesters.Text(str(r) + ", " + str(c), 200, -200)
caption = codesters.Text(name, -10, -200)
if board[r][c] == "mars":
stage.remove_sprite(talker)
talker = codesters.Text("You win!!!", 200, -200)
row = 0
column = 0
show_bg(row, column)
def left_key():
global column, row
column = column - 1
if column < 0:
column = 7
show_bg(row, column)
def right_key():
global column, row
column = column + 1
if column > 7:
column = 0
show_bg(row, column)
def up_key():
global column, row
row = row - 1
if row < 0:
row = 7
show_bg(row, column)
def down_key():
global row, column
row = row + 1
if row > 7:
row = 0
show_bg(row, column)
stage.event_key("left", left_key)
stage.event_key("right", right_key)
stage.event_key("up", up_key)
stage.event_key("down", down_key)