Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a treasure hunt
#1
I am creating a treasurehunt game that should display a grid to the player, where they can move around by entering values, the grid contains bandits and treasurechests. The player will win the game when they reach 100 coins. they can obtain coins by collecting 10 coins from a treasurechest. if they land on a bandit their coin balance will be reset. the player should get reminded of their balance every time they make a move, as well as their move count.


I need to create a grid with options for other grid sizes (8x8, 10x10 and 12x12) as well as a grid that doesn't display the treasure chests and bandits.



def mainmenu():
    print("Welcome to the Treasure Hunt Game")
    print("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
    print("Play game? (1)")
    print("Test Grid (2)")
    print("Quit (3)")

    user_choice = int(input("Please enter a choice between 1 and 3 "))
    while user_choice < 1 or user_choice > 3:
        print("That was not a valid option")
        user_choice = input("Please enter an option between 1 and 3 ")

    #Run the function that the user chooses by entering a number
    if user_choice == 1:
        grid()
    if user_choice == 2:
        test_grid()
    elif user_choice == 3:
        quit()



def grid():
    x = 8
    y = 8
    grid = [["" for x in range (x)] for y in range (y)]
    from pprint import pprint
    while True:
        import random
        moves = 0
        def Chests():
            ChestCount = 20
            for i in range (ChestCount):
                a = random.randint(0,x-1)
                b = random.randint(0,y-1)
                while grid [a] [b] != "":
                    a = random.randint(O,x-1)
                    b = random.randint(0,y-1)
                else:
                    grid [a] [b] = "t"
        playX = 2
        playY = y-3
        grid [playX] [playY] ="p"
        grid [playX] [playY] = " "
        pprint(grid)
        updown = int(input("Enter how many squares you want to move, negative is up, positive is down: "))
        while updown + playX >= x or updown + playX < 0:
            print ("Incorrect value")
            updown = int(input("Enter how many squares you want to move, negative is up, positive is down: "))
        leftright = int(input("Enter how many squares you want to move, negative is left, positive is right: "))
        while leftright + playY >= y or leftright + playY < 0:
            print ("Incorrect value")
            leftright = int(input("Enter how many squares you want to move, negative is left, positive is right: "))
        playX = (playX + updown)
        playY = (playY + leftright)
        Balance = 0
        if grid [playX] [playY] =="t":
            Balance = Balance + 1
        else:()
        grid [playX+updown] [playY+leftright] = "p"
        moves = moves +1
        pprint(grid)
        print ("Moves: ", moves)
        print("Balance = ",Balance)
Reply
#2
What's your question? How to change the grid size? To start, you should pass the size to the grid function as a parameter:

def test(parameter):
    print(parameter)
For more information, check out the functions tutorial link in my signature.

As for not showing things, I would have the grid be the data, not the text representation. Then have a function that turns the data into a text representation. Then the function can display whatever part of the data you want it to.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
its a nice theme you are working on and very interesting to play
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020