# P Y R A M I D import random # FUNCTIONS def rollDie(): return random.randint(1,6) # VARIABLES turns = 0 top, middle, bottom = 0, 0, 0 topList = ['top', '1'] middleList = ['middle', '2'] bottomList = ['bottom', '3'] acceptable = topList + middleList + bottomList + ['hack'] # INTRODUCTION # introduces game concept to the player # TODO: improve the copy here print("Hey! The goal of Pyramid is to make it so each of a 3-level pyramid's levels ", "has half as many points as the level below it. Each turn, ", "you'll roll a die and choose which level to put that number of points in. ", "The game tracks how many turns you take - the fewer, the better.\n\n------") # MAIN # TODO: write or find refine your own ambient music to play during the game - also # record different songs to play at different completion levels # TODO: give different answers at the end depending on how many turns you took # TODO: implement a simple statistical analysis function to track the number of turns # you take each game and give you an average score - figure out way to use that # data to improve the gameplay # TODO: make a new prompt for the lowest possible score - 3 # TODO: create a GUI # TODO: make the code more elegant and compact (low priority) # TODO: improve code documentation # notes: would work better if you showed the levels bottom to top or thought of it as # each level up times 2, to line up how the thought is organized with how it's # being visually represented onscreen while True: roll = rollDie() print("\nYou rolled a {0}. Your pyramid looks like this - \n\n{1}\n{2}\n{3}\n".format(roll, top, middle, bottom)) while True: turns += 1 placement = input("Where do you want to place it? (top, middle, bottom): ") if placement.lower() in acceptable: if placement.lower() in topList : top += roll elif placement.lower() in middleList: middle += roll elif placement.lower() in bottomList: bottom += roll elif placement.lower() == 'hack': top = 1 middle = 2 bottom = 4 break else: print("\n'fraid that won't do. Try again.\n") if (top == middle/2) & (middle == bottom/2): if turns == 3: print("\nGoddamn. 3 turns. The best I've ever seen.\n") elif turns < 3: print("\ny0u cH471nG fUuUck\n\n\n--\n\n\n-----\n\n\n-\n\n{0}\n".format(turns)) elif turns <= 10: print("\nHey! You won in {0} turns. Give yourself a pat on the back.\n".format(turns)) elif turns <= 20: print("\n{0} turns? You did all right this time.\n".format(turns)) else: print("\nAt least you won. {0} turns...\n".format(turns)) break else: continue
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question