Search⌘ K
AI Features

الحل: أضف طبقات إلى مغامرتك

سنغطي ما يلي...

هذا البرنامج عبارة عن لعبة بسيطة يمكنك من خلالها اختيار مغامرتك الخاصة، حيث تحدد اختياراتك ما سيحدث بعد ذلك.

كيف يعمل:

  • def jungle_adventure(): يعرف وظيفة تحتوي على اللعبة بأكملها.

  • يختار اللاعب المسار أولاً:"river" ،"mountain" ، أو"jungle" .

  • اعتمادًا على الاختيار، تقوم اللعبة بتشغيل كتلة مختلفة من التعليمات البرمجية باستخدامif ،elif ، وelse .

  • تتضمن بعض المسارات (مثل النهر والجبل) قرارًا ثانيًا، حيث يختار اللاعب ما يجب فعله بعد ذلك - ولكل اختيار نتيجته الخاصة المطبوعةprint() .

  • إذا كتب اللاعب شيئًا غير متوقع، تعرض اللعبة رسالة افتراضية باستخدامelse جزء.

def jungle_adventure():
    # First decision: Choose between three paths
    path = input("You find three paths: river, mountain, or jungle. Where do you go? ")

    if path == "river":
        # Second decision with three possible actions
        action = input("At the river, do you swim, build a raft, or follow the shore? ")
        if action == "swim":
            print("You swim with dolphins!")
        elif action == "build a raft":
            print("You float downstream to a hidden village!")
        elif action == "follow the shore":
            print("You find a boat tied to a tree and sail away!")
        else:
            print("You wait too long and it gets dark.")

    elif path == "mountain":
        # Second decision with three possible outcomes
        action = input("At the mountain, do you explore a cave, enjoy the view, or set up camp? ")
        if action == "explore a cave":
            print("You find glowing crystals and ancient symbols!")
        elif action == "enjoy the view":
            print("You spot a distant city — your next quest!")
        elif action == "set up camp":
            print("You build a cozy fire and rest under the stars.")
        else:
            print("You get cold and decide to head back.")

    elif path == "jungle":
        print("You get tangled in vines and meet a group of talking monkeys!")

    else:
        print("You wander in circles and end up where you started.")

jungle_adventure()
Introducing the idea of nested decisions for more story complexity