Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project completed #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/vikingsClasses.cpython-312.pyc
Binary file not shown.
87 changes: 71 additions & 16 deletions vikingsClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,111 @@

class Soldier:
def __init__(self, health, strength):
# your code here
self.health = health
self.strength = strength

def attack(self):
# your code here
return self.strength



def receiveDamage(self, damage):
# your code here
self.health -= damage



# Viking

class Viking(Soldier):
def __init__(self, name, health, strength):
# your code here
super().__init__(health, strength)
self.name = name


def battleCry(self):
# your code here
return "Odin Owns You All!"

def receiveDamage(self, damage):
# your code here

self.health -= damage
if self.health > 0:
return f"{self.name} has received {damage} points of damage"
else:
return f"{self.name} has died in act of combat"
# Saxon

class Saxon(Soldier):
def __init__(self, health, strength):
# your code here
super().__init__(health, strength)

def receiveDamage(self, damage):
# your code here
self.health -= damage
if self.health > 0:
return f"A Saxon has received {damage} points of damage"
else:
return f"{self.name} has died in act of combat"

# Davicente

class War():
def __init__(self):
# your code here
self.vikingArmy = []
self.saxonArmy = []

def addViking(self, viking):
# your code here
self.vikingArmy.append(viking)

def addSaxon(self, saxon):
# your code here
self.saxonArmy.append(saxon)

def vikingAttack(self):
# your code here
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
result = saxon.receiveDamage(viking.attack())
if saxon.health <= 0:
self.saxonArmy.remove(saxon)
return result

def saxonAttack(self):
# your code here
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
result = viking.receiveDamage(saxon.attack())
if viking.health <= 0:
self.vikingArmy.remove(viking)
return result

def showStatus(self):
# your code here
pass
if len(self.saxonArmy) == 0:
return "Vikings have won the war of the century!"
elif len(self.vikingArmy) == 0:
return "Saxons have fought for their lives and survive another day..."
else:
return "Vikings and Saxons are still in the thick of battle."


def main():
print("Welcome to the Viking vs. Saxon Battle Simulator!")

# Step 1: Create the teams
viking_names = ["Ragnar", "Lagertha", "Bjorn", "Floki", "Ivar"]
viking_count = int(input("Enter the number of Vikings: "))
saxon_count = int(input("Enter the number of Saxons: "))

vikings = create_viking_team(viking_names, viking_count)
saxons = create_saxon_team(saxon_count)

# Step 2: Set up the war
war = War()
for viking in vikings:
war.addViking(viking)
for saxon in saxons:
war.addSaxon(saxon)

print("\nThe armies are ready!")
print(f"Viking army: {len(war.vikingArmy)} warriors")
print(f"Saxon army: {len(war.saxonArmy)} warriors\n")

# Step 3: Run the battle
run_battle(war)

if __name__ == "__main__":
main()
69 changes: 69 additions & 0 deletions vikingsGame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from vikingsClasses import Viking, Saxon, War
import random

def create_viking_team(names, count):
"""Create a list of Viking warriors with random health and strength."""
vikings = []
for _ in range(count):
name = random.choice(names)
health = random.randint(100, 200)
strength = random.randint(30, 50)
vikings.append(Viking(name, health, strength))
return vikings

def create_saxon_team(count):
"""Create a list of Saxon warriors with random health and strength."""
saxons = []
for _ in range(count):
health = random.randint(80, 150)
strength = random.randint(25, 40)
saxons.append(Saxon(health, strength))
return saxons

def run_battle(war):
"""Run the battle between Vikings and Saxons."""
round_number = 1
while war.vikingArmy and war.saxonArmy:
print(f"--- Round {round_number} ---")
if random.choice([True, False]):
result = war.vikingAttack()
print(f"Viking attacks: {result}")
else:
result = war.saxonAttack()
print(f"Saxon attacks: {result}")

round_number += 1

if round_number % 3 == 0:
print(war.showStatus())

print("\n--- Final Status ---")
print(war.showStatus())

def main():
print("Welcome to the Viking vs. Saxon Battle Simulator!")

# Step 1: Create the teams
viking_names = ["Wasif", "Larry", "Cindy", "Ignacio", "Montassar"]
viking_count = int(input("Enter the number of Vikings: "))
saxon_count = int(input("Enter the number of Saxons: "))

vikings = create_viking_team(viking_names, viking_count)
saxons = create_saxon_team(saxon_count)

# Step 2: Set up the war
war = War()
for viking in vikings:
war.addViking(viking)
for saxon in saxons:
war.addSaxon(saxon)

print("\nThe armies are ready!")
print(f"Viking army: {len(war.vikingArmy)} warriors")
print(f"Saxon army: {len(war.saxonArmy)} warriors\n")

# Step 3: Run the battle
run_battle(war)

if __name__ == "__main__":
main()