Close

25/10/2017

Writing a game in Python Part 2

The biggest headache at first — it’s self when you refer to a function or feature class inside of this class, and the comparison operator == instead of = assignment operator beside the conditional operators. Probably about that, and about other you will forget, so watch out for that. By the way, note the key word and that is used near the forks — it means that you should fulfill both conditions, being with him.

LINES 87-94: finally, at the bottom ends with a description of the class and starts the main logic of the program. We create a sample class Bureaucrat, bureaucrat assigning it to a variable and use the function with a greeting of a bureaucrat. After this, run an infinite loop inside the run function with output and input actions of the player, as well as conditional execution create and welcome a new bureaucrat — depending on what the current value of the bureaucrat.negative. Note two things: the else statement optionally, you cannot use, and in the case of Boolean data types in Python instead of the operator == apply the is keyword.

The first prototype of the LAM-40 ready. Of course, it’s not that far from final, and even from the alpha version, so we have quite a lot of work. Now I see a lot of problems with this prototype that are going to fix next time:

You need to completely change the structure of the code: the text data from the upper part to move to a separate database functions spread to other classes, the main logic program to send in a separate file and so on.

Cannot do without the element of surprise in “battles” with the bureaucrats — otherwise the game will quickly get bored. Probably, it will also help to avoid the wild branches, which are now in the bottom of the code.

The game needs more variety in the phrases, characteristics, actions, and things, and in how it is displayed, to add variety to the narrative.

It is desirable to describe in text all the actions that are possible in the game, including the exit and wait.

Of the possible actions it is advisable to make a list and not a separate string in order that there could be, under certain conditions, to add new actions. In addition, the input to apply the upper () function below is not required every time to enter lowercase letters. It is also necessary to make an adequate response to invalid characters.

The main logic of the game is the recurring two lines that violate the dry rule. And the loop itself is not very beautiful — it might be worth to think over it, when it begins to expand.

A lot of things like the description of the function act(), comments to some parts of the code, use sys.exit() and the characteristics of the negative, which is also not a very elegant solution. So look for an alternative.

As you can see, the work to be complete. I hope next time the game will have a more holistic view. 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. Thanks, and until next time!

Leave a Reply

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