├── A) Dice with Death.py ├── B) Hacker.py ├── Bonus Games ├── The King's Curse.py ├── The Road to Eden │ ├── Info.txt │ └── The Road to Eden.py └── Who Dares Win │ ├── Who Dares Win.py │ ├── high.txt │ └── name.txt ├── C) The Lord, The Hunter and The Fox game.py ├── D) Mini gamble.py ├── E) Battle Master.py ├── F) Blood Pit .py ├── G) Dungeon Hack.py ├── H)The Haunted House.py ├── I ) A Grots Life ( Version B ) ├── game.py ├── goblin.py ├── info (alternative) .py ├── info.py └── mood.py ├── I) A Grots Life( Version A ) .py ├── J) The Slumber of the Doom King.py ├── K) Space Rescue .py ├── L) One click rpg.py └── README.md /A) Dice with Death.py: -------------------------------------------------------------------------------- 1 | import random, sys # This 'import' the random and sys module which will be used in the programme 2 | # This will provide access additional functions within the module. 3 | # From example : random.randint (From the random module) and sys.exit() (From the sys module) 4 | def intro(): 5 | 6 | print("You are playing dice with death") 7 | print("Win and live another day, lose and your soul is doomed") 8 | 9 | input("press enter to continue") # Allows user to 'input' info but because it is not tied to a variable 10 | # the info is lost. In this instance it is used to 'pause' the game 11 | def game(): 12 | 13 | print("death rolls first") 14 | death_roll=random.randint(1,12) # 'randint' is an example of a method .A method is a function that is tied 15 | print( "death rolls",death_roll) # to an object ( which is random) 16 | input("press enter to continue") 17 | your_roll=random.randint(1,12) 18 | print("you roll",your_roll) 19 | input("press enter to continue") 20 | 21 | while death_roll == your_roll: 22 | print("you will need to play again") 23 | game() 24 | 25 | if death_roll>your_roll: 26 | print("You lose the game and your life") 27 | 28 | if your_roll>death_roll: 29 | print("You win and live another day") 30 | 31 | play_again = input("Play again? (yes/no)") 32 | play_again= play_again.lower() 33 | 34 | if play_again =="no": # Simple example of if statement. If you type in 'no' it will quit the game 35 | input("Good bye, press enter to quit ") 36 | sys.exit() 37 | 38 | intro() # If you write anything aisde from 'no' it will trigger the intro and game function again 39 | game() # hence repeating the game. 40 | 41 | intro() # A function will need to be 'called'/invoked before it does anything, eg: intro(),game() 42 | game() 43 | 44 | #Variables 45 | 46 | # A variable is a container for storing data values. It is like a box to store something 47 | # example : death_roll is a variable. A dice roll between 1 to 12 will be stored within the variable 'death_roll' 48 | # In the next game 'Hacker' I will be providing more examples of variables. 49 | 50 | # Functions 51 | 52 | # A function is a block of organized, 53 | # reusable code that is used to perform a single, related action 54 | # They are like little machines that needs to be switched on (invoked/called) before they do anything 55 | 56 | # def intro() is a user defined function (created by the user) 57 | 58 | # print and input are examples of inbuilt functions. 59 | 60 | 61 | # Conditional Statements 62 | 63 | # If statement 64 | 65 | # The if statement is the most simple decision-making statement. It is used to decide whether a certain statement 66 | # or block of statements will be executed or not. 67 | 68 | #https://github.com/Ninedeadeyes/15-mini-python-games- 69 | -------------------------------------------------------------------------------- /B) Hacker.py: -------------------------------------------------------------------------------- 1 | print("You are a hacker and attempting to hack Robert's bank account") 2 | print(" ") 3 | input(" press enter to continue") 4 | print(" ") 5 | print("You know he is 24 years old and like cats and work as an accountant") 6 | print(" ") 7 | 8 | input(" press enter to continue") 9 | 10 | print ("Welcome to Catwest Security System") 11 | 12 | raw = input("Enter the Password ") 13 | 14 | password=raw.lower() # any input typed will become lower case 15 | # 'lower' is an in-built method 16 | attempt=0 17 | 18 | while password != 'bob': # When password is 'bob' this will break 19 | print("Access denied") # the while loop and then the next line 20 | attempt+=1 # of code will play eg: print ("Access granted") 21 | 22 | 23 | if attempt == 1: 24 | print(" Tip(It has 3 letters)") 25 | 26 | if attempt == 3: 27 | print(" Tip(Begins with a 'B')") 28 | 29 | if attempt == 5: 30 | print(" Tip( Relates to his name)") 31 | 32 | if attempt == 7: 33 | print(" Tip( Ends with a 'B')") 34 | 35 | if attempt == 8: 36 | break 37 | 38 | raw = input("Enter the Password ") 39 | 40 | password=raw.lower() 41 | 42 | if attempt !=8: 43 | print("Access granted") 44 | input("press enter to exit") # In theory you can click any button to exit 45 | 46 | else: 47 | print("too many attempts") 48 | input("press enter to quit") 49 | 50 | #Variables 51 | 52 | # A variable is a container for storing data values. It is like a box to store something 53 | # example : attempt=0 is a variable. The variable 'attempt' stores how many times you attempted the password. 54 | # raw is also a variable that is attached to the inbuilt function 'input' which means anything you type when it request 55 | # the password it will store it into 'raw'. 56 | 57 | # While loop 58 | 59 | # Python while loop is used to run a block code until a certain condition is met. 60 | # In the below example while password is not 'bob' it will keep playing the looping until 61 | # either password is 'bob' or on the 8th attempt with the 'break' keyword which will break 62 | # the loop 63 | 64 | # Conditional Statements 65 | 66 | # else statement 67 | 68 | #An else statement contains the block of code that executes 69 | #if the conditional expression in the if or ELIF statement resolves to 0 or a FALSE value 70 | 71 | 72 | # Examples of Python operators 73 | 74 | #!= is not equal 75 | # += add 76 | # -= minus 77 | # == equals 78 | # > Greater than 79 | # < less than 80 | # >= Greater than or equal to 81 | # <= Less than or equal to 82 | 83 | #https://github.com/Ninedeadeyes/15-mini-python-games- 84 | 85 | -------------------------------------------------------------------------------- /Bonus Games/The King's Curse.py: -------------------------------------------------------------------------------- 1 | cure=False 2 | goblin =False 3 | quest1=False 4 | potion=False 5 | 6 | print (" The King's Curse ") 7 | print (" Art by eVil, Glory Moon, Dustin Slater and Joan Stark ") 8 | print 9 | print (""" 10 | 11 | ___,---.__ /'|`\ __,---,___ 12 | ,-' \` `-.____,-' | `-.____,-' // `-. 13 | ,' | ~'\ /`~ | `. 14 | / ___// `. ,' , , \___ \ 15 | | ,-' `-.__ _ | , __,-' `-. | 16 | | / /\_ ` . | , _/\ \ | 17 | \ | \ \`-.___ \ | / ___,-'/ / | / 18 | \ \ | `._ `\\ | //' _,' | / / 19 | `-.\ /' _ `---'' , . ``---' _ `\ /,-' 20 | `` / \ ,='/ \`=. / \ '' 21 | |__ /|\_,--.,-.--,--._/|\ __| 22 | / `./ \\`\ | | | /,//' \,' \ 23 | / / ||--+--|--+-/-| \ \ 24 | | | /'\_\_\ | /_/_/`\ | | 25 | \ \__, \_ `~' _/ .__/ / 26 | `-._,-' `-._______,-' `-._,-' 27 | 28 | """) 29 | 30 | Name=input("What is your name brave adventurer ? ") 31 | print("Hello "+Name) 32 | print("Someone has turned the King into stone. Your Quest is to remove the curse !!!") 33 | 34 | while cure==False: 35 | print(" ") 36 | print("Where do you want to go ? (A,B,C or D ") 37 | print ("A) Castle B) The Old Hags Hut C) The Wild Forest D) Fortress of Doom") 38 | Choice=input() 39 | Choice=Choice.lower() 40 | 41 | if Choice=="a": 42 | print (""" 43 | 44 | -| |- 45 | -| [-_-_-_-_-_-_-_-] |- 46 | [-_-_-_-_-] | | [-_-_-_-_-] 47 | | o o | [ 0 0 0 ] | o o | 48 | | | -| | | |- | | 49 | | |_-___-___-___-| |-___-___-___-_| | 50 | | o ] [ 0 ] [ o | 51 | | ] o o o [ _______ ] o o o [ | ----__________ 52 | _____----- | ] [ ||||||| ] [ | 53 | | ] [ ||||||| ] [ | 54 | _-_-|_____]--------------[_|||||||_]--------------[_____|-_-_ 55 | ( (__________------------_____________-------------_________) ) 56 | 57 | """) 58 | 59 | if potion==True: 60 | cure=True 61 | 62 | else: 63 | print("You go back to the castle with empty hands.") 64 | 65 | if Choice=="b": 66 | print(""" 67 | 68 | 69 | /^\ 70 | // \\ ,@@@@@@@, 71 | // \\ ,@@@\@@@@/@@, 72 | // === \\ @@\@@@/@@@@@ 73 | // =-=-= \\@@@@\@@@@@@;% 74 | // === \\@@@@@@/@@@%%%, 75 | //| |\\@\\//@@%%%%%% 76 | ~ | | ~ @|| %\\//%%% 77 | | __ __ | || %%||%%' 78 | | | | | | || || 79 | | | -|- | | || || 80 | |_|__|__|_| || || 81 | /` ======= `\__||_._|| 82 | /` ======= `\ 83 | 84 | """) 85 | 86 | if quest1==True and goblin ==True: 87 | print("The old hag thank you for your help and wish you the best in your quest.") 88 | 89 | if quest1==False and goblin ==True: 90 | 91 | print("As you approach the old hag's hut, you see an old hag smiling at you. ") 92 | print("she thank you for saving her pet goblin and is willing to help your quest.") 93 | print("she tells you that there is a magical potion in the Fortress of Doom. ") 94 | print("It will cure the King. She provides you with a map and the location. ") 95 | print("Before you leave she informs you of the fortress password 'DARKSTONE'") 96 | quest1=True 97 | 98 | if quest1 == False and goblin == False: 99 | print("As you approach the old hag's hut, an army of crows chase you away.") 100 | 101 | if Choice=="c": 102 | print("You enter the wild forest....") 103 | 104 | print(""" 105 | 106 | * * 107 | * * * 108 | * * * * * 109 | * * * * * 110 | * * * * * * * 111 | * * * * * .# * * 112 | * * * #. .# * * 113 | * "#. #: #" * * * 114 | * * * "#. ##" * 115 | * "### 116 | "## 117 | ##. 118 | .##: 119 | :### 120 | ;### 121 | ,####. 122 | /\/\/\/\/\/.######.\/\/\/\/\ 123 | 124 | """) 125 | 126 | if goblin==False: 127 | print ("You see a goblin trapped in some bramble do you help (YES OR NO) ") 128 | Help=input() 129 | Help.lower() 130 | 131 | if Help=="yes"or Help=="YES": 132 | print ("You help the goblin, the goblin runs back home.") 133 | goblin=True 134 | 135 | else: 136 | print("You see nothing of importance here, maybe you will go hunting later") 137 | 138 | if Choice=="d": 139 | 140 | print(""" 141 | 142 | `,. . . * . . . _ .. . 143 | \,~-. * . . )) * . 144 | \ * . . | * . . ~ . . . , 145 | , `-. . : * ,- 146 | - `-. *._/_\_. . . ,-' 147 | - `-_., |n| . . ; 148 | - \ ._/_,_\_. . . ,' , 149 | - `-.|.n.| . ,-.__,' - 150 | - ._/_,_,_\_. ,-' - 151 | - |..n..|-`'-' - 152 | - ._/_,_,_,_\_. - 153 | - ,-|...n...| - 154 | - ,-'._/_,_,_,_,_\_. - 155 | - ,-=-' |....n....| - 156 | -; ._/_,_,_,_,_,_\_. - 157 | ,- |.....n.....| - 158 | ,; ._/_,_,_,_,_,_,_\_. - 159 | `, '. `. ". `, '.| n ,-. n | ", `. `, '. `, ', 160 | ,.:;..;;..;;.,:;,.;:,o__|__o !.|.! o__|__o;,.:;.,;;,,:;,.:;,;;: 161 | ][ ][ ][ ][ ][ |_i_i_H_|_|_|_H_i_i_| ][ ][ ][ ][ ][ 162 | | //=====\\ | 163 | |____//=======\\____| 164 | //=========\\ 165 | 166 | """) 167 | if quest1==True and potion == False: 168 | 169 | while potion ==False: 170 | print("You stand at the entrance of the Fortress of Doom.") 171 | print("You hear a booming voice.. 'Halt, what is the password ?") 172 | Answer=input() 173 | Answer=Answer.lower() 174 | 175 | if Answer=="darkstone": 176 | print("They allow you into the Fortress and you quickly locate the magical potion.") 177 | potion=True 178 | 179 | else: 180 | 181 | print(" INCORRECT !! NOW FEAR MY POWER !! ") 182 | print("A great fireball consumes your body and ends your adventure") 183 | print(" GAME OVER ") 184 | print (""" 185 | 186 | 187 | / \\ 188 | /\\ | . . \\ 189 | ////\\| || 190 | //// \\ ___//\ 191 | /// \\ \ 192 | /// |\\ | 193 | // | \\ \ \ 194 | / | \\ \ \ 195 | | \\ / / 196 | | \/ / 197 | | \\/| 198 | | \\| 199 | | \\ 200 | | | 201 | |_________\ 202 | 203 | """) 204 | 205 | print("Press any button to exit the game") 206 | input() 207 | exit() 208 | 209 | else: 210 | print("You arrive at the Fortress of Doom but with no purpose, you quickly leave.") 211 | 212 | print("You pour the magical potion over the King's stone body.") 213 | print("It has worked, the curse is removed.") 214 | print("You are rewarded with 10,000 gold !!! ") 215 | print(" ") 216 | print (" GAME OVER ") 217 | print(" ") 218 | print(" ") 219 | 220 | print(""" 221 | 222 | 223 | (_) 224 | .-'-. 225 | | | 226 | | | 227 | | | 228 | | | 229 | __| |__ .-. 230 | .-' | | `-: : 231 | : `---' :-' 232 | `-._ _.-' 233 | '"""""" 234 | 235 | """) 236 | 237 | input("press enter to exit") 238 | 239 | #https://github.com/Ninedeadeyes/15-mini-python-games- 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | -------------------------------------------------------------------------------- /Bonus Games/The Road to Eden/Info.txt: -------------------------------------------------------------------------------- 1 | One of your men is sick and is slowing down your journey. What do you do?# A) Leave him behind B) Let him be carried#H#S# 2 | You see a Unicorn trapped in some bramble. What do you do?#A) Help her out of the bramble B) Ignore it because Unicorns don't exist#S#H# 3 | You come across an injured man. What do you do?#A) Treat the man and find him some shelter B) Treat the man but quickly#S#H# 4 | Your men need some rest and are complaining. What do you do? #A) Keep pushing ahead B) Stop for a little rest#H#S# 5 | You see a nearby village engulfed in flames. What do you do?#A) Let them burn B)Help put out the fire#H#S# 6 | You see a merchant who's caravan has broken down. What do you do?#A)Ransack the caravan B) Fix the broken caravan#E#S# 7 | END#END#END#END# 8 | -------------------------------------------------------------------------------- /Bonus Games/The Road to Eden/The Road to Eden.py: -------------------------------------------------------------------------------- 1 | print(" The Road to Eden ") 2 | print("You and your men are on an urgent mission to get to City of Eden") 3 | print("to deliver an important message. Will you get there on time? ") 4 | print(" ") 5 | 6 | file= open ("info.txt","r") # This will open up the text file and r = read mode 7 | line=file.readline() # This will read each line of your text and then the next 8 | Info=line.split("#") # This will split the line/list by each # eg: Info[0],Info[1] 9 | 10 | Match=[] # An empty list 11 | 12 | while Info[0]!= "END": 13 | print(Info[0]) 14 | print(" ") 15 | print(Info[1]) 16 | print(" ") 17 | guess=input("(A or B): ") 18 | guess=guess.upper() 19 | 20 | if guess == "A": 21 | Match.append(Info[2]) 22 | line=file.readline() 23 | Info=line.split("#") 24 | 25 | elif guess=="B": 26 | Match.append(Info[3]) 27 | line=file.readline() 28 | Info=line.split("#") 29 | 30 | else: 31 | guess=input("Number not allowed,try again ") 32 | 33 | hard=Match.count("H") # Add up the number of 'H' eg if there is 3xH, hard=3 34 | soft=Match.count("S") 35 | evil=Match.count("E") 36 | 37 | if evil==1: 38 | print ("Even though you reach Eden, you are quickly arrested for crimes against humanity ") 39 | 40 | elif hard > soft: 41 | print ("Even though you reach Eden, your crew abandons you for being too cruel") 42 | 43 | elif soft > hard: 44 | print ("You fail to reach Eden. You wasted too much time along the way") 45 | 46 | elif soft==hard: 47 | print ("Congratulations, you reach Eden on time. Your men celebrate your victory") 48 | 49 | #https://github.com/Ninedeadeyes/15-mini-python-games- 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Bonus Games/Who Dares Win/Who Dares Win.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | 4 | turn=True 5 | game=True 6 | counter=0 7 | goal=0 8 | numberlist1=[0,7] 9 | numberlist2=[1,2] 10 | 11 | while game: 12 | os.system('cls') 13 | counter=0 14 | goal=0 15 | print(" Who Dares Win " ) 16 | print(" ") 17 | print("The aim of the game is to roll the dice as many times as possible, ") 18 | print("without the total going over 21. Each successful roll you will gain 5 points") 19 | print("There will be a selection of dices to choose from. ") 20 | print(" Will you acquire the highest score ?") 21 | print(" ") 22 | with open("high.txt", "r") as f: 23 | old_score = f.read() 24 | print("The highest score is ",old_score) 25 | high_score=int(old_score) 26 | 27 | with open("name.txt", "r") as r: 28 | old_name = r.read() 29 | print("by ",old_name) 30 | print(" ") 31 | 32 | while goal <21: 33 | while turn: 34 | decide=input("Pick dice(1,2,3 or 4)") 35 | 36 | if decide==("1"): 37 | dice=random.randint(2,5) 38 | break 39 | 40 | if decide==("2"): 41 | dice=random.randint(1,6) 42 | break 43 | 44 | if decide==("3"): 45 | dice=random.choice(numberlist1) 46 | break 47 | 48 | if decide==("4"): 49 | dice=random.choice(numberlist2) 50 | bob=random.randint(2,4) 51 | counter-=bob 52 | print("You lose ", bob, " points") 53 | break 54 | 55 | else: 56 | print ("Wrong choice") 57 | 58 | input("press enter to roll dice" ) 59 | print("you rolled a",dice) 60 | goal+=dice 61 | print("The total is ",goal) 62 | counter+=5 63 | again=input("keep playing? Y/N") 64 | again=again.upper() 65 | 66 | if again==("N"): 67 | break 68 | 69 | else: 70 | pass 71 | 72 | if goal>21: 73 | print("Sorry you went over 21") 74 | input("Press enter to exit") 75 | break 76 | 77 | else: 78 | new_score=counter 79 | print("You score",new_score) 80 | 81 | if new_score >high_score: 82 | print("Congratulations,you have got the highest score !! ") 83 | New_name=input( " Enter your name :") 84 | best_name=open("name.txt",'w') 85 | best_name.write(New_name) 86 | best_name.close() 87 | 88 | new_score=str(new_score) 89 | best_score=open("high.txt",'w') 90 | best_score.write(new_score) 91 | best_score.close() 92 | 93 | print("The new highest score is", new_score) 94 | print("by : ",New_name) 95 | again=input("play again? Y/N") 96 | again=again.upper() 97 | 98 | if again == ("Y"): 99 | pass 100 | 101 | else: 102 | input("Press enter to exit") 103 | break 104 | 105 | else: 106 | print("You did not beat the previous highest score of", high_score, "by ",old_name) 107 | again=input("play again? Y/N") 108 | again=again.upper() 109 | 110 | if again == ("Y"): 111 | pass 112 | 113 | else: 114 | input("Press enter to exit") 115 | break 116 | 117 | #https://github.com/Ninedeadeyes/15-mini-python-games- 118 | -------------------------------------------------------------------------------- /Bonus Games/Who Dares Win/high.txt: -------------------------------------------------------------------------------- 1 | 30 -------------------------------------------------------------------------------- /Bonus Games/Who Dares Win/name.txt: -------------------------------------------------------------------------------- 1 | Tom -------------------------------------------------------------------------------- /C) The Lord, The Hunter and The Fox game.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | list1= ["fox","hunter","lord"] 4 | 5 | print("This is an alternative game of rock, paper and scissors ") 6 | print("") 7 | win_count=0 8 | lose_count=0 9 | win=True 10 | 11 | while win: 12 | cpu=random.choice(list1) 13 | user=input("Enter your choice:[fox, hunter, lord] or exit : ") 14 | user=user.lower() 15 | 16 | if (user=="fox" and cpu=="lord")or(user=="hunter" and cpu=="fox")or (user=="lord" and cpu=="hunter"): 17 | print("computer choose " , cpu) 18 | print("You have won") 19 | win_count+=1 20 | 21 | elif (user=="lord" and cpu=="fox")or(user=="fox" and cpu=="hunter")or (user=="hunter" and cpu=="lord"): 22 | print("computer choose " , cpu) 23 | print("You lose") 24 | lose_count+=1 25 | 26 | elif user==cpu: 27 | print("computer choose " , cpu) 28 | print("It is a draw") 29 | 30 | 31 | elif user=="exit": 32 | print("Goodbye") 33 | print("you won, ", win_count,"times.", "You lose,",lose_count,"times.") 34 | win=False 35 | 36 | else: 37 | print("not valid") 38 | 39 | # List 40 | 41 | # List is a Data Structure (a specialized format for organizing, processing, retrieving and storing data. ) 42 | # Lists are used to store multiple items in a single variable, eg : list1= ["fox","hunter","lord"] 43 | 44 | # Conditional Statements 45 | 46 | # elif statement 47 | 48 | #The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition". 49 | # At the above example if it is none of the decisions it will try the condition 'else' 50 | 51 | #https://github.com/Ninedeadeyes/15-mini-python-games- 52 | 53 | -------------------------------------------------------------------------------- /D) Mini gamble.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def dice(): 4 | total = 120 5 | game = "Y" 6 | 7 | while (game == "Y"or game =="y"): 8 | print (" you have = ", total, "Gold") 9 | bbet = input("how much do you bet ? : ") 10 | bet = int(bbet) # Turns the input into a 'number value' from a string value because a string can't interact with an integer (whole number) 11 | while bet > total: 12 | print("You don't have the money, Please bet again") 13 | bbet = input("how much do you bet ?") 14 | bet = int(bbet) 15 | 16 | print (r""" \_1_/ \_2_/ \_3_/ """) # Prefix the string with an r to treat it as a raw string, which tells Python not to interpret escape sequences within the string. 17 | guess= input("Which pot is the stone in ? : ") 18 | guess=int(guess) 19 | while guess >3: 20 | print("It is out of 3 !!") 21 | guess= input("Which pot is the stone in ? : ") 22 | guess=int(guess) 23 | die1 = random.randint(1,3) 24 | print ("It is under pot ", die1) 25 | if die1 !=guess: 26 | print ("You lose") 27 | total-=bet 28 | else: 29 | print ( "You win") 30 | total+=bet*2 31 | 32 | if total<=0: 33 | input("Go home you have no more gold left, press enter to escape ") 34 | break # Automatically break the while loop hence ending the game 35 | game = input("Play again? (Y/N)") # At the end of each game will ask if player want to play again 36 | game= game.upper() 37 | 38 | if game== "N": # If player answer N, it will break the loop because game has to be Y 39 | # Will finish the loop hence provide final amount of gold before breaking. 40 | print (" final amount = ", total, "Gold") 41 | input("Good bye, press enter to escape") 42 | 43 | dice() 44 | 45 | #https://github.com/Ninedeadeyes/15-mini-python-games- 46 | -------------------------------------------------------------------------------- /E) Battle Master.py: -------------------------------------------------------------------------------- 1 | import time, random 2 | counter=0 3 | player1=0 4 | player2=0 5 | 6 | def player1_win(): 7 | print("Orcs win the battle") 8 | global player1 # Generally speakin Global keyword is the worst 9 | player1+=1 # approach to interact with variable outside the 10 | # function but its good to know how to do it 11 | def player2_win(): # Better methods is using data structure like list or OOP (CLASS) 12 | print("Humans win the battle") 13 | global player2 14 | player2+=1 15 | 16 | while True: 17 | print("""The war between Orcs and Humans rage on forever 18 | "You are the new commander, you have 100 men which you have to 19 | allocate to the apprioate position to win the war """) 20 | 21 | #The try and except block in Python is used to catch and handle exceptions. 22 | 23 | while True: 24 | knight=input("how many Knights ?") 25 | try: 26 | int(knight) 27 | break 28 | except: 29 | print("This is not a number") 30 | 31 | while True: 32 | farmer=input("how many Farmers ?") 33 | try: 34 | int(farmer) 35 | break 36 | except: 37 | print("This is not a number") 38 | 39 | 40 | while True: 41 | defender=input("how many Defenders ?") 42 | try: 43 | int(defender) 44 | break 45 | except: 46 | print("This is not a number") 47 | 48 | tog=int(defender)+int(farmer)+int(knight) 49 | 50 | if tog>100: 51 | print("You have allocated over 100") 52 | else: 53 | print("You have",str(defender),"Defenders.You have",str(farmer),"Farmers and" 54 | ,str(knight),"Knights") 55 | break 56 | 57 | while True: 58 | while True: 59 | counter+=1 60 | print("The battle rages on and on ..") 61 | time.sleep(.5) 62 | print("...") 63 | time.sleep(.5) 64 | print("...") 65 | time.sleep(.5) 66 | print("...") 67 | if counter==3: 68 | break 69 | 70 | print("A victor has been decided") 71 | x=random.randint(1,3) 72 | time.sleep(x) 73 | 74 | defender1=int(defender)+random.randint(1,15) 75 | farmer1=int(farmer)+random.randint(1,10) 76 | knight1=int(knight)+random.randint(1,15) 77 | 78 | if defender1>=35 and farmer1>=15 and knight1>=50: 79 | player2_win() 80 | else: 81 | player1_win() 82 | 83 | print("Orc victory:"+str(player1)+" Human victory:"+str(player2)) 84 | counter=0 85 | 86 | if player1==5: 87 | print("""The Orcs has won the war. You have been defeated !!""") 88 | break 89 | 90 | if player2==5: 91 | print("The Humans has won the war, congratulations !!") 92 | break 93 | 94 | input("Press enter to exit") 95 | 96 | #https://github.com/Ninedeadeyes/15-mini-python-games- 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /F) Blood Pit .py: -------------------------------------------------------------------------------- 1 | hero_max_power=20 2 | hero_max_health=300 3 | hero_health=[300] # This is a list [] with only one item 4 | hero_power=[20] 5 | turn_counter=0 6 | rep=0 7 | 8 | def enemy(name,a,b): 9 | print(name+" "+str(a)+"hp "+str(b)+" power") 10 | health=a 11 | power=b 12 | hh= hero_health[0] # Within a 'list' the first item will be in [0] whilst the second will be in [1]. 13 | hp= hero_power[0] # If hero's health wasn't in a list, the enemy function would not acknowledge it 14 | while hh>0 or health>0: 15 | (hh)-=(power) 16 | (health)-=(hp) 17 | print("The "+name+" attack you.Your health is "+str(hh)) 18 | print("You attack the "+name+".The "+name+" health is "+ str(health)) 19 | 20 | if hh<=0: 21 | print("hero has been slained") 22 | input("Press enter to quit") 23 | quit() 24 | 25 | if health<=0: 26 | print("You have slained the "+name) 27 | break 28 | 29 | while True: 30 | print("Welcome to the blood pit, choose your opponent!! ") 31 | choose=input( "Please select goblin, orc, pit fighter or red dragon: ") 32 | choose=choose.upper() 33 | 34 | while choose == "GOBLIN" or "ORC" or "PIT FIGHTER" or "RED DRAGON": 35 | print("your opponent is a...") 36 | 37 | if choose==("GOBLIN"): 38 | enemy("Goblin",200,20) 39 | rep+=10 40 | hero_max_health+=20 41 | hero_health[0]=hero_max_health 42 | hero_max_power+=5 43 | hero_power[0]=hero_max_power 44 | print("you become stronger with every goblin you slay") 45 | print("you gain some reputation for the fight") 46 | print("Totol Reputation: "+ str(rep)) 47 | break 48 | 49 | elif choose==("ORC"): 50 | enemy("Orc",400,60) 51 | rep+=50 52 | hero_max_health+=40 53 | hero_health[0]=hero_max_health 54 | hero_max_power+=10 55 | hero_power[0]=hero_max_power 56 | print("you become more powerful with every orc you crush") 57 | print("you gain some reputation for the fight") 58 | print("Totol Reputation: "+ str(rep)) 59 | break 60 | 61 | 62 | elif choose==("PIT FIGHTER"): 63 | enemy("Pit Fighter",500,200) 64 | rep+=100 65 | hero_max_health+=60 66 | hero_health[0]=hero_max_health 67 | hero_max_power+=20 68 | hero_power[0]=hero_max_power 69 | print("you gain experience for every pit fighter you battle") 70 | print("you gain some reputation for the fight") 71 | print("Totol Reputation: "+ str(rep)) 72 | break 73 | 74 | elif choose==("RED DRAGON"): 75 | enemy("Red Dragon",1500,400) 76 | rep+=300 77 | hero_max_health+=70 78 | hero_health[0]=hero_max_health 79 | hero_max_power+=30 80 | hero_power[0]=hero_max_power 81 | print("You become more vicious for every red dragon you face") 82 | print("you gain some reputation for the fight") 83 | print("Totol Reputation: "+ str(rep)) 84 | break 85 | 86 | else: 87 | print("Try again") 88 | break 89 | 90 | turn_counter+=1 91 | print("It is turn "+str(turn_counter)) 92 | 93 | if rep>2000: 94 | print("You are the master of the blood pit") 95 | print("You beat the game in turn "+ str(turn_counter)) 96 | input("You win, press enter to exit") 97 | break 98 | 99 | #https://github.com/Ninedeadeyes/15-mini-python-games- 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /G) Dungeon Hack.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def game(): 4 | print("Choose your party and enter the dungeon") 5 | print("to slay the beast and steal his treasure !! ") 6 | print("") 7 | 8 | print( "Fighter, ","Wizard, ","Thief, ","Paladin, ","Rogue ") 9 | group=[] # An empty list which begins with no items 10 | open_slot= True 11 | loop=0 12 | power=0 13 | scout=0 14 | magic=0 15 | 16 | while open_slot: 17 | user_input=input("who are you going to take with you ? : ") 18 | user_input=user_input.upper() 19 | 20 | if user_input=="FIGHTER": 21 | print("you have chosen the Fighter") 22 | group.append(user_input) 23 | power+=5 24 | 25 | elif user_input=="THIEF": 26 | print("you have chosen the Thief") 27 | group.append(user_input) 28 | scout+=5 29 | 30 | elif user_input=="WIZARD": 31 | print("you have chosen the Wizard") 32 | group.append(user_input) 33 | magic+=5 34 | 35 | elif user_input=="ROGUE": 36 | print("you have chosen the rogue") 37 | group.append(user_input) 38 | scout+=random.randint(2,5) 39 | power+=random.randint(2,5) 40 | 41 | elif user_input=="PALADIN": 42 | print("you have chosen the Paladin") 43 | group.append(user_input) 44 | power+= random.randint(2,5) 45 | magic+= random.randint(2,5) 46 | 47 | else: 48 | print("not a valid choice, but don't worry i'll pick someone for you") 49 | list=("VILLAGE IDIOT","SNOTLING JESTER","PROFESSIONAL COWARD","SAD CLOWN") 50 | wildcard=random.choice(list) 51 | group.append(wildcard) 52 | power+= random.randint(1,3) 53 | magic+=random.randint(1,3) 54 | scout+=random.randint(1,2) 55 | 56 | loop+=1 57 | 58 | if loop==4: 59 | open_slot= False 60 | 61 | print("Your party is full, it is time to begin your adventure") 62 | print("You party consist of:") 63 | for x in range(len(group)): # This only really numbers your characters in your group 64 | print (x+1,group[x]) # For x in range = For every 'item' in the group whilst len find the length of the list which will be (4) 65 | # x+1 because range starts at 0, group[x]=acquire the value of the 'item' which will be PALADIN,ROGUE etc etc 66 | dungeon=input(" Pick dungeon: Hard or Easy ?") 67 | dungeon=dungeon.lower() 68 | input("You go into the dungeon and.... ") 69 | 70 | if dungeon== "hard": 71 | 72 | if power>=12 and scout>=5 and magic>=7: 73 | print ("You slay the beast and find the treasure !!, you win all the loot ") 74 | print ("Your party stats are : power=",power, "scout=",scout,"magic=",magic) 75 | 76 | elif power>12 and scout>=5 and magic<7: 77 | print("You slay the beast but did not find any treasure, you lose") 78 | print ("Your party stats are : power=",power, "scout=",scout,"magic=",magic) 79 | else: 80 | print("you are defeated by the beast, your party was too weak, you lose ") 81 | print ("Your party stats are : power=",power, "scout=",scout,"magic=",magic) 82 | 83 | print("Game over") 84 | play=input("play again Y/N ? : ") 85 | if play == "y" or"Y": 86 | game() 87 | else: 88 | print("good bye") 89 | quit() 90 | 91 | else: 92 | 93 | if power>=10 and scout>=5 and magic>=5: 94 | print ("You slay the beast and find the treasure !!, you win, try the hard dungeon ") 95 | print ("Your party stats are : power=",power, "scout=",scout,"magic=",magic) 96 | 97 | elif power>10 and magic>=5 and scout<5: 98 | print("You slay the beast but did not find any treasure, you lose") 99 | print ("Your party stats are : power=",power, "scout=",scout,"magic=",magic) 100 | else: 101 | print("you are defeated by the beast, your party was too weak, you lose ") 102 | print ("Your party stats are : power=",power, "scout=",scout,"magic=",magic) 103 | 104 | print("Game over") 105 | play=input("play again Y/N ? : ") 106 | if play == "y" or"Y": 107 | game() 108 | else: 109 | print("good bye") 110 | quit() 111 | 112 | game() 113 | 114 | #https://github.com/Ninedeadeyes/15-mini-python-games- 115 | 116 | -------------------------------------------------------------------------------- /H)The Haunted House.py: -------------------------------------------------------------------------------- 1 | # There is an explanation of what a dictionary and nested dictionary are at the very bottom. 2 | 3 | def showInstructions(): 4 | print(''' 5 | The Haunted House 6 | 7 | Escape the house with its riches but beware of the evil undead !! 8 | 9 | Commands: 10 | 11 | use [item] eg: use key 12 | 13 | shoot[monster] eg: shoot zombie 14 | 15 | go [direction] eg: go south 16 | 17 | get [item] eg: get bandage 18 | 19 | commands ( To view a list of commands) 20 | 21 | ''') 22 | 23 | health= 100 24 | 25 | def showStatus(): 26 | 27 | print('You are in the ' + currentRoom) 28 | print (rooms[currentRoom]['desc']) 29 | print("Inventory : " + str(inventory)) 30 | print("Your health is",health) 31 | if "item" in rooms[currentRoom]: 32 | print('You see a ' + rooms[currentRoom]['item']) 33 | print("---------------------------") 34 | 35 | inventory = [] 36 | 37 | monster=[] 38 | 39 | rooms = { 40 | 41 | 'Hall' : {'south' : 'Kitchen', 42 | 'east' : 'Dining Room', 43 | "north":"Bed Room", 44 | 'item' : 'shotgun', 45 | 'monster' : '', "desc":"No one has been here for a while", 46 | }, 47 | 48 | 'Kitchen' : { 'north' : 'Hall', 49 | "item":"golden_crown", 50 | 'monster' : 'zombie',"desc":"Dead bodies scatter the floor", 51 | }, 52 | 53 | 'Dining Room' : { 'west' : 'Hall', 54 | 'south' : 'Garden', 55 | 'item' : 'key', 56 | 'monster' : 'zombie',"desc":"Old painting hangs on the wall", 57 | }, 58 | 59 | 'Garden' : { 'north' : 'Dining Room', 60 | 'monster' : '', "desc": "There is a locked gate here", 61 | }, 62 | 63 | 'Bed Room' : {'south' : 'Hall', 64 | 'item' : 'bandage', 65 | 'monster' : 'ghoul',"desc":"There is blood all over the bed ", 66 | }, 67 | } 68 | 69 | currentRoom = 'Hall' 70 | 71 | showInstructions() 72 | 73 | while True: 74 | 75 | showStatus() # Everytime it refresh it will show you up to date status 76 | 77 | move = '' 78 | while move == '': 79 | move = input('>') # If you click enter with no command it will just ask for input 80 | 81 | move = move.lower().split() # lower case everything and split will turn a string into a list hence ' get shotgun' = move =[get,shotgun] 82 | 83 | if move[0]=="shoot": # acquire the value from index 0 of the list of 'move'. In this case if it is shoot 84 | 85 | if "monster"in rooms[currentRoom] and move[1] in rooms[currentRoom]['monster'] and "shotgun" in inventory : 86 | del rooms[currentRoom]['monster'] 87 | print( "you killed the", move[1]) 88 | rooms[currentRoom].update({"monster":"dead"},) #update merge dictionary with an iterable of key value pair 89 | 90 | else: 91 | print("you cannot attack " ) 92 | 93 | if move[0]=="use": 94 | 95 | if "bandage" in inventory and move[1]== "bandage": 96 | heal=40 97 | health=min(100,health+heal) 98 | inventory.remove("bandage") 99 | print("you recovered 40 health (max 100)") 100 | 101 | elif "key" in inventory and move[1]== "key" and "golden_crown" in inventory and currentRoom=="Garden": 102 | print("you escape with the loot, you retire in style, you win!! ") 103 | input("Press Enter to Exit") 104 | break 105 | 106 | 107 | elif "key" in inventory and move[1]== "key" in inventory and currentRoom=="Garden": 108 | print("you escape the house but die a pauper, you lose ") 109 | input("Press Enter to Exit") 110 | break 111 | 112 | else: 113 | print("can't use that") 114 | 115 | if move[0] == 'go': 116 | if move[1] in rooms[currentRoom]: 117 | currentRoom = rooms[currentRoom][move[1]] # acquire the new room (the nested value) from the 'direction'(the nested key) 118 | #eg rooms[Dining room][west] return value Hall because 'Dining Room' : { 'west' : 'Hall', within rooms dictionary hence currentRoom=Hall 119 | else: 120 | print('You can\'t go that way!') 121 | 122 | if move[0] == 'get': 123 | if 'item' in rooms[currentRoom] and rooms[currentRoom]['item'] == move[1]: # move[1] is whatever you type '== move[1]' make sure you are typing correctly before gaining the item. 124 | inventory += [rooms[currentRoom]['item']] 125 | print(rooms[currentRoom]['item'] + ' got!') 126 | del rooms[currentRoom]['item'] 127 | else: 128 | print("Can't get that") 129 | 130 | if move[0] == 'commands': 131 | print(''' 132 | Commands: 133 | 134 | use [item] eg: use key 135 | 136 | shoot[monster] eg: shoot zombie 137 | 138 | go [direction] eg: go south 139 | 140 | get [item] eg: get bandage 141 | 142 | commands ( To view a list of commands) 143 | 144 | ''') 145 | 146 | if 'zombie' in rooms[currentRoom]['monster']: 147 | print("A zombie attacks you !!!") 148 | health=health-30 149 | 150 | if 'ghoul' in rooms[currentRoom]['monster']: 151 | print('A ghoul attacks you !!!') 152 | health=health-20 153 | 154 | 155 | if health <= 0: 156 | print("you are dead") 157 | input("Press Enter to Exit") 158 | break 159 | 160 | 161 | 162 | # MAP LAYOUT 163 | 164 | # BedRoom 165 | # ^ 166 | # Hall > Dining Room 167 | # v v 168 | # Kitchen || Garden 169 | 170 | 171 | # A Dictionary will have a value and a key and you will be able to 'extract the 'value from the key. 172 | 173 | #computer = { 174 | #"brand": "NES", 175 | #"model": "Blue", 176 | #"year": 1994 } 177 | 178 | #print computer[model] will print 'Blue' so in conclusion dictionary[key] to extract the value 179 | 180 | # Nested Dictionary 181 | 182 | # You can also have a Dictionary within a Dictionary and that is called a 'Nested Dictionary 183 | # For example within the above game if you are if current Room is in 'Hall' and you instruct to 'go north' current Room will change to Bed Room 184 | # because the code currentRoom = rooms[currentRoom][move[1]] will equate to rooms[Hall][north] and the 'value' of the nested key 'north' is 'Bed Room 185 | # hence currentRoom becomes 'Bed Room'. So in conclusion dictionary[key][nested key] to extract nested value 186 | 187 | 188 | 189 | # 190 | 191 | #https://github.com/Ninedeadeyes/15-mini-python-games- 192 | -------------------------------------------------------------------------------- /I ) A Grots Life ( Version B )/game.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | from goblin import Goblin # Example of importing class (import all functions) 3 | import time 4 | 5 | 6 | 7 | # A grots life. 8 | 9 | 10 | def main(): 11 | 12 | print( " A Grot's Life By T.K ") 13 | print("") 14 | time.sleep(1) 15 | 16 | print("You open your eyes and take your first breath ") 17 | time.sleep(1) 18 | print("You hear a voice in the darkness...") 19 | time.sleep(1) 20 | print("What is your name, you filthy Grot? ") 21 | gob_name = input("Name:") 22 | print(gob_name,".. it suits you. Now, go do what grots do..") 23 | time.sleep(1) 24 | print( "Kill, eat, sleep and get precious shinies !! ") 25 | time.sleep(1) 26 | print("And maybe a place where your grubby face can call home") 27 | time.sleep(2) 28 | gob = Goblin(gob_name,0,100,0,20) 29 | print(""" 30 | . . . . . . . . . . . . . . . 31 | . @%%@ . . . @%%@ X . . . . 32 | . . . @::8@t;::::;::;::::.:@S;::@ .X.X; . . . 33 | . .tt%X :S%tXSStXStX%8S@tt8X:: X .;X. . . . 34 | . . . .;88S:;;8@8X@8XX::;8... . X.::; X. . 35 | . . . 8:. 8:8. X:::;;: X . . . . 36 | . . 8:. @.8: . X::.:;::::X . . 37 | . . . . 8:. @.8. :@ . . . 38 | . . . .8.: S.8.. ..; :@ . . . 39 | . . . 8:: @.8: .: :@ . . . . 40 | . . .. :.tt8.::::::::::::Xt%t... ..;@ . . 41 | . ::.;X:.::t%%%%%%t%tS;tt:::X;X: . :@. . . . . 42 | . . S;;@@::8t:;:;:;:;:;t:;8::t8S:t .:@ . . 43 | . ;X8S@8;8.8: . . 8;;. ;X;t .;@. . . . . 44 | . XXS8% ;@.8. . . . 8;: @ 8:;@ . . 45 | :XXS :@.8. . 8;.. . 8:;@ . . . . 46 | . X;;@ . ;@.8: . . . . 8;: . .;@ . . . 47 | . ;@.:SXXXXXXXXXXXXX@:. . .:@ . . . . 48 | . . . ;X..::........::....... .;@ . . . 49 | . . XXS:::@X@@XXS.;8X@X@S . . ;8 . . . 50 | . . . .8;:.. . .;% . . . .;@ . . 51 | . . . 8;. ..t% . ..;@ . . . . 52 | . SS%S@X@8;: . . . X ; 8XSS . :@ . . . . . 53 | . . 8888888S ... 888888888 . :@ . . 54 | . . . . . . . . . . . 55 | . . . . . . . 56 | 57 | """) 58 | endgame= False 59 | choice = None 60 | while choice != "0": 61 | #os.system("cls") 62 | 63 | 64 | print("") 65 | print ( " So... " ,gob_name, " What is your action ?" ) 66 | print \ 67 | (""" 68 | 69 | 0 - Quit 70 | 1 - Status 71 | 2 - Eat 72 | 3 - Scavenge 73 | 4 - Explore 74 | 5 - Rest 75 | 6 - Craft 76 | """) 77 | 78 | 79 | 80 | choice = input("Choice: ") 81 | print() 82 | 83 | 84 | if choice == "0": 85 | print("Good-bye.") 86 | 87 | 88 | elif choice == "1": 89 | gob.status() 90 | 91 | 92 | elif choice == "2": 93 | gob.eat() 94 | 95 | 96 | elif choice == "3": 97 | gob.farm() 98 | 99 | elif choice == "4": 100 | gob.explore() 101 | 102 | elif choice == "5": 103 | gob.rest() 104 | 105 | elif choice == "6": 106 | gob.craft() 107 | 108 | else: 109 | 110 | print("\nSorry, but", choice, "isn't a valid choice.") 111 | 112 | if gob.hunger >20: 113 | print("You have gone too many days without food. You have died from hunger") 114 | input("press any button to continue") 115 | break 116 | 117 | if gob.health <=0: 118 | print("You have suffered too many wounds, you have bled to death") 119 | input("press any button to continue") 120 | break 121 | 122 | if endgame == False: 123 | if ("Fish Bone Spear") in gob.goal and ("Straw Bed")in gob.goal and("Small Hut") in gob.goal: 124 | print("You have built your home and prove you are a survivor, you win !!") 125 | con=input("Do you want to continue playing 1-yes, 2-no" ) 126 | if con == "1": 127 | endgame = True 128 | 129 | elif con == "2": 130 | print("Good bye") 131 | break 132 | 133 | else: 134 | pass 135 | 136 | else: 137 | pass 138 | 139 | else: 140 | pass 141 | 142 | 143 | main() 144 | 145 | 146 | ("\n\nPress the enter key to exit.") 147 | -------------------------------------------------------------------------------- /I ) A Grots Life ( Version B )/goblin.py: -------------------------------------------------------------------------------- 1 | from info import* # *import all elements from the module 2 | from mood import hung,wounded # Can import specific hence leaving out the function 'left_behind 3 | import random # if just import module no import instruction 4 | # then need to write module and method name 5 | # for example : random.choice or random.randint 6 | 7 | 8 | class Goblin(object): 9 | 10 | 11 | 12 | def __init__(self, name, hunger,health,provision,gold ): 13 | self.name = name 14 | self.hunger = hunger 15 | self.health= health 16 | self.provision= provision 17 | self.gold=gold 18 | self.inventory=[] 19 | self.goal=[] 20 | self.larder=[] 21 | 22 | 23 | def __pass_time(self): 24 | self.hunger += 1 25 | 26 | 27 | 28 | 29 | def status(self): 30 | print("Inventory") 31 | for x in range(len(self.inventory)): 32 | print (self.inventory[x],) 33 | print("You have",self.provision,"provisions") 34 | #print("You have",self.inventory,"in your bag" ) 35 | print("You have",self.gold, "gold") 36 | print("You are",hung(self.hunger)) 37 | print("You are",wounded(self.health)) 38 | self.__pass_time() 39 | 40 | 41 | 42 | def eat(self, eat = 5): 43 | 44 | if self.hunger<=0: 45 | print("You are not hungry") 46 | 47 | elif self.provision>0: 48 | mep=random.choice(self.larder) 49 | print("You eat some",mep) 50 | self.larder.remove(mep) 51 | print("It was a tasty meal") 52 | self.hunger -= eat 53 | self.provision-=2 54 | 55 | 56 | else: 57 | print("You do not have any food") 58 | 59 | 60 | self.__pass_time() 61 | 62 | 63 | def explore(self): 64 | loot=random.choice(lootlist) 65 | enemy=random.choice(enemylist) 66 | if ("Fish Bone Spear") in self.goal: 67 | print("Armed with your Fish Bone Spear...") 68 | damage=random.randint(1,10) 69 | self.health-=damage 70 | 71 | else: 72 | damage=random.randint(11,30) 73 | self.health-=damage 74 | 75 | print("You come across a",enemy) 76 | print("After an epic fight, you defeat the",enemy) 77 | print("you took",damage,"damage") 78 | 79 | if loot in self.inventory: 80 | print("You see nothing of interest") 81 | 82 | else: 83 | self.inventory.append(loot) 84 | print("You find a",loot) 85 | 86 | coin=random.randint(1,5) 87 | self.gold+=coin 88 | print("You gain",coin,"gold") 89 | 90 | self.__pass_time() 91 | 92 | 93 | 94 | def farm(self,stash=2): 95 | grub=random.choice(foodlist) 96 | print("You find some",grub) 97 | self.larder.append(grub) 98 | print("You gain",stash,"provisions") 99 | self.provision+= stash 100 | 101 | self.__pass_time() 102 | 103 | 104 | def rest(self): 105 | 106 | if self.health>=100: 107 | print("You do not need rest") 108 | 109 | else: 110 | 111 | 112 | if("Straw Bed") in self.goal: 113 | print("You rest better in your Straw Bed") 114 | sleep=random.randint(10,30) 115 | 116 | 117 | else: 118 | print("Sleeping on the floor is rough ") 119 | sleep=random.randint(5,20) 120 | 121 | 122 | bob=self.health 123 | self.health+=sleep 124 | 125 | if self.health>=100: 126 | self.health=100 127 | 128 | recover= self.health-bob 129 | print("You have recover",recover,"health") 130 | 131 | self.__pass_time() 132 | 133 | 134 | def craft(self): 135 | print( """ 136 | 0-exit 137 | 1-Fish Bone Spear 138 | 2-Straw Bed 139 | 3-Small Hut 140 | 141 | 142 | """) 143 | 144 | 145 | 146 | choice=input("Choice:") 147 | 148 | if choice == "0": 149 | print("come back when you have more resource") 150 | 151 | elif choice=="1": 152 | if ("Fish Bone Spear") in self.goal: 153 | print("You only need one") 154 | 155 | elif "Fish Bone" and "Wood Stick" in self.inventory: 156 | self.inventory.remove("Fish Bone") 157 | self.inventory.remove("Wood Stick") 158 | self.goal.append("Fish Bone Spear") 159 | print("You have crafted the Fish Bone Spear") 160 | 161 | else: 162 | print("You do not have the crafting material") 163 | 164 | elif choice=="2": 165 | 166 | if ("Straw Bed") in self.goal: 167 | print("You only need one") 168 | 169 | elif ("Fist Full of Straws") and ("Dirty Potato Sack") in self.inventory: 170 | self.inventory.remove("Fist Full of Straws") 171 | self.inventory.remove("Dirty Potato Sack") 172 | self.goal.append("Straw Bed") 173 | print("You have crafted Straw Bed") 174 | 175 | else: 176 | print("You do not have the crafting material") 177 | 178 | elif choice=="3": 179 | 180 | if ("Small Hut") in self.goal: 181 | print("You only need one") 182 | 183 | elif ("Giant Boot") and ("Rusty Umbrella") in self.inventory: 184 | self.inventory.remove("Giant Boot") 185 | self.inventory.remove("Rusty Umbrella") 186 | self.goal.append("Small Hut") 187 | print("You have crafted Small Hut") 188 | 189 | else: 190 | print("You do not have the crafting material") 191 | 192 | 193 | 194 | else: 195 | print("invalid") 196 | 197 | 198 | -------------------------------------------------------------------------------- /I ) A Grots Life ( Version B )/info (alternative) .py: -------------------------------------------------------------------------------- 1 | # This is not used in the game but provide an alternative approach 2 | # Alternatively you can write it as a class 3 | # but will need to call the object for example : 4 | # for example info_crit=List()in goblin.py 5 | # and to call list you need to write info_crit.foodlist 6 | 7 | 8 | class List: 9 | def __init__(self): 10 | self.foodlist=("Happy Mushrooms","Bony Bones","Rotten Apples","Mystery Meat") 11 | self.enemylist=("Tiny Tiny Dragon","Beta Male Orc","Hobbit Berserker","Tiny Tiny Dragon","Sucidal Jester","Cannibal Gnome") 12 | self.lootlist=("Fish Bone","Dirty Potato Sack","Fist Full of Straws","Wood Stick","Giant Boot","Rusty Umbrella") 13 | 14 | 15 | -------------------------------------------------------------------------------- /I ) A Grots Life ( Version B )/info.py: -------------------------------------------------------------------------------- 1 | 2 | foodlist=("Happy Mushrooms","Bony Bones","Rotten Apples","Mystery Meat") 3 | enemylist=("Tiny Tiny Dragon","Beta Male Orc","Hobbit Berserker","Tiny Tiny Dragon","Sucidal Jester","Cannibal Gnome") 4 | lootlist=("Fish Bone","Dirty Potato Sack","Fist Full of Straws","Wood Stick","Giant Boot","Rusty Umbrella") 5 | 6 | 7 | -------------------------------------------------------------------------------- /I ) A Grots Life ( Version B )/mood.py: -------------------------------------------------------------------------------- 1 | 2 | def hung(a): 3 | 4 | if a<5: 5 | m=("not hungry") 6 | elif 5 <=a <=10: 7 | m=(" a bit hungry") 8 | elif 11 <=a<=15: 9 | m=("hungry") 10 | else: 11 | m= (" staving !!!") 12 | 13 | return str(m) 14 | 15 | 16 | def wounded(b): 17 | 18 | if b==100: 19 | d=("fighting fit !!") 20 | elif 70 <=b<=99: 21 | d=("in good health") 22 | elif 40<=b<=69: 23 | d=(" bleeding bad") 24 | else: 25 | d=("very wounded") 26 | 27 | return str(d) 28 | 29 | 30 | def left_behind(): 31 | 32 | print("functions that not been imported ") 33 | -------------------------------------------------------------------------------- /I) A Grots Life( Version A ) .py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | lootlist=["Fist Full of Straws","Fish Bone","Old Stick","Dirty Potato Sack","Crumbling Stones","Rusty Umbrella","Rope"] 4 | enemylist=("Rat","Hobbit","Tiny Dragon","Drunk Human","Killer Bee") 5 | inventory=[] 6 | food=("Mushrooms","Meaty Bones","Rotten Apples","Spoiled Meat") 7 | larder=[] 8 | goal=[] 9 | 10 | # Class defines an object 11 | 12 | #self represents the instance of the class. 13 | #When objects are instantiated, the object itself is passed into the self parameter. 14 | #Because of this, the object’s data is bound to the object 15 | 16 | # __init__ ( known as a constructor or initialization method) 17 | # This automatically invoked when new object is created. 18 | # All class will have a method __init__ which provide instructions on what arguments is needed 19 | # eg: gob = Goblin(gob_name,0,100,0,20) which is the goblin's name,hunger,health,provision,gold 20 | # can invoke functions/methods but in this case just intialize attribute values 21 | 22 | # In python 3 it makes little difference if it is class Goblin: or Goblin (object) or Globin(): 23 | # since in python 3 it inherits it behind the scence anyway so 'Goblin:' would be fine 24 | #Left it in the code just to make you aware if you ever see (object), took me awhile to research. 25 | 26 | class Goblin(object): 27 | def __init__(self, name, hunger,health,provision,gold ): 28 | self.name = name 29 | self.hunger = hunger 30 | self.health= health 31 | self.provision= provision 32 | self.gold=gold 33 | 34 | def __pass_time(self): 35 | self.hunger += 1 36 | 37 | @property 38 | def hung(self): 39 | 40 | hung=self.hunger 41 | 42 | if hung<5: 43 | m=("not hungry") 44 | elif 5 <=hung <=10: 45 | m=(" a bit hungry") 46 | elif 11 <=hung<=15: 47 | m=("hungry") 48 | else: 49 | m= (" staving !!!") 50 | 51 | return m 52 | 53 | @property 54 | def wounded(self): 55 | 56 | cod=self.health 57 | 58 | if cod==100: 59 | d=("fighting fit !!") 60 | elif 70 <=cod <=99: 61 | d=("in good health") 62 | elif 40<=cod<=69: 63 | d=(" bleeding bad") 64 | else: 65 | d=("very wounded") 66 | 67 | return d 68 | 69 | def status(self): 70 | print("You have",self.provision,"provisions") 71 | print("You have",inventory,"in your bag" ) 72 | print("You have",self.gold, "gold") 73 | print("You are ",self.hung) 74 | print("You are ",self.wounded) 75 | self.__pass_time() 76 | 77 | def eat(self, eat = 5): 78 | if self.hunger<=0: 79 | print("You are not hungry") 80 | 81 | elif self.provision>0: 82 | mep=random.choice(larder) 83 | print("You eat some",mep) 84 | larder.remove(mep) 85 | print("It was a tasty meal") 86 | self.hunger -= eat 87 | self.provision-=2 88 | 89 | else: 90 | print("You do not have any food") 91 | 92 | self.__pass_time() 93 | 94 | def hunt(self): 95 | loot=random.choice(lootlist) 96 | enemy=random.choice(enemylist) 97 | 98 | if ("Fish Bone Spear") in goal: 99 | print("Armed with your Fish Bone Spear...") 100 | damage=random.randint(1,10) 101 | self.health-=damage 102 | 103 | else: 104 | damage=random.randint(11,30) 105 | self.health-=damage 106 | 107 | print ("You came across a",enemy) 108 | print("After an epic fight you took ",damage,"damage") 109 | 110 | if loot in inventory: 111 | print("You see nothing of interest") 112 | 113 | else: 114 | inventory.append(loot) 115 | print("But you find",loot) 116 | 117 | coin=random.randint(1,5) 118 | self.gold+=coin 119 | print("You have gain",coin,"gold") 120 | self.__pass_time() 121 | 122 | def farm(self,stash=2): 123 | grub=random.choice(food) 124 | print("You have found some",grub) 125 | larder.append(grub) 126 | print("You have gained",stash,"provisions") 127 | self.provision+= stash 128 | self.__pass_time() 129 | 130 | def rest(self): 131 | if self.health>=100: 132 | print("You do not need rest") 133 | 134 | else: 135 | 136 | if("Straw Bed") in goal: 137 | print("You rest better in your Straw Bed") 138 | sleep=random.randint(10,30) 139 | 140 | else: 141 | print("Sleeping on the floor is rough ") 142 | sleep=random.randint(5,20) 143 | 144 | bob=self.health 145 | self.health+=sleep 146 | 147 | if self.health>=100: 148 | self.health=100 149 | 150 | recover= self.health-bob 151 | print("You have recovered",recover,"health") 152 | 153 | self.__pass_time() 154 | 155 | def craft(self): 156 | print( """ 157 | 0-exit 158 | 1-Fish Bone Spear 159 | 2-Straw Bed 160 | 3-Small Hut 161 | """) 162 | 163 | choice=input("Choice:") 164 | 165 | if choice == "0": 166 | print("come back when you have more resource") 167 | 168 | elif choice=="1": 169 | 170 | if ("Fish Bone Spear") in goal: 171 | print("You only need one") 172 | 173 | elif "Fish Bone" and "Old Stick" in inventory: 174 | inventory.remove("Fish Bone") 175 | inventory.remove("Old Stick") 176 | goal.append("Fish Bone Spear") 177 | print("You have crafted the Fish Bone Spear") 178 | 179 | else: 180 | print("You do not have the crafting material") 181 | 182 | elif choice=="2": 183 | 184 | if ("Straw Bed") in goal: 185 | print("You only need one") 186 | 187 | elif "Fist Full of Straws" and "Dirty Potato Sack" in inventory: 188 | inventory.remove("Fist Full of Straws") 189 | inventory.remove("Dirty Potato Sack") 190 | goal.append("Straw Bed") 191 | print("You have crafted Straw Bed") 192 | 193 | else: 194 | print("You do not have the crafting material") 195 | 196 | elif choice=="3": 197 | 198 | if ("Small Hut") in goal: 199 | print("You only need one") 200 | 201 | elif "Crumbling Stones" and "Rusty Umbrella" and "Rope" in inventory: 202 | inventory.remove("Crumbling Stones") 203 | inventory.remove("Rusty Umbrella") 204 | inventory.remove("Rope") 205 | goal.append("Small Hut") 206 | print("You have crafted Small Hut") 207 | 208 | else: 209 | print("You do not have the crafting material") 210 | 211 | else: 212 | print("invalid") 213 | 214 | def main(): 215 | 216 | gob_name = input("What do you want to name your Goblin?: ") 217 | gob = Goblin(gob_name,0,100,0,20) 218 | 219 | endgame = False 220 | choice = None 221 | while choice != "0": 222 | print ( " So... " ,gob_name, " What is your action ?" ) 223 | print \ 224 | (""" 225 | 0 - Quit 226 | 1 - status 227 | 2 - Eat 228 | 3 - Scavenge 229 | 4 - Explore 230 | 5 - Rest 231 | 6 - Craft 232 | """) 233 | 234 | choice = input("Choice: ") 235 | print() 236 | 237 | if choice == "0": 238 | print("Good-bye.") 239 | 240 | elif choice == "1": 241 | gob.status() 242 | 243 | elif choice == "2": 244 | gob.eat() 245 | 246 | elif choice == "3": 247 | gob.farm() 248 | 249 | elif choice == "4": 250 | gob.hunt() 251 | 252 | elif choice == "5": 253 | gob.rest() 254 | 255 | elif choice == "6": 256 | gob.craft() 257 | 258 | else: 259 | print("\nSorry, but", choice, "isn't a valid choice.") 260 | 261 | if gob.hunger >20: 262 | print("died from hunger") 263 | input("press any button to continue") 264 | break 265 | 266 | if gob.health <=0: 267 | print("died from wounds") 268 | input("press any button to continue") 269 | break 270 | 271 | if endgame == False: 272 | if ("Fish Bone Spear") in goal and ("Straw Bed")in goal and("Small Hut") in goal: 273 | print("You have built your home and prove you are a survivor, you win !!") 274 | con=input("Do you want to continue playing 1-yes, 2-no" ) 275 | if con == "1": 276 | endgame = True 277 | 278 | elif con == "2": 279 | print("Good bye") 280 | break 281 | 282 | else: 283 | pass 284 | 285 | else: 286 | pass 287 | 288 | else: 289 | pass 290 | 291 | main() 292 | ("\n\nPress the enter key to exit.") 293 | #https://github.com/Ninedeadeyes/15-mini-python-games- 294 | -------------------------------------------------------------------------------- /J) The Slumber of the Doom King.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | 4 | # Stats 5 | health=100 6 | gold=0 7 | alive=True 8 | encounter1=False # This is used so that unique encounter only happen once. 9 | 10 | # function that provides input from player 11 | 12 | def input_direction(): 13 | direction = input("Which direction do you want to go? ") 14 | direction=direction.lower() 15 | while direction not in ["north", "south", "east", "west", "exit"]: 16 | direction = input("Invalid answer,which direction do you want to go? ") 17 | direction=direction.lower() 18 | 19 | return direction # When you execute input_direction it will return 'the direction' eg: north,south,east,west 20 | # Return statement is used in a function to return something to the caller program. 21 | 22 | def nothing(): 23 | pass 24 | 25 | def jester(): 26 | 27 | global encounter1 # If you do not use global the encounter within the function is consider a local variable 28 | # and you will have a "local variable referenced before assignment error" 29 | while encounter1==False: 30 | print ("You see a sad jester in the corner of the room") 31 | print ("He ask you a question") 32 | question1=input("Can you spare me some life for some gold ? Y or N " ) 33 | question=question1.lower() 34 | 35 | if question=="y" or question=="yes": 36 | global health 37 | global gold 38 | health=-5 39 | gold=+300 40 | print("The Jester smile and say 'thank you'.") 41 | print("You lose 5 life ") 42 | print("You gain 300 gold") 43 | encounter1=True 44 | 45 | else: 46 | print("The Jester scream at you 'go away!' ") 47 | encounter1=True 48 | else: 49 | pass 50 | 51 | print (" The Slumber of the Doom King ") 52 | print(" ") 53 | print("Goal: Steal as much gold as possible and escape the castle of the Doom King before he consume your soul !!") 54 | print("Direction: North/East/South/West/Quit") 55 | 56 | time.sleep(1.5) 57 | 58 | # Set up the Locations 59 | 60 | compass = { "north" : {1:-1,2:-1,3:-1,4:-1,5:1,6:2,7:3,8:4,9:5,10:6,11:7}, 61 | "east": {1:2,2:3,3:4,4:-1,5:6,6:7,7:8,8:-1,9:10,10:11,11:12}, 62 | "south": {1:5,2:6,3:7,4:8,5:9,6:10,7:11,8:12,9:-1,10:-1,11:-1}, 63 | "west": {1:-1,2:1,3:2,4:3,5:-1,6:5,7:6,8:7,9:-1,10:9,11:10} 64 | } 65 | 66 | descr = { 67 | 1: "Location: Master bedroom. You feel something is watching you", 68 | 2: "Location: Nursery. There is a sense of forelorn here", 69 | 3: "Location: Treasury. It has been ransacked a long time ago", 70 | 4: "Location: Library. It is filled with books of black magic ", 71 | 5: "Location: Dining room. Someone has been here recently", 72 | 6: "Location: Torture chamber. You feel sick with dread...", 73 | 7: "Location: Garden. All flowers has withered and died ", 74 | 8: "Location: Burial Chamber. Something should be forgotten", 75 | 9: "Location: Armoury. Filled with a assortment of demonic weapons", 76 | 10: "Location: Kitchen. Old pots and pans clutters the room ", 77 | 11: "Location: Servant Quarter. A skeleton lies on the floor, a sad sight", 78 | 12: ""} 79 | 80 | # Unique events ( You can add different types of quests/storylines/characters for each location 81 | 82 | events = { 83 | 1: nothing, 84 | 2: jester, 85 | 3: nothing, 86 | 4: nothing, 87 | 5: nothing, 88 | 6: nothing, 89 | 7: nothing, 90 | 8: nothing, 91 | 9: nothing, 92 | 10: nothing, 93 | 11: nothing, 94 | 12: nothing,} 95 | 96 | currentRoom = 1 97 | 98 | # Game loop 99 | while alive==True: 100 | 101 | # Describe the current room 102 | print (descr[currentRoom]) 103 | events[currentRoom]() 104 | 105 | loot=random.randrange(1,20) 106 | loot1=str(loot) 107 | print ("you find",loot1,"gold") 108 | gold+=loot 109 | print ("Total gold:",gold) 110 | print("Life:",health) 111 | 112 | # See if you awake the Doom King or not 113 | sleep=random.randint(1,9) 114 | 115 | if sleep ==5 and currentRoom !=12: 116 | damage=random.randrange(30,60) 117 | health-=damage 118 | print("The Doom King is awake, he attacks you !!") 119 | print("Life:", health) 120 | if health <=0: 121 | print("The Doom King consume your soul and break your body.( THE END )") 122 | input("Press enter to escape") 123 | break 124 | else: 125 | print("Thankfully you escape and the King falls back into slumber") 126 | 127 | elif sleep==1 or sleep==2: 128 | print("You hear the Doom King groan but then silence") 129 | 130 | elif sleep==3 or sleep==4: 131 | print("The Doom King is left undisturbed") 132 | 133 | elif sleep==6 or sleep==7: 134 | print("The Doom King remains asleep") 135 | 136 | else: 137 | print( "The Doom King slumber..") 138 | 139 | newDir = input_direction() # calling the function of user input, works because the 'return' function was used 140 | 141 | if newDir == "quit": # If you wish to exit 142 | print ("Good bye") 143 | break 144 | else: 145 | 146 | # Otherwise look up whether there is a path that way 147 | if compass[newDir][currentRoom] != -1: # ( if the nested value is a -1 means there is no path ) 148 | currentRoom = compass[newDir][currentRoom] # eg: compass[east][1] which is dic[key][nested key] will return value 2 which will be the new room/key 149 | print(newDir) # This is just to demonstrate how 'return' works, can delete if you want 150 | 151 | else: 152 | print ("There is no path in that direction") 153 | 154 | # If you find the exit 155 | if currentRoom ==12: 156 | print("Location: Exit Gate. You have found the exit, well done !!") 157 | print("Total gold:",gold," can you do better next time?") 158 | input("Press enter to escape") 159 | break 160 | 161 | #so the world is set up like 162 | 163 | # 1 2 3 4 164 | # 5 6 7 8 165 | # 9 10 11 12 166 | 167 | #You begin at 1 since currentRoom = 1 If you go east you will go to 2 because 168 | #compass[newDir][currentRoom] equals to compass[east][1] which will 169 | #extract the key of 2 because ('east": {1:2,')and then the new currentRoom becomes 2 170 | 171 | # if compass[newDir][currentRoom] != -1: ( if the nested value is a -1 means there is no path ) 172 | # currentRoom = compass[newDir][currentRoom] 173 | 174 | 175 | # If you then go south then it will be compass[south][2] which will obtain 176 | # the key 6 because ("south": {1:5,2:6,) and then the new currentRoom becomes 6 177 | 178 | # You have then travelled from A to C on the map 179 | 180 | # A B x x 181 | # x C x x 182 | # x x x x 183 | 184 | #https://github.com/Ninedeadeyes/15-mini-python-games- 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /K) Space Rescue .py: -------------------------------------------------------------------------------- 1 | import turtle 2 | import random 3 | import time 4 | 5 | # set up screen 6 | turtle.ht() 7 | turtle.setup(950,950) 8 | turtle.title("Space Rescue") 9 | turtle.bgcolor("black") 10 | turtle.setundobuffer(0) #This saves memory 11 | turtle.tracer(0) #This speeds up drawing 12 | 13 | class Game(): 14 | def __init__(self): # All class will have a method __init__ which provide instructions on what arguments is needed, example below at * 15 | self.pen = turtle.Turtle() # Has also invoked an turtle method (an additional attribute) to draw borders. 16 | 17 | def draw_border(self): #Function that draw border 18 | self.pen.speed(0) 19 | self.pen.color("white") 20 | self.pen.pensize(3) 21 | self.pen.penup() 22 | self.pen.goto(-400, 400) 23 | self.pen.pendown() 24 | for side in range(4): 25 | self.pen.fd(800) 26 | self.pen.rt(90) 27 | self.pen.penup() 28 | self.pen.ht() 29 | 30 | class Pen(turtle.Turtle): # Example of class inheritance, inheriting from the parent 'turtle.Turtle' 31 | def __init__(self): # The 'child' class (PEN) inherit the properties and methods from the Parent class (turtle.Turtle) 32 | turtle.Turtle.__init__(self) #This line of code is needed to keep the inheritance of the parent's __init__() function otherwise 33 | # it will be overrided by the child's __init() function 34 | def show_rules(self): 35 | self.ht() 36 | self.up() 37 | msg = ("Controls: ArrowKeys, Rescue the red ships and avoid the rocks ") 38 | self.goto(-300, -450) 39 | self.color("white") 40 | self.write(msg, font=("Arial", 16, "normal")) 41 | self.pendown() 42 | self.penup() 43 | 44 | def you_lose(self): 45 | self.ht() 46 | self.up() 47 | self.goto(-170,450) 48 | self.color("white") 49 | msg = (""" 50 | You lose, final points:%s""") %(player1.points) 51 | self.write(msg, font=("Arial", 16, "normal")) 52 | 53 | def show_points1(self): 54 | self.ht() 55 | self.up() 56 | self.goto(310,450) 57 | self.color("white") 58 | msg = " Points:%s" %(player1.points) 59 | self.write(msg, font=("Arial", 16, "normal")) 60 | 61 | def update_points1(self): 62 | self.undo() 63 | self.ht() 64 | self.up() 65 | self.goto(310,450) 66 | self.color("white") 67 | msg = "Points:%s" %(player1.points) 68 | self.write(msg, font=("Arial", 16, "normal")) 69 | 70 | class Sprite(turtle.Turtle): 71 | def __init__(self, shape, color, startx, starty): 72 | super().__init__() # By using the super() function instead of turtle.Turtle.__init__() , you do not have to use the name of the parent element, 73 | self.speed(0) # it will automatically inherit the methods and properties from its parent. 74 | self.penup() 75 | self.color(color) 76 | self.shape(shape) 77 | self.fd(0) 78 | self.goto(startx, starty) 79 | self.speed = 1 80 | 81 | def move(self): 82 | self.fd(self.speed) 83 | #Boundary detection 84 | if self.xcor() > 390: 85 | self.setx(390) 86 | self.rt(135) 87 | 88 | if self.xcor() < -390: 89 | self.setx(-390) 90 | self.rt (135) 91 | 92 | if self.ycor() > 390: 93 | self.sety(390) 94 | self.rt (135) 95 | 96 | if self.ycor() < -390: 97 | self.sety(-390) 98 | self.rt (135) 99 | 100 | def is_collision(self, other): 101 | if (self.xcor() >= (other.xcor() - 20)) and \ 102 | (self.xcor() <= (other.xcor() + 20)) and \ 103 | (self.ycor() >= (other.ycor() - 20)) and \ 104 | (self.ycor() <= (other.ycor() + 20)): 105 | return True 106 | else: 107 | return False 108 | 109 | def destroy(self): 110 | self.goto(9000,9000) 111 | self.hideturtle() 112 | 113 | class Player(Sprite): 114 | def __init__(self, shape, color, startx, starty): 115 | super().__init__(shape, color, startx, starty) # Because of super() we don't need 116 | self.speed =1 # write out those attributes again 117 | self.points=0 # eg : self.color within player class. 118 | # Since it will be handles by parent class 119 | def turn_left(self): # Any difference will need to be alter eg: self.speed 120 | self.lt(45) 121 | 122 | def turn_right(self): 123 | self.rt(45) 124 | 125 | def accelerate(self): 126 | if self.speed==2: 127 | pass 128 | else: 129 | self.speed += 1 130 | 131 | def decelerate(self): 132 | if self.speed == -1: 133 | pass 134 | else: 135 | self.speed -= 1 136 | 137 | class Ship(Sprite): 138 | def __init__(self, shape, color, startx, starty): 139 | super().__init__(shape, color, startx, starty) 140 | self.speed = 0 141 | self.setheading(random.randint(0,360)) 142 | 143 | class Enemy(Sprite): 144 | def __init__(self, spriteshape, color, startx, starty): 145 | super().__init__(spriteshape, color, startx, starty) 146 | self.speed = .5 147 | self.setheading(random.randint(0,360)) 148 | 149 | game = Game() #call game function 150 | game.draw_border() # draw border 151 | player1 = Player(("triangle"),"blue",-380,-380) 152 | 153 | turtle.onkey(player1.turn_left, "Left") 154 | turtle.onkey(player1.turn_right, "Right") 155 | turtle.onkey(player1.accelerate, "Up") 156 | turtle.onkey(player1.decelerate, "Down") 157 | 158 | turtle.listen() 159 | points1=Pen() 160 | points1.show_points1() 161 | rules=Pen() 162 | rules.show_rules() 163 | ship=[] 164 | 165 | for shi in range(3): 166 | ship.append(Ship("circle","red",random.randint(-370,370),random.randint(-370,370))) 167 | 168 | maxenemies= random.randint(10,16) 169 | 170 | enemies =[] 171 | for i in range(maxenemies): 172 | enemies.append(Enemy("square", "grey",0, 0)) 173 | enemies[i].setposition(random.randint(-300,300),random.randint(-300,300)) 174 | 175 | #Game loop 176 | while True: 177 | player1.move() 178 | 179 | for enemy in enemies: 180 | enemy.move() 181 | 182 | if player1.is_collision(enemy): 183 | player1.destroy() 184 | points1.you_lose() 185 | for enemy in enemies: 186 | enemy.speed=0 187 | time.sleep(5) 188 | break 189 | 190 | for shi in range (3): 191 | if player1.is_collision(ship[shi]): 192 | x = random.randint(-390, 390) 193 | y = random.randint(-390, 390) 194 | ship[shi].goto(x, y) 195 | player1.points+=100 196 | points1.update_points1() 197 | 198 | turtle.update() 199 | 200 | # *__init__ Example 201 | 202 | #class Computer(): 203 | # def __init__(self, computer, ram, ssd): 204 | # self.computer = computer 205 | # self.ram = ram 206 | # self.ssd = ssd 207 | # print ("Computer info is below ") 208 | # 209 | # 210 | #lenovo = Computer('lenovo', 2, 512) 211 | #print('This computer is:', lenovo.computer) 212 | #print('This computer has ram of', lenovo.ram) 213 | #print('This computer has ssd of', lenovo.ssd) 214 | # 215 | # 216 | #Computer info is below 217 | #This computer is: lenovo 218 | #This computer has ram of 2 219 | #This computer has ssd of 512 220 | 221 | 222 | #https://github.com/Ninedeadeyes/15-mini-python-games- 223 | 224 | 225 | 226 | 227 | -------------------------------------------------------------------------------- /L) One click rpg.py: -------------------------------------------------------------------------------- 1 | from tkinter import* 2 | from tkinter import ttk #ttk are actually separate files in tkinter, this updates the original with improved widgets. 3 | import random 4 | 5 | class Application(Frame): #Frame is a previously defined class/widget designed to be a container for other widgets. Example of Class inheritance 6 | def __init__ (self,master): # 'master' is just the augment, in this example it will be root eg: Application(root) which is basically Tk() 7 | Frame.__init__(self,master) # This line of code is needed to keep the inheritance of the parent's __init__() function otherwise it will be overrided by the child's __init() function 8 | self.grid() # Inheritance allows us to define a class that inherits all the methods and properties from another class. 9 | self.create_widgets() 10 | self.gold=0 11 | self.exp=0 12 | self.lexp=0 13 | self.level=0 14 | self.area=["Forest of the Chaos Harlequins ","Forgotten Graveyard of Endal","Castle of the Blackest Knight","Haunted Farm of Yondor","Deathtrap Dungeon of Borgon"," Mysterious Swampland of Kuluth", 15 | "Swamp of the Slimy Hobbits", "Darkest Dungeons", "Ruins of the Fallen Gods", "Forlorn Islands of Lost Souls","Hidden Hideout of Ninedeadeyes", "Wildlands of Lady L Moore"," Woods of Ypres","Heart of Darkness", 16 | "Doomville", "The Red Jester's Torture Chamber","The Goblins Fortress of Snikrik,"," Temple of Apshai"," Dungeons of Doom", "Mountains of the Wild Berserker","Stronghold of Daggerfall","Walking Hills of Cthulhu" ] 17 | 18 | self.monster=["orcs","goblins","dragons","demons","kobolds","blobs","hobbits","zombies","gnomes","vampires","beholders","trolls","hill giants","ettins","mimics", 19 | "succubuses","bone devils","clay golems","drows","gnolls","swamp hags"," night goblins","half-ogres","hobgoblins","bog imps","owlbears","ponies","winter wolves","harlequin","abomination"] 20 | 21 | self.description=["stupid","horny","heart broken","deranged","morbid","tiny","suicidal","sexy","skinny","racist","peaceful","silly","drunk","sadistic","young", "shy","talkative", 22 | "lovestruck","sarcastic","homophobic","forelorn","happy","friendly","psychopathic","optimistic","mysterious","beautiful","malnourish","zealous","hot-headed"] 23 | 24 | self.power_ranking=("The Village Punchbag (It's a job, i guess )") 25 | 26 | def create_widgets(self): 27 | self.bttn= Button(self) 28 | self.bttn["text"]="Explore" 29 | self.bttn["command"]= self.adventure 30 | self.bttn.grid(row=0,column=0,columnspan=1,sticky=W) 31 | 32 | self.stat_lbl=Label(self,text="Gold:0 EXP:0 LEVEL:0") 33 | self.stat_lbl.grid(row=0,column=1,columnspan=2,sticky=E) 34 | 35 | self.story_txt=Text(self,width=45, height=5,wrap=WORD) 36 | self.story_txt.grid(row=3, column=0, columnspan=3, sticky = W) 37 | 38 | self.stat_lb2=Label(self,text="Power ranking: Ready to begin your quest from zero to hero ? ") 39 | self.stat_lb2.grid(row=5,column=0,columnspan=2,sticky=W) 40 | 41 | def adventure(self): 42 | adventure=random.choice(self.area) 43 | adventure1=str(adventure) 44 | encounter=random.choice(self.monster) 45 | descript=random.choice(self.description) 46 | descript1=str(descript) 47 | encounter1=str(encounter) 48 | number=random.randrange(2,5) 49 | number1=str(number) 50 | reward=random.randrange(1,10) 51 | reward1=str(reward) 52 | exp=random.randrange(1,20) 53 | exp1=str(exp) 54 | self.gold+=reward 55 | self.exp+=exp 56 | self.lexp+=exp 57 | 58 | if self.lexp >123+(self.level*10): 59 | self.level+=1 60 | self.lexp=0 61 | 62 | if self.level >2 and self.level <4: 63 | self.power_ranking="The Cannon Fodder (Ready to die ? ) " 64 | 65 | if self.level >4 and self.level <6: 66 | self.power_ranking="The Weakling Avenger (At least you tried )" 67 | 68 | if self.level >6 and self.level <8: 69 | self.power_ranking="The Nice Guy (This is no compliment )" 70 | 71 | if self.level >8 and self.level <10: 72 | self.power_ranking="The Beta Warrior (Well.. You won't die first, I guess )" 73 | 74 | if self.level >10 and self.level <12: 75 | self.power_ranking="The Mighty Beta Warrior (Some nerds respect you )" 76 | 77 | if self.level >12 and self.level <14: 78 | self.power_ranking="The Average Chump (Nothing to see here ) " 79 | 80 | if self.level >14 and self.level <16: 81 | self.power_ranking="The Man with a Stick (Fear my wood ) " 82 | 83 | if self.level >16 and self.level <18: 84 | self.power_ranking="The Man with a Big Stick (MORE WOOD )" 85 | 86 | if self.level >18 and self.level <20: 87 | self.power_ranking="The Town's Guard (Obey my authority ) " 88 | 89 | if self.level >20 and self.level <24: 90 | self.power_ranking="The Try-Hard Hero (You win some, you lose more )" 91 | 92 | if self.level >24 and self.level <26: 93 | self.power_ranking="The Goblin Slayer (Your reputation grows )" 94 | 95 | if self.level >26 and self.level <28: 96 | self.power_ranking="The Orc Breaker (Orcs cower in your presence )" 97 | 98 | if self.level >28 and self.level <30: 99 | self.power_ranking=" The Average Hero (Good but not great,keep fighting )" 100 | 101 | if self.level >30 and self.level <32: 102 | self.power_ranking=" The Demon Demolisher (Guts will be proud of you )" 103 | 104 | if self.level >32 and self.level <34: 105 | self.power_ranking=" The Master Killer (A black belt in DEATH )" 106 | 107 | if self.level >34 and self.level <40: 108 | self.power_ranking=" The Champion of Man (The best a man can be )" 109 | 110 | if self.level >40 and self.level <70: 111 | self.power_ranking=" Legendary Hero (Well done. You can retire now )" 112 | 113 | if self.level >70 and self.level <90: 114 | self.power_ranking=" Old Warrior (Why are you still playing ? )" 115 | 116 | if self.level >90 and self.level <90: 117 | self.power_ranking="It's Over 9000 !! ( Seriously, quit it )" 118 | 119 | if self.level >100 : 120 | self.power_ranking="God (We bow down to your greatness )" 121 | 122 | story ="You explore the " 123 | story += adventure1 124 | story +="." 125 | story += " You encounter " 126 | story +=number1 127 | story +=" " 128 | story+=descript1 129 | story +=" " 130 | story += encounter1 131 | story +="." 132 | story += " You slay the " 133 | story += encounter1 134 | story +="." 135 | story += " You gain " 136 | story += reward1 137 | story += " gold and " 138 | story += exp1 139 | story += " exp" 140 | story +="." 141 | 142 | rank= "Power ranking: " 143 | rank+= self.power_ranking 144 | 145 | stat="Gold:" 146 | stat+=str(self.gold) 147 | stat+=" " 148 | stat+="EXP" 149 | stat+=str(self.exp) 150 | stat+=" " 151 | stat+="LEVEL:" 152 | stat+=str(self.level) 153 | 154 | self.story_txt.delete(0.0,END) 155 | self.story_txt.insert(0.0,story) 156 | self.stat_lbl["text"]=stat 157 | self.stat_lb2["text"]=rank 158 | 159 | root = Tk() 160 | root.title(" One Click RPG ") 161 | root.geometry("380x150") 162 | app=Application(root) 163 | 164 | root.mainloop() # This is a method on the main window which we execute when we want to run our application. 165 | #This method will loop forever, waiting for events from the user, until the user exits the program 166 | 167 | #https://github.com/Ninedeadeyes/15-mini-python-games- 168 | 169 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 15-mini-standard-library python-games 2 | 3 | A collection of 12 mini games created with standard library that scales in complexity. Good for beginners looking for examples of games that implement a specific python code. 4 | The games cover the 'basic topics' of python and some intermediate topics like OOP so you can treat this as a beginners python course too. 5 | 6 | I have done some 'notes' to explain some of the code but if you do not understand something best thing to do is to google it. I have also added a few bonus games that doesn't fit within the collection for additional examples and reference. 7 | 8 | A) Dice with Death = Simple dice game with death, you win you live. You lose, your soul is his. This is a very basic game using USER-DEFINED, IN BUILT functions, VARIABLES and IF STATEMENTS 9 | 10 | B) Hacker= Goal of the game is to hack into Robert's account. The more attempts, the more clues it provide. Implement the use of INPUT function, VARIABLES, WHILE loop, BREAK statement and IF ELSE STATEMENTS. 11 | 12 | C) The lord, the hunter and the fox= alternative to Rock,Paper,Scissors. Using LIST data type and IF,ELIF and ELSE STATEMENTS. 13 | 14 | D) Mini gamble = A simple 'Shell' game where you make bets on which pot the stone is under. Implement INT function converting 'string' to integer. 15 | 16 | E) Battle Master= Build the optimal army to defeat the dreaded orcs. Implement the use of TRY and EXCEPT statements 17 | 18 | F) Blood Pit= Fight a selection of monsters in the blood pit to gain reputation and glory. Demonstrate how to use data structure (LIST) to interact with variables within a function. Demonstrate a user defined function with multiple arguments. 19 | 20 | G) Dungeon Hack = an adventure simulation game. You need to pick a band of adventurers and complete a dungeon run. Depending on the combination of adventurers it will dictate the outcome of the dungeon run. Using FOR LOOP. 21 | 22 | H) The Haunted House= A mini adventure game. Your main goal is to escape the house with the loot. Using NESTED DICTIONARY data type. 23 | 24 | I) A Grot's Life = A Survival crafting Game written in standard library where you play as a grot doing what a grot do. Version implements OOP Object oriented programming whilst Version B also implements 'IMPORT' transfering functions/class/lists from USER DEFINED modules (MODULARITY). Using CLASS is the best method to interact with global variables. 25 | A good example of Modularity on a bigger project will be my open world rpg GrimeLore-Land-of-the-Heretic-Hand on my github page. 26 | 27 | J) The Slumber of the Doom King= Break into the Doom King's castle and steal as much gold as possible and find an escape before the king consumes your soul. Using DICTIONARY,NESTED DICTIONARY and RETURN function. 28 | 29 | K) One Click RPG= An Idle RPG. Using TUPLES data type, Using TKINTER GUI library ( part of the standard library ) 30 | 31 | L) Space Rescue = Rescue the red ships and avoid the rocks. Using TURTLE GRAPHICS library ( part of the standard library ) 32 | 33 | Bonus games 34 | 35 | The King's Curse = A simple text based adventure using Ascii graphics taken from https://www.asciiart.eu/ 36 | 37 | Who Dare Wins= A tactical dice game with a high score save function. Demonstrate how to OPEN/READ/WRITE TXT.FILES as well as an example of 'clear screen' function. 38 | 39 | The Road To Eden = Make hard decisions as you make your way to the city of Eden. Demonstrate how to open and read multiple lines/elements within a txt.file. 40 | 41 | If you want to 'expand' your learning. I would recommend the below github projects. I have listed from easiest to hardest. Enjoy 42 | 43 | 44 | https://github.com/Ninedeadeyes/Dungeon-of-the-Black-Dragon ( A 2d Ascii adventure/dungeon crawler game) 45 | 46 | https://github.com/Ninedeadeyes/Tank-Battle-At-Ghost-Forest ( A shootem up with 2 player options written with Turtle library ) 47 | 48 | https://github.com/Ninedeadeyes/A-Grots-Life-2 ( A survival/crafting game wrttien with Tkinter Library ) 49 | 50 | https://github.com/Ninedeadeyes/Quest-for-the-Golden-Turtle ( A hack and slash dungeon crawler written with Turtle library, There is a mod version here demonistrating player movement animation called Pac-Man vs The Goblins of Doom) 51 | 52 | https://github.com/Ninedeadeyes/7-Dungeons-Deep ( An action rpg written with Turtle Library ) 53 | 54 | https://github.com/Ninedeadeyes/GrimLore-Land-of-the-Heretic-Hand ( A 2d Ascii open world rpg) 55 | 56 | 57 | Youtube Video 58 | 59 | https://www.youtube.com/watch?v=ike4KGsFM2Y 60 | 61 | --------------------------------------------------------------------------------