import sys
import random
from PyQt6.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QLabel, QPushButton, QLineEdit,
    QMessageBox, QTextEdit
)
from PyQt6.QtCore import Qt

class Character:
    def __init__(self, name):
        self.name = name
        self.health = 100
        self.food = 100
        self.alive = True

    def __str__(self):
        return f"{self.name}: Health = {self.health}, Food = {self.food}, Alive = {self.alive}"

class OregonTrailGame:
    def __init__(self):
        self.distance_to_travel = 200  # Total distance in miles
        self.distance_traveled = 0
        self.days_passed = 0
        self.characters = []
        self.events = [
            "found food",
            "lost food",
            "health issues",
            "nothing happens",
            "disease outbreak",
            "friendly encounter"
        ]

    def setup_characters(self, names):
        self.characters = [Character(name) for name in names]

    def travel(self):
        if all(not character.alive for character in self.characters):
            return "All characters have perished. Game over."

        travel_distance = random.randint(10, 30)
        self.distance_traveled += travel_distance
        self.days_passed += 1

        for character in self.characters:
            character.food -= travel_distance // 2
            if character.food <= 0:
                character.health -= 10
                if character.health <= 0:
                    character.alive = False

        event_message = self.trigger_event()
        if self.distance_traveled >= self.distance_to_travel:
            return "Congratulations! You've reached your destination!"
        
        return event_message

    def trigger_event(self):
        event = random.choice(self.events)
        if event == "found food":
            food_found = random.randint(10, 30)
            for character in self.characters:
                character.food += food_found // len(self.characters)
            return f"You found {food_found} units of food!"
        elif event == "lost food":
            food_lost = random.randint(10, 20)
            for character in self.characters:
                character.food -= food_lost // len(self.characters)
            return f"You lost {food_lost} units of food!"
        elif event == "health issues":
            for character in self.characters:
                health_loss = random.randint(5, 15)
                character.health -= health_loss
            return "Some characters suffered health issues!"
        elif event == "disease outbreak":
            for character in self.characters:
                health_loss = random.randint(10, 30)
                character.health -= health_loss
            return "A disease outbreak has affected your party!"
        elif event == "friendly encounter":
            for character in self.characters:
                character.food += 10
            return "You encountered a friendly traveler who shares supplies!"

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Oregon Trail Game")
        self.setGeometry(100, 100, 600, 400)

        # Set up layout and widgets
        self.layout = QVBoxLayout()
        
        self.intro_label = QLabel("Welcome to the Oregon Trail Game!")
        self.intro_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.layout.addWidget(self.intro_label)

        self.character_input = QLineEdit(self)
        self.character_input.setPlaceholderText("Enter character names (comma separated)")
        self.layout.addWidget(self.character_input)

        self.setup_button = QPushButton("Setup Characters", self)
        self.setup_button.clicked.connect(self.setup_characters)
        self.layout.addWidget(self.setup_button)

        self.travel_button = QPushButton("Travel", self)
        self.travel_button.clicked.connect(self.travel)
        self.travel_button.setEnabled(False)  # Disabled until characters are set
        self.layout.addWidget(self.travel_button)

        self.status_display = QTextEdit(self)
        self.status_display.setReadOnly(True)
        self.layout.addWidget(self.status_display)

        self.setLayout(self.layout)
        self.setStyleSheet("""
            QWidget {
                background-color: #2e2e2e;
                color: white;
                font-size: 16px;
            }
            QLineEdit, QPushButton {
                background-color: #444444;
                color: white;
                padding: 10px;
            }
            QPushButton:hover {
                background-color: #666666;
            }
        """)

        self.game = OregonTrailGame()

    def setup_characters(self):
        names = [name.strip() for name in self.character_input.text().split(',')]
        self.game.setup_characters(names)
        self.status_display.append("Characters have been set up:")
        for character in self.game.characters:
            self.status_display.append(str(character))
        self.travel_button.setEnabled(True)

    def travel(self):
        message = self.game.travel()
        self.status_display.append(message)
        for character in self.game.characters:
            if not character.alive:
                self.status_display.append(f"{character.name} has died.")

        if all(not character.alive for character in self.game.characters):
            QMessageBox.information(self, "Game Over", "All characters have perished. Game over.")
            self.close()

        if self.game.distance_traveled >= self.game.distance_to_travel:
            QMessageBox.information(self, "Congratulations!", "You've reached your destination!")
            self.close()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())


make this as advanced as real game