π
<-
Chat plein-écran
[^]

Jeu rpg sur numworks

Jeu rpg sur numworks

Unread postby doux-loux » 28 Feb 2024, 20:36

Bonjour, je débute tout juste dans numworks et j'ai tenté de créer un jeu rpg avec l'aide de quelques tutoriels .
Malheureusement lorsque je lance le script, j'obtiens des erreurs de syntaxe notamment ligne 109 du script. Est-ce que quelqu'un aurait une idée pour régler cela ?
Merci d'avance.
voici le script :
(il y a quelques erreurs d'affichage mais je suppose que c'est normal)
(je suis sur la dernière version: la 22)

Code: Select all
# Type your text here# Type your text hereimport random

# Carte du monde
WORLD_MAP = [
    "XXXXXXXXXXXXXXXXXXXXXXXXX",
    "X.P.....................X",
    "X.......................X",
    "X.....V..............A..X",
    "X.......................X",
    "X.........EEEEE.........X",
    "X.........EEEEE.........X",
    "X.........EEEEE.........X",
    "X.........EEEEE.........X",
    "X.........EEEEE.........X",
    "X.........EEEEE.........X",
    "X.......................X",
    "X.......................X",
    "X.......................X",
    "X.......M...............X",
    "XXXXXXXXXXXXXXXXXXXXXXXXX"
]

# Position initiale et symbole du joueur
player_symbol = 'P'
player_pos = [1, 1]

# Statistiques du joueur
player_base_hp = 20
player_base_attack = 5
player_base_defense = 2
player_base_pe = 10  # Points d'effort
player_max_hp = player_base_hp
player_max_pe = player_base_pe
player_attack_boost = 0
player_defense_boost = 0
player_pe_boost = 0

# Statistiques du joueur modifiées par les objets et les interactions
player_hp = player_max_hp
player_attack = player_base_attack
player_defense = player_base_defense
player_pe = player_max_pe

# Ennemis possibles et leurs caractéristiques
ENEMIES = {
    'Goblin': {'hp': 10, 'attack': 3, 'defense': 1, 'special_defense': 2, 'special_chance': 0.2, 'frozen': False, 'burning': False},
    'Dragon': {'hp': 20, 'attack': 5, 'defense': 3, 'special_defense': 1, 'special_chance': 0.3, 'frozen': False, 'burning': False},
    'Skeleton': {'hp': 8, 'attack': 2, 'defense': 2, 'special_defense': 3, 'special_chance': 0.1, 'frozen': False, 'burning': False},
    'Slime': {'hp': 5, 'attack': 1, 'defense': 0, 'special_defense': 0, 'special_chance': 0.4, 'frozen': False, 'burning': False},
    'Boss': {'hp': 50, 'attack': 10, 'defense': 5, 'special_defense': 5, 'special_chance': 0.5, 'frozen': False, 'burning': False}
}

# Objets disponibles chez le vendeur
SHOP_ITEMS = {
    'Potion': {'price': 5, 'hp_restore': 10},
    'Sword': {'price': 10, 'attack_bonus': 3},
    'Shield': {'price': 8, 'defense_bonus': 2},
    'Strength Potion': {'price': 15, 'attack_bonus': 5},
    'Effort Drink': {'price': 10, 'pe_bonus': 5},
    'Freezing Scroll': {'price': 12, 'effect': 'freeze'},
    'Fire Scroll': {'price': 12, 'effect': 'burn'}
}

# Arme puissante sur le piédestal
POWERFUL_WEAPON = {'name': 'Legendary Sword', 'attack_bonus': 10, 'pe_requirement': 15}

# Fonction pour afficher la carte du monde avec le joueur
def display_world():
    world_with_player = [list(row) for row in WORLD_MAP]
    world_with_player[player_pos[0]][player_pos[1]] = player_symbol
    for row in world_with_player:
        print(''.join(row))

