I create a python game that enable player to choose your own unit and assemble a team. The game included many vehicles and troopers in Star Wars. Enjoy the game!
import random
class Unit:
def __init__(self, input_name, input_armor, input_health, input_attack, input_history = ""):
self.name = input_name
self.armor = input_armor
self.health = input_health
self.attack = input_attack
self.history = input_history
def __repr__(self):
description = "{name}:{history} It has {armor} armor, {health} hitpoints and {attack} attack.".format(name = self.name, history = self.history, armor = self.armor, health = self.health, attack = self.attack)
return description
Player_unit_list = []
A_I = Unit("B1", "Light", 120, 20, "The predominantly used battle droids manufactured by Baktoid Combat Automata and Baktoid Armor Workshop.")
A_II = Unit("B2", "Medium", 200, 60, "An advanced droid with heavier armor and higher durability, but it is also slow and clumsy.")
A_III = Unit("BX", "Medium", 320, 80, "Advanced battle droids used by the Confederacy of Independent Systems.")
A_IV = Unit("OG-9 homing spider droid", "Heavy", 600, 140, "A model of large, four-legged battle droid manufactured by Baktoid Armor Workshop.")
A_V = Unit("AT-AT","Heavy",1200, 280, "A major part of the Galactic Empire's motor-pool. Carrying a vast amount of fire power and being heavily armored.")
B_I = Unit("Clone trooper", "Light", 160, 40, "Highly trained soldiers in the Grand Army of the Republic.")
B_II = Unit("Clone shock trooper", "Medium", 200, 40, "Security police for the administrative facilities on Coruscant.")
B_III = Unit("BARC troopers", "Medium", 220, 80, "Special troopers trained to ride BARC speeders across difficult terrain or dangerous battlegrounds.")
B_IV = Unit("Clone commandos", "Medium", 580, 200, "Clone troopers specially bred by the Kaminoans to be the elite force of the Grand Army; received specialized training and equipment.")
B_V = Unit("Super Tank", "Heavy", 1050, 300, "An experimental tank created by Baktoid Armor Workshop.")
C_I = Unit("STAP", "Light", 150, 40, "A repulsorcraft used by the Trade Federation and later the Confederacy of Independent Systems.")
C_II = Unit("DSD1 dwarf spider droid", "Heavy", 200, 80, "A model of battle droid_II manufactured by Baktoid Armor Workshop.")
C_III = Unit("AAT", "Heavy", 400, 150, "The Confederacy of Independent Systems' primary infantry vehicle used during the Clone Wars.")
C_IV = Unit("AT-TE", "Heavy", 700, 180, "A multi-purpose assault vehicle capable of tasks ranging from the transportation of clone trooper platoons around a battlefield to full-scale attacks upon enemy installations.")
C_V = Unit("HAVw A6 Juggernaut", "Heavy", 1300, 215, "A massive, ten-wheeled heavy assault vehicle manufactured by Kuat Drive Yards for use by the Galactic Republic's clone army." )
D_I = Unit("Rebel trooper", "Light",150,30,"The front-line soldiers of both the early rebel movement and, later, the Rebel Alliance against the Galactic Empire during the Galactic Civil War.")
D_II = Unit("LM-432 crab droid", "Medium", 240, 65, "A four-legged droid tank of various sizes manufactured by the Techno Union.")
D_III = Unit("Droideka", "Medium", 340, 90, "A type of heavy battle droid used by the Trade Federation and the Confederacy of Independent Systems.")
D_IV = Unit("RX-200 Falchion-class assault tank", "Heavy", 480, 240, "A model of tank used by the Grand Army of the Republic during the Clone Wars. Its ion cannon allowed it to drain targets of their energy, rendering them useless.")
D_V = Unit("AT-M6","Heavy", 1500, 320, "A mobile heavy artillery walker used by the First Order during their war with the Resistance.")
E_I = Unit("D-wing droid","Light",130,25,"Security droidsthat were developed as an experiment of the Techno Union.")
E_II = Unit("AT-RT","Medium", 230, 60, "One-man bipedal walker used for reconnaissance and patrolling.")
E_III = Unit("NR-N99 Persuader-class droid enforcer","Heavy",420, 120, "A droid tank manufactured by Techno Union and mainly utilized by Corporate Alliance, and it was this group that largely funded the unit's manufacture.")
E_IV = Unit("AT-AP", "Heavy",420, 280, "A small tripedal walker manufactured by Kuat Drive Yards and was developed from the All Terrain Personal Transport and the All Terrain Tactical Enforcer.")
E_V = Unit("SPHA-T", "Heavy", 700, 450, "A 12-legged gun platform manufactured by Rothana Heavy Engineering.")
F_I = Unit("Aqua droid","Medium", 165,35,"An amphibious model of battle droid manufactured by Haor Chall Engineering Corporation.")
F_II = Unit("Clone sharpshooters", "Light", 130, 90, "A type of specialized clone trooper of the Grand Army of the Republic that was deployed as a sniper or marksman specialist.")
F_III = Unit("IG-227 Hailfire-class droid tank","Medium", 240, 220, "A model of droid tank manufactured by Haor Chall Engineering Corporation that was used by the InterGalactic Banking Clan and Confederacy of Independent Systems during the Clone Wars as well as the Alliance to Restore the Republic during the Galactic Civil War.")
F_IV = Unit("Umbaran mobile heavy cannon", "Heavy", 680, 270, "A model of walker that was heavily armored, impervious to blasters and even missile launchers,[4] and had an articulated electromagnetic plasma cannon mounted on top of its dome-like body.")
F_V = Unit("Superlaser siege cannon", "Heavy", 550, 630," A heavy artillery weapon deployed by the First Order, capable of penetrating enemy defenses.")
Unit_pool = {"A_I":1, "B_I":1, "C_I":1, "D_I":1, "E_I":1, "F_I":1, "A_II":2, "B_II":2, "C_II":2, "A_III":3, "B_III":3, "C_III":3, "D_III":3, "E_III":3, "F_III":3, "A_IV":4, "B_IV":4, "C_IV":4, "D_IV":4, "E_IV":4, "F_IV":4, "A_V":5, "B_V":5, "C_V":5, "D_V":5, "E_V":5, "F_V":5}
level1_unit = [key for key in Unit_pool.keys() if Unit_pool[key] == 1]
level1_dict = {"B1":A_I, "Clone trooper":B_I, "STAP":C_I, "Rebel trooper":D_I,"D-wing Droid":E_I,"Aqua Droid":F_I}
level2_unit = [key for key in Unit_pool.keys() if Unit_pool[key] == 2]
level2_dict = {"B2":A_II, "Clone shock trooper":B_II, "DSD1 dwarf spider droid":C_II, "LM-432 crab droid":D_II, "AT-RT":E_II, "Clone sharpshooters":F_II}
level3_unit = [key for key in Unit_pool.keys() if Unit_pool[key] == 3]
level3_dict = {"BX":A_III, "BRAC troopers":B_III, "AAT":C_III, "Droideka":D_III, "NR-N99 Persuader-class droid enforcer":E_III, "IG-227 Hailfire-class droid tank":F_III}
level4_unit = [key for key in Unit_pool.keys() if Unit_pool[key] == 4]
level4_dict = {"OG-9 homing spider droid":A_IV, "Clone commandos":B_IV, "AT-TE":C_IV, "RX-200 Falchion-class assault tank":D_IV, "AT-AP":E_IV, "Umbaran mobile heavy cannon":F_IV}
level5_unit = [key for key in Unit_pool.keys() if Unit_pool[key] == 5]
level5_dict = {"AT-AT":A_V, "Super Tank":B_V, "HAVw A6 Juggernaut":C_V, "AT-M6":D_V, "SPHA-T":E_V, "Superlaser siege cannon":F_V}
Computer_unit_pool = [list(level1_dict.values())[random.randint(0,5)], list(level2_dict.values())[random.randint(0,5)], list(level3_dict.values())[random.randint(0,5)], list(level4_dict.values())[random.randint(0,5)], list(level5_dict.values())[random.randint(0,5)]]
winner_list1 = []
winner_list2 = []
loser_list1 = []
loser_list2 = []
health_armor_exchange_dict = {"Light":1, "Medium":1.2, "Heavy":1.5}
def calculation1(unit1, unit2):
unit1_H = (unit1.health)*(health_armor_exchange_dict[unit1.armor])
unit2_H = (unit2.health)*(health_armor_exchange_dict[unit2.armor])
if (unit2_H//unit1.attack) < (unit1_H//unit2.attack):
print("Congradulations, your {unit1} win!".format(unit1 = unit1.name))
winner_list1.append(unit1)
loser_list2.append(unit2)
elif (unit2_H//unit1.attack) > (unit1_H//unit2.attack):
print("Sorry, enemy's {unit2} win!".format(unit2 = unit2.name))
winner_list2.append(unit2)
loser_list1.append(unit1)
elif (unit2_H // unit1.attack) == (unit1_H // unit2.attack) and ((unit1_H % unit2.attack >0 and unit2_H % unit1.attack >0) or (unit1_H % unit2.attack == 0 and unit2_H % unit1.attack == 0)):
print("Both {unit1} and {unit2} eliminated!".format(unit1 = unit1.name, unit2 = unit2.name))
loser_list1.append(unit1)
loser_list2.append(unit2)
elif (unit2_H // unit1.attack) == (unit1_H // unit2.attack) and (unit1_H % unit2.attack >0 and unit2_H % unit1.attack == 0):
print("Congradulations, your {unit1} win!".format(unit1 = unit1.name))
winner_list1.append(unit1)
loser_list2.append(unit2)
elif (unit2_H // unit1.attack) == (unit1_H // unit2.attack) and (unit1_H % unit2.attack == 0 and unit2_H % unit1.attack > 0):
print("Sorry, enemy's {unit2} win!".format(unit2 = unit2.name))
winner_list2.append(unit2)
loser_list1.append(unit1)
print("Hello, this is a STAR WARS combat game, you will design your own team in this game now.Each team has five unit in level1, level2, level3, level4 and level5.")
order_1 = input("First, choose your level1 unit. {names}:".format(names = list(level1_dict.keys())))
while order_1 not in level1_dict.keys():
order_1 = input("Please try again.")
Player_unit_list.append(level1_dict[order_1])
order_2 = input("Second, choose your level2 unit. {names}:".format(names = list(level2_dict.keys())))
while order_2 not in level2_dict.keys():
order_2 = input("Please try again.")
Player_unit_list.append(level2_dict[order_2])
order_3 = input("Last, choose your level3 unit. {names}:".format(names = list(level3_dict.keys())))
while order_3 not in level3_dict.keys():
order_3 = input("Please try again.")
Player_unit_list.append(level3_dict[order_3])
order_4 = input("Last, choose your level4 unit. {names}:".format(names = list(level4_dict.keys())))
while order_4 not in level4_dict.keys():
order_4 = input("Please try again.")
Player_unit_list.append(level4_dict[order_4])
order_5 = input("Last, choose your level5 unit. {names}:".format(names = list(level5_dict.keys())))
while order_5 not in level5_dict.keys():
order_5 = input("Please try again.")
Player_unit_list.append(level5_dict[order_5])
print("Your unit list is {name}".format(name = [order_1, order_2, order_3, order_4, order_5]))
for unit in Player_unit_list:
print("{name}:{history}".format(name = unit.name, history = unit.history))
print()
print("The battle will begin!")
print("First, your level1 unit {name1} will fight with enemy's level1 unit {name2}.".format(name1 = Player_unit_list[0].name, name2 = Computer_unit_pool[0].name))
calculation1(Player_unit_list[0], Computer_unit_pool[0])
Input = input("The battle will continue, do you want to change your level2 unit to have a better result? Enter Yes or No(case matter!)")
while Input != "Yes" and Input != "No":
Input = input("Please try again:")
if Input == "Yes":
order_2 = input("Please choose your level2 unit: {names}:".format(names = list(level2_dict.keys())))
while order_2 not in level2_dict.keys():
order_2 = input("Please try again.")
Player_unit_list[1] = level2_dict[order_2]
print("Your unit list is {name}".format(name = [order_1, order_2, order_3, order_4, order_5]))
print("Second, your level2 unit {name1} will fight with enemy's level2 unit {name2}.".format(name1 = Player_unit_list[1].name, name2 = Computer_unit_pool[1].name))
calculation1(Player_unit_list[1], Computer_unit_pool[1])
Input = input("The battle will continue, do you want to change your level3 unit to have a better result? Enter Yes or No(case matter!)")
while Input != "Yes" and Input != "No":
Input = input("Please try again:")
if Input == "Yes":
order_3 = input("Please choose your level3 unit: {names}:".format(names = list(level3_dict.keys())))
while order_3 not in level3_dict.keys():
order_3 = input("Please try again.")
Player_unit_list[2] = level3_dict[order_3]
print("Your unit list is {name}".format(name = [order_1, order_2, order_3, order_4, order_5]))
print("Third, your level3 unit {name1} will fight with enemy's level3 unit {name2}.".format(name1 = Player_unit_list[2].name, name2 = Computer_unit_pool[2].name))
calculation1(Player_unit_list[2], Computer_unit_pool[2])
Input = input("The battle will continue, do you want to change your level4 unit to have a better result? Enter Yes or No(case matter!)")
while Input != "Yes" and Input != "No":
Input = input("Please try again:")
if Input == "Yes":
order_4 = input("Please choose your level4 unit: {names}:".format(names = list(level4_dict.keys())))
while order_4 not in level4_dict.keys():
order_4 = input("Please try again.")
Player_unit_list[3] = level4_dict[order_4]
print("Your unit list is {name}".format(name = [order_1, order_2, order_3, order_4, order_5]))
print("Fourth, your level4 unit {name1} will fight with enemy's level4 unit {name2}.".format(name1 = Player_unit_list[3].name, name2 = Computer_unit_pool[3].name))
calculation1(Player_unit_list[3], Computer_unit_pool[3])
Input = input("The battle will continue, do you want to change your level5 unit to have a better result? Enter Yes or No(case matter!)")
while Input != "Yes" and Input != "No":
Input = input("Please try again:")
if Input == "Yes":
order_5 = input("Please choose your level5 unit: {names}:".format(names = list(level5_dict.keys())))
while order_5 not in level5_dict.keys():
order_5 = input("Please try again.")
Player_unit_list[4] = level5_dict[order_5]
print("Your unit list is {name}".format(name = [order_1, order_2, order_3, order_4, order_5]))
print("Last, your level5 unit {name1} will fight with enemy's level5 unit {name2}.".format(name1 = Player_unit_list[4].name, name2 = Computer_unit_pool[4].name))
calculation1(Player_unit_list[4], Computer_unit_pool[4])
if len(winner_list1) > len(winner_list2):
finalWinner = "You"
elif len(winner_list1) == len(winner_list2):
finalWinner = "None"
elif len(winner_list1) < len(winner_list2):
finalWinner = "Enemy"
print("Now, the duel has ended. Let us chear for the CHAMPION!")
print()
print()
if finalWinner == "You":
print("Congratulations!")
print("Your Team WON!")
elif finalWinner == "None":
print("Good game, the result is draw.")
elif finalWinner == "Enemy":
print("Sorry, the Enemy team has won.")