Permalink
Browse files

AdventureSample - extract constants into VerbResult class

  • Loading branch information...
bobbymcr committed May 12, 2018
1 parent e17ec6e commit 09af825a3c8f6b720be8760e2f46dd163c2d2f02
Showing with 19 additions and 11 deletions.
  1. +19 −11 projects/AdventureSample/src/Adventure/adventure.cs
@@ -43,7 +43,7 @@ public adventure(TextReader input, TextWriter output)
public void Run()
{
while ((this.Main()) == (1))
while (this.Main() == VerbResult.RestartGame)
{
}
}
@@ -616,7 +616,7 @@ private int HandleVerb()
{
if (Go())
{
return 0;
return VerbResult.Proceed;
}
}
else if ((verb == "GET") || (verb == "TAK"))
@@ -638,7 +638,7 @@ private int HandleVerb()
{
if (Look())
{
return 0;
return VerbResult.Proceed;
}
}
else if (verb == "EXA")
@@ -648,7 +648,7 @@ private int HandleVerb()
else if (verb == "QUI")
{
int q = Quit();
if (q != 0)
if (q != VerbResult.Proceed)
{
return q;
}
@@ -665,7 +665,7 @@ private int HandleVerb()
{
if (Pour())
{
return 0;
return VerbResult.Proceed;
}
}
else if (verb == "CLI")
@@ -676,7 +676,7 @@ private int HandleVerb()
{
if (Jump())
{
return 0;
return VerbResult.Proceed;
}
}
else if (verb == "DIG")
@@ -695,7 +695,7 @@ private int HandleVerb()
{
if (Leave())
{
return 0;
return VerbResult.Proceed;
}
}
else if (verb == "FIG")
@@ -711,7 +711,7 @@ private int HandleVerb()
PRINT(("") + ("I DON'T KNOW HOW TO DO THAT"));
}
return -1;
return VerbResult.Idle;
}
private void Parser()
@@ -979,7 +979,7 @@ private int Quit()
return PlayAgain();
}
return 0;
return VerbResult.Proceed;
}
private int PlayAgain()
@@ -990,12 +990,12 @@ private int PlayAgain()
string quit = INPUT_s("");
if (quit == "Y")
{
return 1;
return VerbResult.RestartGame;
}
if (quit == "N")
{
return 2;
return VerbResult.EndGame;
}
}
}
@@ -1370,4 +1370,12 @@ private void Wear()
wearingGloves = 1;
}
}
private static class VerbResult
{
public const int Idle = -1;
public const int Proceed = 0;
public const int RestartGame = 1;
public const int EndGame = 2;
}
}

0 comments on commit 09af825

Please sign in to comment.