patternpythonMinor
Simple text adventure game
Viewed 0 times
textsimpleadventuregame
Problem
I've decided to make a text adventure game but I feel that the code I have now is annoying, and as I get farther, it will make it hard to read. Is this a correct assumption? Please tell me what I'm doing wrong so I can improve on my techniques with coding.
```
#VARIABLES======================================================================================================================================
else_statement = "How hard is it to press 1..."
introduction = "Introduction:\n\n""The year is 567 C.E. You and your family live in Czarne, Pomerania. There has been a major population shift to your region as viking raids terrorize the people along the shore. Because of this massive population shift, tensions are high between the populas. There are constant fights in the street because the local militia isn't plentiful enough to pacify the fights. The viking raiders exhausted the coatal villages. To keep funding their raids, they must go inland to the village of Czarne..."
introduction_1 = "You, your wife, and your kids are having dinner in your small home. Your wife prepared a heavenly soup and chicken. After dinner you put your kids to bed and you fell asleep. You are awaken by screams outside your house. Your wife and kids were already awake and were huddled up close to you. You sit up and say 'it's just another fight'. Then a man weilding an axe bursts through the door. He starts to charge for your family. You charge and tackle the man. Several punches are thrown but you managed to choke the man out. You then realized that this is no ordinary man... he is a viking. After learning of this news, you gathered your family and left through the back door."
introduction_2 = "You gather your family and leave through the back door. When you stepped outside, you were greeted with horror. Houses being burned down, people being slain, livestock being taken. You were seeing your life crumble with your own eyes. 'We need to make it to the town hall' you say. Your family is spe
```
#VARIABLES======================================================================================================================================
else_statement = "How hard is it to press 1..."
introduction = "Introduction:\n\n""The year is 567 C.E. You and your family live in Czarne, Pomerania. There has been a major population shift to your region as viking raids terrorize the people along the shore. Because of this massive population shift, tensions are high between the populas. There are constant fights in the street because the local militia isn't plentiful enough to pacify the fights. The viking raiders exhausted the coatal villages. To keep funding their raids, they must go inland to the village of Czarne..."
introduction_1 = "You, your wife, and your kids are having dinner in your small home. Your wife prepared a heavenly soup and chicken. After dinner you put your kids to bed and you fell asleep. You are awaken by screams outside your house. Your wife and kids were already awake and were huddled up close to you. You sit up and say 'it's just another fight'. Then a man weilding an axe bursts through the door. He starts to charge for your family. You charge and tackle the man. Several punches are thrown but you managed to choke the man out. You then realized that this is no ordinary man... he is a viking. After learning of this news, you gathered your family and left through the back door."
introduction_2 = "You gather your family and leave through the back door. When you stepped outside, you were greeted with horror. Houses being burned down, people being slain, livestock being taken. You were seeing your life crumble with your own eyes. 'We need to make it to the town hall' you say. Your family is spe
Solution
Thoughts:
https://en.wikipedia.org/wiki/Choose_Your_Own_Adventure
-
Keep the text for each choice/page in a separate file, no need to clutter up your code. Perhaps even name the files page1.txt, page2.txt, etc.
-
Instead of having the logic of which page can lead to which pages, include that logic in the text files themselves. That way, your adventure can get longer without your code getting longer. Of course, preprocess the "this page leads to pages x/y/z" before printing them for the end user.
- You're effectively creating Choose Your Own Adventure(tm) books:
https://en.wikipedia.org/wiki/Choose_Your_Own_Adventure
-
Keep the text for each choice/page in a separate file, no need to clutter up your code. Perhaps even name the files page1.txt, page2.txt, etc.
-
Instead of having the logic of which page can lead to which pages, include that logic in the text files themselves. That way, your adventure can get longer without your code getting longer. Of course, preprocess the "this page leads to pages x/y/z" before printing them for the end user.
Context
StackExchange Code Review Q#123041, answer score: 3
Revisions (0)
No revisions yet.