dimanche 3 décembre 2017

Passing milestones in Oregon Trail using "if" statements

I am trying to re-create Oregon Trail in Python. If you haven't played the game, there a milestones throughout your journey to Oregon where you (1.) must stop or (2.) get to choose to stop.

i.e. river crossings you must stop and find a way to cross, and forts where you can choose to stop at the store.

My question is, if they were to travel over the amount of miles necessary, how can I send them back to the milestone by force, and also make sure they don't infinitely get sent back.

To make it more clear, if you just look at the 'if' statement in the first line of code. If they were to, at random, travel 70 miles (the minimum allowed), it would send them straight back to the same milestone and they wouldn't progress.

P.S. If it helps answer the question the next milestone is at 185 miles.

If I did a bad job elaborating just let me know in the comments and I'll try to clarify. Thanks.

if miles_gone >= 102 and miles_gone < 185:
    choice = 0
    while choice == 0:
        print("You were prepared to travel", twoweekmilage,"miles but you arrived at the Kansas River Crossing.")
        choice = int(input("What do you want to do? : (1) Rest (2) Continue"))
        if choice < 1 or choice > 2:
            print("Pick a valid input!")
            choice = 0

        while choice == 1:
            miles_gone = 102
            restdays = random.randrange(1,4)
            print("")
            print("Your group decided to rest for ", restdays, " days.")
            print("")
            for i in range (restdays):
                start_day = (start_day + 1)
                amounttofeed = 0
                if player1.alive == True:
                    amounttofeed = amounttofeed + 1
                if player2.alive == True:
                    amounttofeed = amounttofeed + 1
                if player3.alive == True:
                    amounttofeed = amounttofeed + 1
                if player4.alive == True:
                    amounttofeed = amounttofeed + 1
                if player5.alive == True:
                    amounttofeed = amounttofeed + 1
                food = food - (amounttofeed * eat_rate )
                misfourtunes()
            choice = int(input("Would you like to rest again or continue? (1) Rest (2) Continue "))

        if choice == 2:
            miles_gone = 102
            print("")
            print("You had to take a ferry to cross the river, it costed $5.")
            print("")
            total_money = total_money - 5

Aucun commentaire:

Enregistrer un commentaire