"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Simple Command Line Dungeons and Dragons

Simple Command Line Dungeons and Dragons

Published on 2024-11-07
Browse:819

Simple Command Line Dungeons and Dragons

As a participant in a Coding Nomads bootcamp, one of the early projects in the Python course is a simple Dungeon and Dragons command line game. The objective: find a sword and slay a dragon. The command line game is driven by user input (responding to presented binary choices; e.g., yes / no, fight / safety). In addition to user input, flag variables are essential in the code to both keep track of where the player is located in the game (i.e., player_pos = "c" ("c" = corridor; "l" = left (empty) room; "r" = right (dragon) room), whether the player has the sword, and finally, whether the dragon is alive. The sword is initially hidden in the empty room on the left, and is tracked via the flag "has_sword." Initially set to "False", when the sword is looked for and found, the flag switches to "True". The status of the dragon is tracked via the Boolean flag variable, "dragon_dead = False". In addition to tracking the dragon's status, this Boolean flag also keeps the player within a while loop where the player can move between the corridor, the left room, and the right room. In order to claim victory in this game, the player must find and take the sword, then enter the dragon's lair, and chose to fight it. Alternatively, if the player choses to fight the dragon without the sword, they will meet their demise in the command line game. Once the dragon_dead Boolean flag variable flips to "True", the code exits from the while loop, and the player can claim victory.

Again, this was an early in my Python learning, but the project emphasized the utility that flag variables offer in coding. Additionally, to get the script to operate fluidly, nested loops had to be constructed and carefully place to ensure the player could not backtrack and repeat previous actions they already took.

Release Statement This article is reproduced at: https://dev.to/drn19/simple-command-line-dungeons-and-dragons-59gj?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3