# Fonction pour déplacer le joueur
def move_player(direction):
    global player_pos
    new_pos = list(player_pos)
    if direction == 'n':
        new_pos[0] -= 1
    elif direction == 's':
        new_pos[0] += 1
    elif direction == 'e':
        new_pos[1] += 1
    elif direction == 'o':
        new_pos[1] -= 1
   
    if WORLD_MAP[new_pos[0]][new_pos[1]] != 'X':
        player_pos = new_pos
        encounter()

# Fonction pour gérer les rencontres avec les ennemis ou les PNJ
def encounter():
    global player_hp, player_gold, player_attack, player_defense, player_pe, player_attack_boost, player_defense_boost, player_pe_boost
    tile = WORLD_MAP[player_pos[0]][player_pos[1]]
    if tile == 'E':
        enemy_name = random.choices(list(ENEMIES.keys()), weights=list(ENEMIES.values()))[0]
        enemy_stats = ENEMIES[enemy_name]
       
        print(f"You encounter a {enemy_name}!")
       
        while player_hp > 0 and enemy_stats['hp'] > 0:
            print(f"Player HP: {player_hp}, {enemy_name} HP: {enemy_stats['hp']}, PE: {player_pe}")
            action = input("Attack (a), Special Attack (s), or Run (r): ").lower()
            if action == 'a':
                # Player physical attack
                if random.random() < 0.7:  # Physical attack has 70% chance to hit
                    enemy_stats['hp'] -= max(0, player_attack + player_attack_boost - enemy_stats['defense'])
                    if enemy_stats['hp'] <= 0:
                        print(f"You defeated the {enemy_name}!")
                        break
                else:
                    print("Your physical attack missed!")
               
                # Enemy attack
                if random.random() < 0.8:  # Enemy has 80% chance to hit with physical attack
                    player_hp -= max(0, enemy_stats['attack'] - (player_defense + player_defense_boost))
                else:
                    print(f"The {enemy_name}'s physical attack missed!")
               
                if player_hp <= 0:
                    print("Game Over. You were defeated.")
                    exit()
            elif action == 's':
                # Player special attack
                if random.random() < 0.6:  # Special attack has 60% chance to hit
                    if 'frozen' in enemy_stats and enemy_stats['frozen']:
                        print("The enemy is frozen and unable to move!")
                    elif 'burning' in enemy_stats and enemy_stats['burning']:
                        print("The enemy is burning and takes extra damage!")
                        enemy_stats['hp'] -= max(0, (player_attack + player_attack_boost) * 2 - enemy_stats['special_defense'])  # Double damage for special attack
                    else:
                        enemy_stats['hp'] -= max(0, (player_attack + player_attack_boost) * 2 - enemy_stats['special_defense'])  # Double damage for special attack
                        if SHOP_ITEMS[action]['effect'] == 'freeze' and random.random() < 0.4:  # 40% chance to freeze the enemy
                            enemy_stats['frozen'] = True
                            print("The enemy is frozen solid!")
                        elif SHOP_ITEMS[action]['effect'] == 'burn' and random.random() < 0.4:  # 40% chance to burn the enemy
                            enemy_stats['burning'] = True
                            print("The enemy is burning!")
                    if enemy_stats['hp'] <= 0:
                        print(f"You defeated the {enemy_name}!")
                        break
                else:
                    print("Your special attack missed!")
               
                # Enemy attack
                if random.random() < enemy_stats['special_chance']:
                    player_hp -= max(0, enemy_stats['attack'] * 2 - (player_defense + player_defense_boost))  # Double damage for enemy's special attack
                else:
                    player_hp -= max(0, enemy_stats['attack'] - (player_defense + player_defense_boost))
               
                if player_hp <= 0:
                    print("Game Over. You were defeated.")
                    exit()
            elif action == 'r':
                print("You managed to escape.")
                break
            else:
                print("Invalid action.")
    elif tile == 'V':
        print("You encounter a vendor.")
        print("Vendor: Welcome, adventurer! Take a look at what I have for sale:")
        for item, details in SHOP_ITEMS.items():
            print(f"{item}: Price - {details['price']} gold")
        action = input("Enter the name of the item you want to buy (or 'leave' to exit): ").lower()
        if action in SHOP_ITEMS:
            if player_gold >= SHOP_ITEMS[action]['price']:
                player_gold -= SHOP_ITEMS[action]['price']
                if 'hp_restore' in SHOP_ITEMS[action]:
                    player_hp += SHOP_ITEMS[action]['hp_restore']
                    print(f"You bought a {action} and restored {SHOP_ITEMS[action]['hp_restore']} HP.")
                elif 'attack_bonus' in SHOP_ITEMS[action]:
                    player_attack_boost = min(5, player_attack_boost + SHOP_ITEMS[action]['attack_bonus'])  # Limit attack boost to 5
                    print(f"You bought a {action} and increased your attack by {SHOP_ITEMS[action]['attack_bonus']}.")
                elif 'defense_bonus' in SHOP_ITEMS[action]:
                    player_defense_boost = min(5, player_defense_boost + SHOP_ITEMS[action]['defense_bonus'])  # Limit defense boost to 5
                    print(f"You bought a {action} and increased your defense by {SHOP_ITEMS[action]['defense_bonus']}.")
                elif 'pe_bonus' in SHOP_ITEMS[action]:
                    player_pe_boost = min(10, player_pe_boost + SHOP_ITEMS[action]['pe_bonus'])  # Limit pe boost to 10
                    print(f"You bought a {action} and increased your PE by {SHOP_ITEMS[action]['pe_bonus']}.")
                elif SHOP_ITEMS[action]['effect'] == 'freeze' or SHOP_ITEMS[action]['effect'] == 'burn':
                    enemy_name = random.choices(list(ENEMIES.keys()), weights=list(ENEMIES.values()))[0]
                    enemy_stats = ENEMIES[enemy_name]
                    if SHOP_ITEMS[action]['effect'] == 'freeze' and random.random() < 0.4:  # 40% chance to freeze the enemy
                        enemy_stats['frozen'] = True
                        print("You used the freezing scroll and the enemy is frozen solid!")
                    elif SHOP_ITEMS[action]['effect'] == 'burn' and random.random() < 0.4:  # 40% chance to burn the enemy
                        enemy_stats['burning'] = True
                        print("You used the fire scroll and the enemy is burning!")
            else:
                print("You don't have enough gold to buy that item.")
        else:
            print("Vendor: Farewell, adventurer!")
    elif tile == 'A':  # Animal
        print("You encounter a friendly animal.")
        action = input("Do you want to pat the animal? (yes/no): ").lower()
        if action == 'yes':
            print("You pat the animal gently.")
            player_pe += 3  # Ajoute 3 PE lorsque le joueur caresse l'animal
            print("The animal seems happy and runs away.")
        else:
            print("You decide not to disturb the animal.")
    elif tile == 'M':  # Piédestal avec l'arme puissante
        print("You encounter a pedestal with a powerful weapon on it.")
        if player_pe >= POWERFUL_WEAPON['pe_requirement']:
            print(f"You have enough PE to wield the {POWERFUL_WEAPON['name']}!")
            action = input("Do you want to take the weapon? (yes/no): ").lower()
            if action == 'yes':
                player_attack_boost += POWERFUL_WEAPON['attack_bonus']
                print(f"You take the {POWERFUL_WEAPON['name']} from the pedestal.")
            else:
                print("You decide not to take the weapon.")
        else:
            print(f"You need at least {POWERFUL_WEAPON['pe_requirement']} PE to wield the {POWERFUL_WEAPON['name']}.")
    elif tile == 'B':  # Boss
        print("You encounter the boss!")
        boss_name = 'Boss'
        boss_stats = ENEMIES[boss_name]
        print(f"You encounter {boss_name}! Prepare for battle!")

        while player_hp > 0 and boss_stats['hp'] > 0:
            print(f"Player HP: {player_hp}, Boss HP: {boss_stats['hp']}, PE: {player_pe}")
            action = input("Attack (a), Special Attack (s), or Run (r): ").lower()
            if action == 'a':
                # Player physical attack
                if random.random() < 0.7:  # Physical attack has 70% chance to hit
                    boss_stats['hp'] -= max(0, player_attack + player_attack_boost - boss_stats['defense'])
                    if boss_stats['hp'] <= 0:
                        print(f"You defeated the {boss_name}!")
                        break
                else:
                    print("Your physical attack missed!")
               
                # Boss attack
                if random.random() < 0.8:  # Boss has 80% chance to hit with physical attack
                    player_hp -= max(0, boss_stats['attack'] - (player_defense + player_defense_boost))
                else:
                    print(f"{boss_name}'s physical attack missed!")
               
                if player_hp <= 0:
                    print("Game Over. You were defeated.")
                    exit()
            elif action == 's':
                # Player special attack
                if random.random() < 0.6:  # Special attack has 60% chance to hit
                    boss_stats['hp'] -= max(0, (player_attack + player_attack_boost) * 2 - boss_stats['special_defense'])  # Double damage for special attack
                    if boss_stats['hp'] <= 0:
                        print(f"You defeated the {boss_name}!")
                        break
                else:
                    print("Your special attack missed!")
               
                # Boss attack
                if random.random() < boss_stats['special_chance']:
                    player_hp -= max(0, boss_stats['attack'] * 2 - (player_defense + player_defense_boost))  # Double damage for boss's special attack
                else:
                    player_hp -= max(0, boss_stats['attack'] - (player_defense + player_defense_boost))
               
                if player_hp <= 0:
                    print("Game Over. You were defeated.")
                    exit()
            elif action == 'r':
                print("You cannot escape from this battle!")
            else:
                print("Invalid action.")
    else:
        print("Nothing interesting here.")

