Python Forum
Python - Treasure Generator on 5x5 Board
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Treasure Generator on 5x5 Board
#1
I was wondering exactly what would be the optimal format to setup a GenerateTreasure function. I already have a move player function in place around the board, so I just need to make a function that generates a random treasure location on my board, notifies the player when they have found it, and then generate another until the player wants to quit. The following is everything I have for my game so far(I have made these in different files so then I import * from them to my main file.):

BoardGenerator

def CreateBoard():
    import copy
    tempList = []
    board= [[".",".",".",".",".",],
            [".",".",".",".",".",],
            [".",".",".",".",".",],
            [".",".",".",".",".",],
            [".",".",".",".",".",]]
    return board

def PlacePlayer(board,player):
    board[player["row"]][player["col"]] = "@"
    return board,player

def ShowBoard(board):
    for i in board:
        row = " ".join(i)
        print (row)
MOVE PLAYER FILE

from BoardGenerator import *

def MovePlayer(player,board):
    currentPlayerLocation = "."
    userInput = input("Select a letter to move your player (WASD): ").upper()

    if userInput == "W":
        if player["row"] > 0:
            board[player["row"]][player["col"]] = "."
            player["row"] -= 1
        else:
            print("You have reached the edge of the board.")

    elif userInput == "A":
        if player["col"] > 0:
            board[player["row"]][player["col"]] = "."
            player["col"] -= 1
        else:
            print("You have reached the edge of the board.")

    elif userInput == "S":
        if player["row"] < len(board)-1:
            board[player["row"]][player["col"]] = "."
            player["row"] += 1
        else:
            print("You have reached the edge of the board.")

    elif userInput == "D":
        if player["col"] < len(board[0])-1:
            board[player["row"]][player["col"]] = "."
            player["col"] += 1
        else:
            print("You have reached the edge of the board.")

    PlacePlayer(board, player)
    ShowBoard(board)
    return MovePlayer(player,board)
DICE FILE
import random

def DieRoller(times,sides):
    total = 0
    for i in range(times):
        total += random.randint(1,sides)
    return total
MAIN FILE

from PlayerGenerator import *
from Dice import *
from BoardGenerator import *
from MovePlayer import *

def Main():
    while True:
        player = GenPlayer(0)
        for key in player: #Printing the player
            print(key + ":" + str(player[key]))
        userInput = input("Do you like this character (Y/N with Y to exit:)?: ").upper()
        if userInput == "Y":
            print("Enjoy your game!")
            break

    board = CreateBoard()
    board,player = PlacePlayer(board,player)
    ShowBoard(board)
    MovePlayer(player,board)


Main()
Reply
#2
Any help would be appreciated. Fairly new to programming in general
Reply
#3
I read your post before and struggled to understand your question.


(Dec-11-2017, 10:01 PM)PhillySports124 Wrote: I was wondering exactly what would be the optimal format to setup a GenerateTreasure function.
Give a 2D list, you just want to replace a random element? Is that it?


(Dec-11-2017, 07:29 PM)PhillySports124 Wrote: notifies the player when they have found it,
Is this a second question? Or would you understand how to do it once the first part is resolved?

If you can frame your question in terms of 5-10 lines of code, it would increase the speed and quality of answers. It's tedious and time-consuming to try to read posts like this, which is probably why you haven't had the greatest luck. That said, kudos on using code tags on your first post, faaar too many people don't and that's the worst!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I need help with Connect-Four Game Board niiakoadjei 2 2,531 May-26-2021, 04:54 PM
Last Post: jefsummers
  Finding the treasure location cjlee420 7 5,422 Oct-03-2019, 04:45 PM
Last Post: cjlee420

Forum Jump:

User Panel Messages

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