[python-events] I have a game code
Helio Loureiro
helio at loureiro.eng.br
Mon May 20 07:57:54 EDT 2024
Hi Isaiah,
We add events to the PSF calendar. We don't handle code here.
Best Regards,
Helio Loureiro
On Mon, 15 Apr 2024 at 02:09, Isaiah Clark <dfg4vfe at gmail.com> wrote:
> import random
>
> class Player:
> def __init__(self, name):
> self.name = name
> self.health = 100
> self.inventory = []
>
> def take_damage(self, damage):
> self.health -= damage
>
> def collect_item(self, item):
> self.inventory.append(item)
>
> def use_item(self, item):
> if item in self.inventory:
> self.inventory.remove(item)
> print(f"{self.name} used {item}.")
> else:
> print(f"{self.name} doesn't have {item}.")
>
> def generate_random_location():
> return random.randint(1, 10), random.randint(1, 10)
>
> def main():
> num_players = 4
> players = [Player(f"Player {i+1}") for i in range(num_players)]
>
> # Generate random player locations
> for player in players:
> player.x, player.y = generate_random_location()
>
> print("Welcome to PyRoyale!")
> print("You find yourself on a mysterious island. Explore, survive, and
> be the last one standing!")
>
> while len(players) > 1:
> for player in players:
> print(f"{player.name} ({player.health} HP) is at ({player.x},
> {player.y}).")
> action = input("Move (W/A/S/D), collect item (C), or quit (Q):
> ").upper()
>
> if action == "Q":
> print(f"{player.name} has quit the game.")
> players.remove(player)
> continue
>
> if action == "C":
> item = input("Enter an item name to collect: ")
> player.collect_item(item)
> continue
>
> # Simulate movement (for simplicity, assume 10x10 grid)
> dx, dy = 0, 0
> if action == "W":
> dy = -1
> elif action == "S":
> dy = 1
> elif action == "A":
> dx = -1
> elif action == "D":
> dx = 1
>
> player.x += dx
> player.y += dy
>
> # Simulate battles (random chance)
> for player in players:
> if random.random() < 0.2: # 20% chance of encountering
> another player
> opponent = random.choice([p for p in players if p !=
> player])
> print(f"{player.name} encounters {opponent.name}!")
> player.take_damage(random.randint(10, 20))
> opponent.take_damage(random.randint(10, 20))
>
> winner = players[0]
> print(f"\n{winner.name} is the last survivor! Congratulations!")
>
> if __name__ == "__main__":
> main()
>
>
> -
>
> def main():
> print("Welcome to the Text-Based Fortnite Game!")
> print("You find yourself on an island. Your goal is to survive and be the last person standing.")
> print("You can explore, gather resources, and engage in battles with other players.")
>
> player_health = 100
> player_resources = 0
>
> while player_health > 0:
> print("\nOptions:")
> print("1. Explore the island")
> print("2. Gather resources")
> print("3. Engage in a battle")
> print("4. Quit")
>
> choice = input("Enter your choice (1/2/3/4): ")
>
> if choice == "1":
> print("You explore the island and find a hidden cave.")
> print("Inside the cave, you discover a treasure chest!")
> player_resources += 10
> elif choice == "2":
> print("You gather wood, stone, and metal from the surroundings.")
> player_resources += 5
> elif choice == "3":
> print("You encounter another player!")
> enemy_health = 80
> while enemy_health > 0:
> attack = input("Do you want to attack? (yes/no): ")
> if attack.lower() == "yes":
> enemy_health -= 20
> print(f"You hit the enemy! Enemy health: {enemy_health}")
> else:
> print("You decide not to attack.")
> print("You defeated the enemy!")
> elif choice == "4":
> print("You quit the game. Thanks for playing!")
> break
> else:
> print("Invalid choice. Please select a valid option.")
>
> print("Game over. You survived!")
> if __name__ == "__main__":
> main()
>
> AI-generated code. Review and use carefully. More info on FAQ
> <https://www.bing.com/new#faq>.
>
> Feel free to modify and expand upon this basic framework to create
> your own Fortnite-inspired game. If you have any other requests or
> questions, feel free to ask! 😊
> 2of5
> Show learn more suggestions
> - Can you add more features to the game?
> - How about adding a crafting system?
> - I'd like to see an inventory management feature.
>
>
> _______________________________________________
> python-events mailing list
> python-events at python.org
> https://mail.python.org/mailman/listinfo/python-events
>
> Calendar wiki page: https://wiki.python.org/moin/PythonEventsCalendar
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-events/attachments/20240520/be4ee986/attachment-0001.html>
More information about the python-events
mailing list