1. Blackbox IDEToggle Sidebar
  2.  
  3.  
  4. Share
  5.  
  6. Creat a gun game for me
  7.  
  8. Copy message
  9. Edit message
  10.  
  11.  
  12. Thought for a moment
  13. Below is a simple text-based "gun game" I created for you in Python. It's a basic shooter game where you aim and fire at targets to score points. You can run this code in any Python environment (like IDLE or an online interpreter). It uses random elements for realism and fun.
  14.  
  15. Game Description
  16. Objective: Shoot targets to earn points. Miss too many times, and you lose.
  17. Mechanics: You input an angle (0-90 degrees) and power (1-10) to aim. The game calculates if you hit based on random factors.
  18. Winning: Reach 100 points or more.
  19. Losing: Miss 5 shots in a row.
  20. Python Code
  21. python
  22.  
  23. Copy code
  24. import random
  25.  
  26. def gun_game():
  27. print("Welcome to the Gun Game!")
  28. print("Aim your shot: Enter an angle (0-90 degrees) and power (1-10).")
  29. print("Hit targets to score points. Reach 100 points to win!")
  30. print("Miss 5 times in a row, and it's game over.\n")
  31.  
  32. score = 0
  33. misses = 0
  34. targets = ["Easy Target", "Moving Target", "Distant Target", "Armored Target"]
  35.  
  36. while score < 100 and misses < 5:
  37. target = random.choice(targets)
  38. print(f"Target: {target}")
  39.  
  40. try:
  41. angle = float(input("Enter angle (0-90): "))
  42. power = int(input("Enter power (1-10): "))
  43.  
  44. if not (0 <= angle <= 90) or not (1 <= power <= 10):
  45. print("Invalid input! Try again.\n")
  46. continue
  47.  
  48. # Simulate shot accuracy with randomness
  49. hit_chance = random.uniform(0, 1)
  50. required_accuracy = (angle / 90) * (power / 10) * 0.8 # Simplified physics
  51.  
  52. if hit_chance < required_accuracy:
  53. points = random.randint(10, 50)
  54. score += points
  55. misses = 0
  56. print(f"Hit! +{points} points. Total score: {score}\n")
  57. else:
  58. misses += 1
  59. print(f"Miss! Misses in a row: {misses}\n")
  60.  
  61. except ValueError:
  62. print("Invalid input! Enter numbers only.\n")
  63.  
  64. if score >= 100:
  65. print("Congratulations! You won with a score of", score)
  66. else:
  67. print("Game over! You missed too many shots. Final score:", score)
  68.  
  69. # Run the game
  70. gun_game()