I have been playing story based games such as lifeline or choice of games. I was wondering what game loop best describes what's happening logically? As when mauling over it myself in my head I am trying to come up with the patterns for developing something similar and I keep hitting a brick wall. Essentially allowing for choices. Text. Variables and conditions. Some text can even be re-used with additions to condition blocks.
-
\$\begingroup\$ The story game loop would be like any other game loop. \$\endgroup\$– JPtheK9Jun 26, 2015 at 1:05
-
2\$\begingroup\$ You can think of it as finite state machine \$\endgroup\$– Ali1S232Jun 26, 2015 at 1:25
-
\$\begingroup\$ You may find this video from this year's GDC interesting: gdcvault.com/play/1021774/Adventures-in-Text-Innovating-in \$\endgroup\$– DMGregory ♦Jun 26, 2015 at 3:13
-
\$\begingroup\$ I gave an answer at a similar question : gamedev.stackexchange.com/questions/101529/… \$\endgroup\$– dnk drone.vs.dronesJun 26, 2015 at 6:31
-
\$\begingroup\$ possible duplicate of How can I implement dialog trees into my game? \$\endgroup\$– Seth BattinJun 26, 2015 at 16:20
3 Answers
This is a super broad question. I have no idea what you want to do with the game, the only thing I can say is everything needs to be contained within a while 1 infinite loop. There's not a lot of advice to give besides that. Just don't think about it too much, actually go start programming the game and you will realize what you need as you go. I mean it's pretty clear where you will need certain loops and stuff so just start working on that.
Try starting your code off with just something like
string userInput = "";
bool quit = false;
while(!quit)
{
Console.WriteLine("Hello, press a key to start your quest or type no to quit");
userInput = Console.ReadLine().ToString();
if(userInput.ToUpper() == "NO")
{
quit = true;
}
else
{
Console.WriteLine("Alright, moving on to the quest then!");
}
}
obviously this would create an infinite loop if you hit a key I'm just trying to give you the general idea.
My partial solution to your "brick wall" is... a Node. Lots of nodes.
Something along the line of....
First node(Head node):
NodeID:1
Message:"You see a path on the left leading to a gloomy forest. You could taste the hint of the sea from the wind blowing from the right.
Options:
-Option:
Title:"Go Left"
TargetNodeID:2
-Option:
Title:Go Right"
TargetNodeID:3
after the above, develop the game loop to run based on the nodes you've created.
The actual game loop could be event based, where you press a button to load next page with little to no animation running.
Or the usual while(true) loop.
Hope it softens the "brick wall" and hope it's the correct "brick wall" we're talking about.
Make methods that seals each of the stages you have(possibly make them into a class), and a infinite loop is will be running on the Start() function along with your storyline.
Your Story class
public void stage_1()
{
int choice = 0;
//Do something at your stage
if(choice == 1)
stage_2();
else if(choice == 2)
stage_4();
else
//Something went wrong
//By default use the first choice
stage_2();
}
public void stage_2()
{
int choice = 0;
//Do something at your stage
if(choice == 1)
stage_3();
else if(choice == 2)
stage_4();
else
//Something went wrong
//By default use the first choice
stage_3();
}
public void stage_3() { //Do something at your stage }
public void stage_4() { //Do something at your stage }
//etc.
public void stage_final()
{
//Same procedures as above
MessageShow("Do you want to start again at the beginning?");
if(choice == 1)
stage_1();
else
end();
}
Your running script
void Start()
{
stage_1();
}