import random

map1 = open("map.py","r")

location = 3

mapDisplay = ["","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O"]

moveDirection = ""

itemLocation = 3

quitTrue = False

score = 0

movesLeft = 10

# this is for the displayMap function to choose what to display

def mapArray(int1, int2):

for i in range(int1, int2 + 1):

print (mapDisplay[i], end="")

print("")

# this displays the map in a 10 * 10 grid

def displayMap():

global score

global movesLeft

#this displays the score

print("score:",score," Moves Left:",movesLeft)

#this displays the location of X or what you control

mapDisplay[location] = "X"

#this displays the location of # or the item to get

mapDisplay[itemLocation] = "#"

#this displays the playing area

mapArray(1, 10)

mapArray(11, 20)

mapArray(21, 30)

mapArray(31, 40)

mapArray(41, 50)

mapArray(51, 60)

mapArray(61, 70)

mapArray(71, 80)

mapArray(81, 90)

mapArray(91, 100)

# this selects the location for the item to get, if it makes the item location equal

# to the X location, it generates another random number until it is at a different location

def item():

global itemLocation

while itemLocation == location:

itemLocation = random.randint(1,100)

# this moves the X value

def movement():

global quitTrue

global location

global score

global movesLeft

movesLeft = 10

while quitTrue == False:

moveDirection = input("Enter a direction to move or press Q to quit: ")

if moveDirection == "up":

# if the X is on the top of the map, it moves the X to the bottom of the map

if location < 11:

mapDisplay[location] = "O"

location += 90

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

#this chooses a new location for the #

item()

score = score + 1

displayMap()

else:

displayMap()

# this moves the X up 1 on the map

else:

mapDisplay[location] = "O"

location -= 10

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

elif moveDirection == "down":

if location > 90:

mapDisplay[location] = "O"

location -= 90

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

else:

mapDisplay[location] = "O"

location += 10

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

elif moveDirection == "left":

#this moves the x to the top right corner of the map if it is in the top left corner of the map

if location == 1:

mapDisplay[location] = "O"

location += 9

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

#if the X is on the far left of the map, it gets moves to the far right of the map

elif location % 10 == 1:

mapDisplay[location] = "O"

location += 9

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

else:

mapDisplay[location] = "O"

location -= 1

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

elif moveDirection == "right":

if location == 10:

mapDisplay[location] = "O"

location -= 9

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

elif location % 10 == 0:

mapDisplay[location] = "O"

location -= 9

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

else:

mapDisplay[location] = "O"

location += 1

movesLeft -= 1

if movesLeft == 0:

quitTrue = True

if location == itemLocation:

item()

score = score + 1

displayMap()

else:

displayMap()

elif moveDirection == "q":

quitTrue = True

else:

print("input a valid response")

def main():

item()

displayMap()

movement()