Auf einem textbasierten Game.py. Ich muss den Code für das textbasierte Spiel basierend auf meinem Pseudocode oder Flowdiagramms schreiben. Ich kann bereits durch die Räume navigieren und die Gegenstände abholen, aber die letzten beiden Räume als Boss -Räume hinzugefügt und den Sieg geschrieben und die Bedingungen verlieren, um das Spiel zu beenden. Auch wenn ich die 6 Artikel im Boss -Raum habe. < /p>
Mein Problem ist, dass auch wenn mein Code einen Sieg hat und im Code geschrieben wird. Ich kann den Siegzustand nicht auslösen. Ich kann die 6 Artikel bekommen und wenn ich in den Boss -Raum komme, bekomme ich immer noch den Verlust des Zustands ausgelöst: < /p>
"You have lost... GAME OVER!"
< /code>
#print a main menu and the commands
def show_instructions():
"""Displays the instructions for the game, including the available commands."""
print("Royal Dragon Text Adventure Game")
print("Collect 6 items and go defeat the darkness to win the game, or your life will be consume by the darkness.")
print("Move commands: go South, go North, go East, go West")
print("Add to Inventory: get 'item name'")
# Function to show the player's current status: current room, inventory, and item in the room
def show_status(player, rooms):
"""Displays the current status of the player including their room and inventory."""
current_room = player['current_room']
inventory = player['inventory']
item_in_room = rooms[current_room].get('item', 'None')
print(f"You are in the {current_room}")
print(f"Inventory: {inventory}")
print(f"You see a {item_in_room}")
print("----------------------")
print("Enter your move:")
# Game dictionary linking a room to other rooms.
rooms = {
'Kingdom Entrance': {
'directions': {'South': 'City', 'North': 'Forrest', 'East': 'Kingdom Store', 'West': 'Castle'},
'item': None
},
'Forrest': {
'directions': {'South': 'Kingdom Entrance', 'North': 'Map Room', 'East': 'Forrest dragil'},
'item': None
},
'Map Room': {
'directions': {'South': 'Forrest'},
'item': 'map'
},
'Forrest dragil': {
'directions': {'West': 'Forrest'},
'item': 'dragon heart'
},
'City': {
'directions': {'North': 'Kingdom Entrance', 'East': 'City dragil', 'West': 'King dragil'},
'item': None
},
'City dragil': {
'directions': {'West': 'City'},
'item': 'king sword'
},
'King dragil': {
'directions': {'East': 'City'},
'item': 'gauntlets'
},
'Kingdoms dragil': {
'directions': {'South': 'Kingdom Store'},
'item': 'dragon soul'
},
'Kingdom Store': {
'directions': {'North': 'Kingdoms dragil', 'West': 'Kingdom Entrance'},
'item': 'potions'
},
'Castle': {
'directions': {'East': 'Kingdom Entrance', 'North': 'Throne Room'},
'item': 'king dark brother' # First Villain Encounter
},
'Throne Room': {
'directions': {'South': 'Castle'},
'item': 'real villain' # Final Boss
}
}
# Display the instructions at the start of the game
show_instructions()
def move_player(direction, current_room, rooms):
"""Handles the player’s movement, checking if the direction is valid."""
# Check if the direction exists in the current room
if direction in rooms[current_room]['directions']:
next_room = rooms[current_room]['directions'][direction]
return next_room
else:
return None # Invalid move or direction
# Function to check for victory condition
def check_victory_condition(player):
"""Check if the player has won the game."""
if len(player['inventory']) == 6 and len(player['defeated_bosses']) == 2:
print("Congratulations! You have collected all items and defeated the Darkness!")
return True
return False
# Check for losing condition
def check_losing_condition(player):
"""Check for losing condition."""
# If player is in Castle and hasn't defeated the first boss yet (king dark brother)
if player['current_room'] == 'Castle' and 'king dark brother' in player['inventory'] and 'king dark brother' not in player['defeated_bosses']:
print("You forfeit your life... GAME OVER!")
return True
# If player is in Throne Room and hasn't defeated the final boss yet (real villain)
elif player['current_room'] == 'Throne Room' and 'real villain' in player['inventory'] and 'real villain' not in player['defeated_bosses']:
print("You cannot defeat the Real Villain without the required item... GAME OVER!")
return True
return False
# Main gameplay loop
def main():
# Main gameplay function
player = {
'current_room': 'Kingdom Entrance', # Starting room
'inventory': [], # Inventory is initially empty
'defeated_bosses': [] # Track defeated bosses
}
# Main gameplay loop
while True:
show_status(player, rooms) # Show the player's status (current room, inventory)
# Get player input for movement or item collection
move = input("What would you like to do? ").strip().lower()
if move.startswith("go"):
# Handle movement
direction = move.split(" ")[1].capitalize()
# Use the move_player function to handle the movement
next_room = move_player(direction, player['current_room'], rooms)
if next_room:
player['current_room'] = next_room
print(f"You move {direction} to the {next_room}.")
else:
print("You cannot go that way or invalid direction.")
elif move.startswith("get"):
# Handle item collection
try:
item = move.split(" ", 1)[1].strip()
except IndexError:
print("Please specify an item to get.")
continue
current_room = player['current_room']
room_item = rooms[current_room].get('item')
if room_item and room_item.lower() == item.lower():
player['inventory'].append(item)
rooms[current_room]['item'] = None
print(f"{item} added to inventory.")
else:
if room_item:
print(f"There is no {item} in this room.")
else:
print("There is nothing to collect in this room.")
# Check if the player is in a room with a boss
if player['current_room'] == 'Castle' and 'king dark brother' in player['inventory'] and 'king dark brother' not in player['defeated_bosses']:
# Fight the first boss (King Dark Brother)
print("You face the King Dark Brother!")
if 'king dark brother' in player['inventory']:
player['defeated_bosses'].append('king dark brother')
print("You have defeated the King Dark Brother!")
else:
print("You need the 'king dark brother' item to defeat this boss!")
elif player['current_room'] == 'Throne Room' and 'real villain' in player['inventory'] and 'real villain' not in player['defeated_bosses']:
# Fight the final boss (Real Villain)
print("You face the Real Villain!")
if 'real villain' in player['inventory']:
player['defeated_bosses'].append('real villain')
print("You have defeated the Real Villain!")
else:
print("You need the 'real villain' item to defeat this boss!")
# Print debug info for inventory and current room
print(f"Current Room: {player['current_room']}")
print(f"Inventory: {player['inventory']}")
print(f"Defeated Bosses: {player['defeated_bosses']}")
# Check for victory condition
if check_victory_condition(player):
print("Victory! You have defeated the Darkness!")
break
# Check for losing condition
if check_losing_condition(player):
print("You have lost... GAME OVER!")
break
def validate_input(move, player, rooms):
"""Validates the player's move or item command."""
if move.startswith("go"):
direction = move.split(" ")[1].capitalize()
if direction in rooms[player['current_room']]:
return True
else:
print("Invalid direction.")
return False
elif move.startswith("get"):
item = move.split(" ", 1)[1]
current_room = player['current_room']
if rooms[current_room].get('item') == item:
return True
else:
print(f"There is no {item} in this room.")
return False
else:
print("Invalid command.")
return False
if __name__ == "__main__":
main()
Auf einem textbasierten Game.py. Ich muss den Code für das textbasierte Spiel basierend auf meinem Pseudocode oder Flowdiagramms schreiben. Ich kann bereits durch die Räume navigieren und die Gegenstände abholen, aber die letzten beiden Räume als Boss -Räume hinzugefügt und den Sieg geschrieben und die Bedingungen verlieren, um das Spiel zu beenden. Auch wenn ich die 6 Artikel im Boss -Raum habe. < /p> Mein [url=viewtopic.php?t=11587]Problem[/url] ist, dass auch wenn mein Code einen Sieg hat und im Code geschrieben wird. Ich kann den Siegzustand nicht auslösen. Ich kann die 6 Artikel bekommen und wenn ich in den Boss -Raum komme, bekomme ich immer noch den Verlust des Zustands ausgelöst: < /p> [code]"You have lost... GAME OVER!" < /code>
#print a main menu and the commands def show_instructions(): """Displays the instructions for the game, including the available commands.""" print("Royal Dragon Text Adventure Game") print("Collect 6 items and go defeat the darkness to win the game, or your life will be consume by the darkness.") print("Move commands: go South, go North, go East, go West") print("Add to Inventory: get 'item name'")
# Function to show the player's current status: current room, inventory, and item in the room def show_status(player, rooms): """Displays the current status of the player including their room and inventory.""" current_room = player['current_room'] inventory = player['inventory'] item_in_room = rooms[current_room].get('item', 'None')
print(f"You are in the {current_room}") print(f"Inventory: {inventory}") print(f"You see a {item_in_room}") print("----------------------") print("Enter your move:")
# Display the instructions at the start of the game show_instructions()
def move_player(direction, current_room, rooms): """Handles the player’s movement, checking if the direction is valid.""" # Check if the direction exists in the current room if direction in rooms[current_room]['directions']: next_room = rooms[current_room]['directions'][direction] return next_room else: return None # Invalid move or direction
# Function to check for victory condition def check_victory_condition(player): """Check if the player has won the game.""" if len(player['inventory']) == 6 and len(player['defeated_bosses']) == 2: print("Congratulations! You have collected all items and defeated the Darkness!") return True return False
# Check for losing condition def check_losing_condition(player): """Check for losing condition.""" # If player is in Castle and hasn't defeated the first boss yet (king dark brother) if player['current_room'] == 'Castle' and 'king dark brother' in player['inventory'] and 'king dark brother' not in player['defeated_bosses']: print("You forfeit your life... GAME OVER!") return True # If player is in Throne Room and hasn't defeated the final boss yet (real villain) elif player['current_room'] == 'Throne Room' and 'real villain' in player['inventory'] and 'real villain' not in player['defeated_bosses']: print("You cannot defeat the Real Villain without the required item... GAME OVER!") return True return False
# Main gameplay loop def main(): # Main gameplay function player = { 'current_room': 'Kingdom Entrance', # Starting room 'inventory': [], # Inventory is initially empty 'defeated_bosses': [] # Track defeated bosses }
# Main gameplay loop while True: show_status(player, rooms) # Show the player's status (current room, inventory) # Get player input for movement or item collection move = input("What would you like to do? ").strip().lower()
if move.startswith("go"): # Handle movement direction = move.split(" ")[1].capitalize() # Use the move_player function to handle the movement next_room = move_player(direction, player['current_room'], rooms)
if next_room: player['current_room'] = next_room print(f"You move {direction} to the {next_room}.") else: print("You cannot go that way or invalid direction.")
current_room = player['current_room'] room_item = rooms[current_room].get('item') if room_item and room_item.lower() == item.lower(): player['inventory'].append(item) rooms[current_room]['item'] = None print(f"{item} added to inventory.") else: if room_item: print(f"There is no {item} in this room.") else: print("There is nothing to collect in this room.")
# Check if the player is in a room with a boss if player['current_room'] == 'Castle' and 'king dark brother' in player['inventory'] and 'king dark brother' not in player['defeated_bosses']: # Fight the first boss (King Dark Brother) print("You face the King Dark Brother!") if 'king dark brother' in player['inventory']: player['defeated_bosses'].append('king dark brother') print("You have defeated the King Dark Brother!") else: print("You need the 'king dark brother' item to defeat this boss!")
elif player['current_room'] == 'Throne Room' and 'real villain' in player['inventory'] and 'real villain' not in player['defeated_bosses']: # Fight the final boss (Real Villain) print("You face the Real Villain!") if 'real villain' in player['inventory']: player['defeated_bosses'].append('real villain') print("You have defeated the Real Villain!") else: print("You need the 'real villain' item to defeat this boss!")
# Print debug info for inventory and current room print(f"Current Room: {player['current_room']}") print(f"Inventory: {player['inventory']}") print(f"Defeated Bosses: {player['defeated_bosses']}")
# Check for victory condition if check_victory_condition(player): print("Victory! You have defeated the Darkness!") break
# Check for losing condition if check_losing_condition(player): print("You have lost... GAME OVER!") break
def validate_input(move, player, rooms): """Validates the player's move or item command.""" if move.startswith("go"): direction = move.split(" ")[1].capitalize() if direction in rooms[player['current_room']]: return True else: print("Invalid direction.") return False elif move.startswith("get"): item = move.split(" ", 1)[1] current_room = player['current_room'] if rooms[current_room].get('item') == item: return True else: print(f"There is no {item} in this room.") return False else: print("Invalid command.") return False
Versuch, ein Programmierlabor in meinem Intro in die Skriptklasse herauszufinden, und ich habe das Gefühl, dass jeder Fehler, den ich behebe, nur zu einem neuen Fehler führt. Die Zuordnung ist
ein...
Ich möchte die Discord Rich Presence-Integration zu einer C#-Anwendung hinzufügen. Gemäß der Dokumentation von Discord habe ich deren offizielles Discord Game SDK ausgewählt, das über C#-Bindungen...
Nach dem neuesten Game Maker IDE/Runtime-Update stürzte mein Spiel auf jedem Arm v7-Gerät ab.
Spieler berichten, dass der Absturz sofort beim Start des Spiels auftritt. Keine Probleme auf anderen...