game
gagan652319 opened this issue · comments
Environment data
- VS Code version: XXX
- Jupyter Extension version (available under the Extensions sidebar): XXX
- Python Extension version (available under the Extensions sidebar): XXX
- OS (Windows | Mac | Linux distro) and version: XXX
- Python and/or Anaconda version: XXX
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): XXX
- Jupyter server running: Local | Remote | N/A
Expected behaviour
XXX
Actual behaviour
XXX
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
- XXX
Logs
Output for Jupyter
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Jupyter
)
XXX
import random
class Player:
def init(self, name, health=100, attack=20, defense=10):
self.name = name
self.health = health
self.max_health = health
self.attack = attack
self.defense = defense
self.position = (random.randint(0, 50), random.randint(0, 50))
self.inventory = []
self.score = 0
def move(self, direction):
x, y = self.position
if direction == "up":
y = min(y + 1, 50)
elif direction == "down":
y = max(y - 1, 0)
elif direction == "left":
x = max(x - 1, 0)
elif direction == "right":
x = min(x + 1, 50)
self.position = (x, y)
def attack_player(self, other_player):
damage = max(0, self.attack - other_player.defense)
other_player.health -= damage
print(f"{self.name} attacked {other_player.name} for {damage} damage!")
if not other_player.is_alive():
print(f"{other_player.name} has been defeated!")
self.score += 1
def is_alive(self):
return self.health > 0
def add_item(self, item):
self.inventory.append(item)
if item == "Health Potion":
self.health = min(self.max_health, self.health + 50)
elif item == "Sword":
self.attack += 10
elif item == "Shield":
self.defense += 5
elif item == "Armor":
self.defense += 10
print(f"{self.name} picked up {item}")
def use_ability(self, other_player):
# Implement special abilities here
pass
class Item:
def init(self, name, description):
self.name = name
self.description = description
def generate_items(num_items):
items = []
item_names = ["Health Potion", "Sword", "Shield", "Armor"]
item_descriptions = [
"Restores 50 health points.",
"Increases attack by 10.",
"Increases defense by 5.",
"Increases defense by 10."
]
for _ in range(num_items):
name = random.choice(item_names)
item_names.remove(name)
description = item_descriptions.pop(0)
items.append(Item(name, description))
return items
def print_player_status(player):
print(f"Player: {player.name}, Health: {player.health}/{player.max_health}, Attack: {player.attack}, Defense: {player.defense}, Score: {player.score}")
def main():
num_players = int(input("Enter the number of players: "))
players = [Player(f"Player {i+1}") for i in range(num_players)]
items = generate_items(num_players * 2)
while len(players) > 1:
for player in players:
if len(players) == 1:
break
print(f"\n{player.name}'s turn:")
print_player_status(player)
action = input("Enter your action (move/up/down/left/right/attack): ").lower()
if action == "move":
direction = input("Enter direction (up/down/left/right): ").lower()
player.move(direction)
elif action == "attack":
target = input("Enter player name to attack: ")
for other_player in players:
if other_player.name.lower() == target.lower() and other_player != player:
player.attack_player(other_player)
break
else:
print("Invalid target!")
else:
print("Invalid action!")
# Check for item pickup
for item in items:
if player.position == (item_pos := (random.randint(0, 50), random.randint(0, 50))):
player.add_item(item.name)
items.remove(item)
# Print player status after each round
print("\nPlayer Status:")
for player in players:
print_player_status(player)
print("\n")
print(f"\n{players[0].name} wins the game with a score of {players[0].score}!")
if name == "main":
main()
Closing due to lack of information.
If there's a bug, please provide more information on the bug, etc by filling in the issue template.