Design document for the text game

In the new issue of blog about programming, I present the first version of the design document LAM-40 and add to the game the possibility of losing function game_over().

Last time we added lam-40 the element of chance. Now for every action in the game is calculated, the probability of its execution, which depends on several parameters. Already two issues I promise to formulate a design document that will constitute the final version of the game, and today finally came time to do it. Also I added in new intermediate version of the game the possibility of losing: the game counts how much time is spent on each action of the player, and if all actions taken by the player to take more than 12 in-game hours, then it happens game_over(), which sometimes happens in the case if you have failed some very risky actions.

Image result for Design document for the text game

NOTE: all code is provided for Python versions 3.0 and older, and therefore may not work on older versions.

The design document is the basis of any game. It describes all that can happen and all goals that are set by the developers. For the background I took a well-known template of a design document and a few changed it.

Don’t forget that this is only the first version of the design document. Usually it changes in the course of development, though slightly, — if he have much to Refine, so the game creators have provided is not all.

Now I hope you more or less know what we want. This time, changes occurred only in the file where is the basic logic of the game. I’ve added the tracking of the current in-game time and made some other edits.

LINE 3: add the datetime module, which is needed for working with date and time. It is particularly convenient in the case when you have to Tinker with time zones, because a bunch of things — but it is, fortunately, not necessary.

LINE 22: assign a variable to the timer element datetime with the specified characteristics. Please note that recording is done on the form as a datetime.datetime() — first we specify the name of the datetime module, the name element is a datetime, and in brackets the desired arguments member. In our case this is the year, month, day, hour, and minute. If you wish, you can continue with second and millisecond. The retrieved element is the starting point from which to start the game. To it will be added to the time periods that will take the implementation of each action.

LINES 29-34: now all the numbers 0 to 10 is added to all actions to be displayed in one row. To do this, the program checks with the help of forks on which loop iteration we are now, and beginning with the 10-th iteration already inserts zeros before the number.

LINES 35-37: add a line displaying the current time using the strftime(), which converts the element datetime in the string data type. For this purpose, the key characters, customizing the display of date and time. Full list of keywords can be found at the bottom of the module documentation.

LINES 40-48, 83-89: in the main logic of the game there is the option evaluate_time(), which checks expired 12 hours in-game or not. To do this, we subtract from the current time on the timer start time. Not to store it in separate variable, I again point out it completely. Since this string becomes too long, I use the symbol \ which indicates to the interpreter that the current and the following lines should merge into one. If the time expires, the game is over — hence, it calls the function game_over(), which follows. If not left, then the next element of the core game logic.

LINES 52-81, 132-134: function timer_add() adds to the variable self.timer the time it took effect. This time is randomly selected from a given period — the more risky the action, the less it takes time (specified in seconds). Note that all figures are highly preliminary — at a late stage of the game still need serious balancing. To add to the self.timer dropped randomly seconds, use the timedelta element included in the datetime module. Timedelta occurs when subtracting one datetime from another element. In fact, it is the difference between two moments in time. In addition to the mandatory self (remember, we are in the Game class), the function timer_add takes an argument seconds_passed — the number of seconds that took the action. It is the number of seconds and added to self.timer. Also note that timedelta requires you to specify the argument through design seconds= — just specify in brackets the number is not enough, POPs up an error. In other words, you should identify a specific unit of time for timedelta.

LINE 143-156: function game_over() leads to the game over screen from which you can either exit the game or restart it. The game checks to see what action the player entering the latter. If one of the four most risky, the game instantly ends in the event of your failure (later, of course, is not so doomed), and the bureaucrat to inform on you to the police. If time has expired, the game tells you this. If desired, you can enter ‘r’ and the game starts again. For this we use function execl() in module current script. More information can be found here.

Image result for Design document for the text game

The program appearance has changed slightly: except that actions are now displayed in one row due to the added zeros, and the timer at the bottom appeared.

The next time the interface waits for the second a radical alteration. First, I want to add some graphic elements (for example, the faces of the bureaucrats that appear using complex emoticons) and gradual withdrawal of the text. Second, the choice of action by entering the letters — not the most comfortable thing. Much better to do it with the arrow keys. Thirdly, the time has come to add to the game random encounters with other unfortunate visitors of the Institution, especially since it technically easy. And if I have time, I will add more and counting the best result to be stored separately even after you’ve finished playing. Not sure I have time to do all this, but I’ll try!

If you do not understand something, write comments under the material and social networks — will be glad and any other feedback. If you are more experienced in programming people than I, with pleasure will listen to substantive criticism. Thank you and until next time!

Leave a Reply

Your email address will not be published. Required fields are marked *