# Boucle principale du jeu
while True:
    display_world()
    direction = input("Enter a direction (n/s/e/o): ").lower()
    if direction in ['n', 's', 'e', 'o']:
        move_player(direction)
    else:
        print("Invalid direction.").
User avatar
doux-loux
Niveau 0: MI (Membre Inactif)
Niveau 0: MI (Membre Inactif)
Level up: 0%
 
Posts: 2
Joined: 28 Feb 2024, 20:20
Gender: Not specified
Calculator(s):
MyCalcs profile

Re: Jeu rpg sur numworks

Unread postby Afyu » 28 Feb 2024, 22:41

Bonsoir doux-loux.

Ton script fonctionne très bien... mais pas sur Epsilon (le firmware officiel de la NumWorks), dans lequel Python ne gère pas les f-string (que tu utilises lignes 109, 163, 213 ou 221, entre autres).

Le firmware alternatif Upsilon gère très bien les f-string et ton script fonctionne très bien, si on enlève le point final ligne 275 :D

Si tu veux vérifier, c'est par ici : https://yaya-cout.github.io/Upsilon-Workshop/

En revanche, a priori tu ne pourras pas installer Upsilon sur ta N0115 pour y faire fonctionner ton script.

Sur le simulateur Upsilon, j'ai testé rapidement et j'ai vu la carte et j'ai fini par croiser un marchand :)
User avatar
AfyuVIP++
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 90.5%
 
Posts: 347
Images: 18
Joined: 30 Oct 2019, 19:17
Gender: Male
Calculator(s):
MyCalcs profile
Class: plutôt, oui :)

Re: Jeu rpg sur numworks

Unread postby doux-loux » 29 Feb 2024, 16:40

Je vois, j'ai d'ores et déjà réglé le problème suite à ton message.
merci à toi pour m'avoir aidé à régler ce problème :)
User avatar
doux-loux
Niveau 0: MI (Membre Inactif)
Niveau 0: MI (Membre Inactif)
Level up: 0%
 
Posts: 2
Joined: 28 Feb 2024, 20:20
Gender: Not specified
Calculator(s):
MyCalcs profile


Return to Programmation Python

Who is online

Users browsing this forum: No registered users and 1 guest

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
840 utilisateurs:
>798 invités
>37 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)