Star Wars Top Trumps Style Game with Python
The Star Wars universe has always been a source of inspiration for fans across the galaxy, and now, it can also be the backdrop for a thrilling Python-based battle game. Step into the world of lightsabers, droids, and the Force, as you pit iconic Star Wars characters against each other in epic battles, where strategy, luck, and the Force play vital roles in determining the victor.
Key Features:
-
Star Wars Characters: The game includes a roster of beloved Star Wars characters. Whether it’s Jedi knights like Luke Skywalker or Sith lords like Darth Vader, each character brings unique abilities and statistics to the battle.
-
Randomized Outcomes: Thanks to Python’s random library, each battle is a unique experience. The outcome depends on a mix of character statistics, tactics, and a dash of luck.
-
Character Statistics: Characters have attributes such as strength, agility, intelligence, and the Force. These statistics influence their performance in battles.
Why I Created This Game
I made this game while working on my Python Crash Course guide: Learn Python in 20 minutes. The idea of the game was to make learning how Pythons lists work more interesting, as the typical Simon is 16 and has grade C was extremely boring and not a fun way to learn it all. So, I made a game consisting of Python lists with the very popular Star Wars as its theme.
How it Works
Each character’s statistics are stored in a list which include:
- Power.
- Speed.
- Weight.
- Height.
- Awareness.
#Combatants [power,speed,weight,height,awareness, "name"] luke=[100,100,10,6,100, " Luke Skywalker", " Luke Skywalker's"] solo=[80,80,11,6,60, " Han Solo", " Han Solo's"] yoda=[100,150,5,3,150, " Yoda", " Yoda's"] vader=[100,90,12,7,100, " Vader", " Vader's"] palpatine=[100,100,9,6,130, " Palpatine", " Palpatine's"] gamo=[150,30,100,5,30, " Gamorrean Warrior", " Gamorrean Warrior's"] rancor=[250,10,200,20,10, " The Rancor", " The Rancor's"] mace=[120,100,10,6,100, " Mace Windu", " Mace Windu's"] greedo=[80,60,9,6,40, " Greedo", " Greedo's"] boba=[90,90,15,6,80, " Boba Fett", " Boba Fett's"] jabba=[100,10,200,4,60, " Jabba the Hutt", " Jabba the Hutt's"]
You then choose the two characters you want to do battle by inputting their names into the two variables you see below:
firstCombatant=luke secondCombatant=vader
Then you run the Python script and prepare for battle.
Making it less Predictable
The original version only used the attributes from the lists to decide on the outcome, which made the game very predictable. I added Pythons random library to simulate a roll of the dice, this gave the game randomness and less predictability. Every battle now had a unique score and outcome.
I also added a handicap to make things fairer, penalty = weight x height
this stopped the Rancor from destroying everyone and Yoda losing every battle.
Images from the game
The Code:
The code could be better, the game could be more adventurous, but this was only created to show beginners learning Python how lists work. I think it does this in a more understandable and fun way.
import random import time dt1=2 dt2=1 diceRes=[] #Combatants [power,speed,weight,height,awareness, "name"] luke=[100,100,10,6,100, " Luke Skywalker", " Luke Skywalker's"] solo=[80,80,11,6,60, " Han Solo", " Han Solo's"] yoda=[100,150,5,3,150, " Yoda", " Yoda's"] vader=[100,90,12,7,100, " Vader", " Vader's"] palpatine=[100,100,9,6,130, " Palpatine", " Palpatine's"] gamo=[150,30,100,5,30, " Gamorrean Warrior", " Gamorrean Warrior's"] rancor=[250,10,200,20,10, " The Rancor", " The Rancor's"] mace=[120,100,10,6,100, " Mace Windu", " Mace Windu's"] greedo=[80,60,9,6,40, " Greedo", " Greedo's"] boba=[90,90,15,6,80, " Boba Fett", " Boba Fett's"] jabba=[100,10,200,4,60, " Jabba the Hutt", " Jabba the Hutt's"] ######################################## #You can change names to any of the above. firstCombatant=luke secondCombatant=vader #Do not change anything outside of this block. ######################################## print(firstCombatant) print(secondCombatant) firstCombatantScore=0 secondCombatantScore=0 def Roll(): global diceRes time.sleep(.5) diceRes = random.sample(range(1, 7), 1) time.sleep(.5) print("You have rolled a ",diceRes) print(""" _________________ ____ __________ . . / | / \ . | | . / ______ _____| . / \ | ___ | . . \ \ | | / /\ \ | |___> | . \ \ | | / /__\ \ . | _/ . . ________> | | | . / \ | |\ \_______ . | / | | / ______ \ | | \ | |___________/ |___| /____/ \____\ |___| \__________| . . ____ __ . _____ ____ . __________ . _________ \ \ / \ / / / \ | \ / | . \ \/ \/ / / \ | ___ | / ______| . \ / / /\ \ . | |___> | \ | . \ / / /__\ \ | _/. \ \ + \ /\ / / \ | |\ \______> | . \ / \ / / ______ \ | | \ / . . . \/ \/ /____/ \____\ |___| \____________/ LS . """) time.sleep(2) print() print() print("You have chosen"+str(firstCombatant[5])+ " To Battle" +str(secondCombatant[5])) print("*****************************************************************************") print() print() # Created a way to give players a disability # penalty = weight x height print(str(firstCombatant[6])+" Weight = " + str(firstCombatant[2])) print(str(secondCombatant[6])+" Weight = " + str(secondCombatant[2])) print() time.sleep(dt2) print(str(firstCombatant[6])+" Height = " + str(firstCombatant[3])) print(str(secondCombatant[6])+" Height = " + str(secondCombatant[3])) firstCombatantPen=firstCombatant[2]/firstCombatant[3] secondCombatantPen=secondCombatant[2]/secondCombatant[3] time.sleep(dt2) print() print(firstCombatant[5]+" has a handicap of "+str(firstCombatantPen)) print(secondCombatant[5]+" has a handicap of "+str(secondCombatantPen)) print() time.sleep(dt1) ################################## #Round 1########################## print("#"*20) print("Round 1") print(str(firstCombatant[6])+" Power = " + str(firstCombatant[0])) time.sleep(.5) print(str(secondCombatant[6])+" Power = " + str(secondCombatant[0])) time.sleep(dt2) print() print(firstCombatant[5]+" is rolling the dice") Roll() p1Pow=firstCombatant[0]*diceRes[0] print(firstCombatant[5], p1Pow) time.sleep(dt1) print() print() print(secondCombatant[5]+" is rolling the dice") Roll() p2Pow=secondCombatant[0]*diceRes[0] print(secondCombatant[5], p2Pow) time.sleep(dt1) print() print() ################################## #Round 2########################## print("#"*20) print("Round 2") print(str(firstCombatant[6])+" Speed = " + str(firstCombatant[1])) time.sleep(.5) print(str(secondCombatant[6])+" Speed = " + str(secondCombatant[1])) time.sleep(dt2) print() print() print(firstCombatant[5]+" is rolling the dice") Roll() p1Spd=firstCombatant[1]*diceRes[0] print(firstCombatant[5], p1Spd) time.sleep(dt1) print() print() print(secondCombatant[5]+" is rolling the dice") Roll() p2Spd=secondCombatant[1]*diceRes[0] print(secondCombatant[5], p2Spd) time.sleep(dt1) print() print() ################################## #Round 3########################## print("#"*20) print("Round 3") print(str(firstCombatant[6])+" Awareness = " + str(firstCombatant[4])) time.sleep(.5) print(str(secondCombatant[6])+" Awareness = " + str(secondCombatant[4])) time.sleep(dt2) print() print() print(firstCombatant[5]+" is rolling the dice") Roll() p1Awr=firstCombatant[4]*diceRes[0] print(firstCombatant[5], p1Awr) time.sleep(dt1) print() print() print(secondCombatant[5]+" is rolling the dice") Roll() p2Awr=secondCombatant[4]*diceRes[0] print(secondCombatant[5], p2Awr) time.sleep(dt1) print() print() ################################## firstCombatantScore=p1Pow+p1Spd+p1Awr-firstCombatantPen secondCombatantScore=p2Pow+p2Spd+p2Awr-secondCombatantPen print("********************************") if firstCombatantScore > secondCombatantScore: print(str(firstCombatant[5]) + " Defeats" + str(secondCombatant[5])) else: print(str(secondCombatant[5]) +" Defeats" + str(firstCombatant[5])) print("********************************") time.sleep(dt2) print(str(firstCombatant[6]) + " Total Score = " + str(round(firstCombatantScore))) print(str(secondCombatant[6]) + " Total Score = " + str(round(secondCombatantScore))) time.sleep(20)
Conclusion
If you’re ready to embark on your Star Wars adventure, grab your lightsaber, unleash the Force, and let the battles begin! The game is not only entertaining but also a great way to explore Python programming while having fun in the Star Wars galaxy.
May the code be with you as you enter the Star Wars universe in a unique and engaging way with this Python-based battle game!
That’s All Folks!
Find more of our Python guides here: Python Guides
Recommendation:
Big Book of Small Python Programs: 81 Easy Practice Programs: https://amzn.to/3rGZjCR