delaford / game

⚔️ An online JavaScript 2D Medieval RPG.
https://play.delaford.com/?useGuestAccount
MIT License
1.32k stars 843 forks source link

拿破仑转生少女-游戏-代码-newbing #207

Closed KionionVeriontor closed 10 months ago

KionionVeriontor commented 1 year ago

This is a simple RPG game about Napoleon being reincarnated as a girl

The game is turn-based and single-player

The game is generated by Bing chat mode

Import modules

import random import time

Define constants

HP = 100 # The player's health points ENEMY_HP = 50 # The enemy's health points ATTACK = 10 # The player's attack power ENEMY_ATTACK = 5 # The enemy's attack power HEAL = 20 # The player's heal amount ITEMS = ["sword", "shield", "potion"] # The items the player can use

Define functions

def print_message(message):

This function prints a message with a delay

print(message)
time.sleep(1)

def choose_action():

This function lets the player choose an action

print_message("What do you want to do?")
print_message("1. Attack")
print_message("2. Heal")
print_message("3. Use item")
action = input("> ")
return action

def choose_item():

This function lets the player choose an item

print_message("What item do you want to use?")
for i in range(len(ITEMS)):
    print_message(f"{i+1}. {ITEMS[i]}")
item = input("> ")
return item

def attack(enemy_hp):

This function calculates the damage done by the player's attack

global HP
global ENEMY_HP
damage = random.randint(ATTACK - 2, ATTACK + 2)
enemy_hp -= damage
print_message(f"You hit the enemy for {damage} points of damage.")
return enemy_hp

def heal():

This function calculates the amount of health restored by the player's heal

global HP
global ENEMY_HP
heal_amount = random.randint(HEAL - 2, HEAL + 2)
HP += heal_amount
if HP > 100:
    HP = 100
print_message(f"You heal yourself for {heal_amount} points of health.")

def use_item(item):

This function applies the effect of the item chosen by the player

global HP
global ENEMY_HP
global ATTACK
global ENEMY_ATTACK
if item == "1":
    # The sword increases the player's attack power by 5 for one turn
    ATTACK += 5
    print_message("You equip the sword and feel stronger.")
    ENEMY_HP = attack(ENEMY_HP)
    ATTACK -= 5
    print_message("The sword breaks after one use.")
elif item == "2":
    # The shield reduces the enemy's attack power by 5 for one turn
    ENEMY_ATTACK -= 5
    print_message("You equip the shield and feel safer.")
    enemy_attack()
    ENEMY_ATTACK += 5
    print_message("The shield breaks after one use.")
elif item == "3":
    # The potion restores 50 points of health to the player
    HP += 50
    if HP > 100:
        HP = 100
    print_message("You drink the potion and feel refreshed.")
    ITEMS.remove("potion")
    print_message("You have no more potions left.")
else:
    # The player chooses an invalid item
    print_message("That is not a valid item.")
    use_item(choose_item())

def enemy_attack():

This function calculates the damage done by the enemy's attack

global HP
global ENEMY_HP
damage = random.randint(ENEMY_ATTACK - 2, ENEMY_ATTACK + 2)
HP -= damage
print_message(f"The enemy hits you for {damage} points of damage.")

def game_over():

This function checks if the game is over and prints the result

global HP
global ENEMY_HP
if HP <= 0:
    print_message("You have no more health left.")
    print_message("You lose!")
    return True
elif ENEMY_HP <= 0:
    print_message("The enemy has no more health left.")
    print_message("You win!")
    return True
else:
    return False

Start the game

print_message("Welcome to Napoleon Girl RPG!") print_message("You are Napoleon Bonaparte, the famous French emperor and general.") print_message("But something strange has happened. You have been reincarnated as a girl in modern times!") print_message("You don't know why or how this happened, but you have to find a way to get back to your own time and body.") print_message("But it won't be easy. You have enemies everywhere who want to stop you or capture you.") print_message("You have to fight your way through them and find a way to reverse this curse.")

print_message("You are now in a dark alley. You see a shadowy figure approachinghttps://github.com/delaford/game/assets/125115532/af870bb8-77d2-4ec8-b796-60cd5429a8c0

ToadRage commented 10 months ago

why is this here