Hi! In my spare time from website development and SEO we are doing a fan version of Shining Force.
we are working on the concept and code of the game
import random
class Character:
def __init__(self, name, max_hp, attack, defense):
self.name = name
self.max_hp = max_hp
self.hp = max_hp
self.attack = attack
self.defense = defense
self.alive = True
def __str__(self):
return f"{self.name} HP: {self.hp}/{self.max_hp}"
def attack_damage(self):
return self.attack + random.randint(1, 6) # Shining Force uses a 6-sided dice for damage calculation.
def defend(self, damage):
damage_taken = damage - self.defense
if damage_taken < 0:
damage_taken = 0
self.hp -= damage_taken
if self.hp <= 0:
self.alive = False
class Player(Character):
def __init__(self, name, max_hp, attack, defense):
super().__init__(name, max_hp, attack, defense)
def choose_action(self):
print("Choose an action:")
print("1. Attack")
print("2. Defend")
choice = input("Enter your choice: ")
return choice
class Enemy(Character):
def __init__(self, name, max_hp, attack, defense):
super().__init__(name, max_hp, attack, defense)
def choose_action(self):
return "1" # Enemies always choose to attack.
def combat(player, enemy):
print(f"{player.name} faces {enemy.name} in battle!\n")
while player.alive and enemy.alive:
print(player)
print(enemy)
# Player's turn
action = player.choose_action()
if action == "1":
damage = player.attack_damage()
print(f"{player.name} attacks {enemy.name} for {damage} damage!")
enemy.defend(damage)
elif action == "2":
player.defense += 2 # Shining Force increases defense by a fixed amount.
print(f"{player.name} defends and increases DEF by 2.")
if not enemy.alive:
print(f"{enemy.name} has fallen!")
break
# Enemy's turn
damage = enemy.attack_damage()
print(f"{enemy.name} attacks {player.name} for {damage} damage!")
player.defend(damage)
if not player.alive:
print(f"{player.name} has fallen!")
break
print("\nBattle has ended.\n")
# Sample usage:
player = Player("Hero", 20, 5, 3)
enemy = Enemy("Goblin", 15, 4, 2)
combat(player, enemy)
This code includes an Character class representing both the player and enemies. Each character has HP, MP, attack, defense, magic, agility, and level parameters. The player and enemies also have their own choose_action method for choosing what to do in battle, and the player has a use_magic method for casting spells.
The combat function takes two Character instances as parameters and simulates a turn-based battle between them. It prints out what happens in each turn and adjusts the HP and defense of characters as necessary. The combat function runs until one of the characters is defeated.
This code is just an example and can be extended to create a full game. You can add more characters, items, quests, and explore different battles scenarios.