Dec-11-2017, 07:29 PM
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 totalMAIN 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()