Camel Code Review

Here are examples of the “Camel” game. Our goal here is to do code reviews on this code.

Before the code review, think about:

  1. First, list what are the goals of the code review.

  2. Look for common mistakes. Keep a to-do list.

    1. Can a person drink more water than is in the canteen?

    2. Do we mis-calculate how far back the people are?

    3. Can the chasing people skip past the person and miss seeing them?

    4. Can we both win and lose the game at the same time? Or otherwise get conflicting messages?

  3. Quantify effectiveness of your code review. (Bugs found, changes made, etc.)

  4. Code reviews often include work on unit-tests. We aren’t doing that here but keep it in mind.

  5. Code reviews should be less than 400 lines and 60 minutes.

Camel Version 1

  1using System;
  2
  3namespace CamelGame
  4{
  5	class Program
  6	{
  7		private static void Choices()
  8		{
  9			Console.WriteLine(" ");
 10			Console.WriteLine("A. Drink from your canteen.");
 11			Console.WriteLine("B. Ahead moderate speed.");
 12			Console.WriteLine("C. Ahead full speed.");
 13			Console.WriteLine("D. Stop and rest.");
 14			Console.WriteLine("E. Status check.");
 15			Console.WriteLine("Q. Quit.");
 16			Console.WriteLine(" ");
 17		}
 18		private static void DistanceTraveled(int camelMovement)
 19		{
 20			Console.WriteLine(" ");
 21			Console.WriteLine("You traveled " + camelMovement + " miles.");
 22		}
 23		private static void ChoiceA(ref int thirst, ref int drinks)
 24		{
 25			if (drinks > 0)
 26			{
 27				drinks -= 1;
 28				thirst = 0;
 29			}
 30			else Console.WriteLine("You are out of water.");
 31		}
 32		private static void ChoiceB(ref int milesTraveled, ref int thirst, ref int camelTiredness, ref int drinks, ref int nativeDistance, Random random)
 33		{
 34			int camelMovement = random.Next(5, 12);
 35			int nativeMovement = random.Next(7, 14);
 36			milesTraveled += camelMovement;
 37			thirst += 1;
 38			camelTiredness += 1;
 39			nativeDistance += nativeMovement;
 40			int oasisFound = random.Next(1, 20);
 41			if (oasisFound == 1)
 42			{
 43				Oasis(out thirst, out camelTiredness, out drinks);
 44			}
 45			DistanceTraveled(camelMovement);
 46		}
 47		private static void ChoiceC(ref int milesTraveled, ref int thirst, ref int camelTiredness, ref int drinks, ref int nativeDistance, Random random)
 48		{
 49			int camelMovement = random.Next(10, 20);
 50			int nativeMovement = random.Next(7, 14);
 51			int addTiredness = random.Next(1, 3);
 52			milesTraveled += camelMovement;
 53			thirst += 1;
 54			camelTiredness += addTiredness;
 55			nativeDistance += nativeMovement;
 56			int oasisFound = random.Next(1, 20);
 57			if (oasisFound == 1)
 58			{
 59				Oasis(out thirst, out camelTiredness, out drinks);
 60			}
 61			DistanceTraveled(camelMovement);
 62		}
 63		private static void ChoiceD(ref int nativeDistance, ref int camelTiredness, Random random)
 64		{
 65			Console.WriteLine("The Camel is happy");
 66			int nativeMovement = random.Next(7, 14);
 67			nativeDistance += nativeMovement;
 68			camelTiredness = 0;
 69		}
 70		private static void ChoiceE(int milesTraveled, int drinks, int nativeDistance)
 71		{
 72			Console.WriteLine("Miles traveled: " + milesTraveled);
 73			Console.WriteLine("Drinks in canteen: " + drinks);
 74			Console.WriteLine("The natives are " + (milesTraveled - nativeDistance) + " miles behind you.");
 75		}
 76		private static void Oasis(out int thirst, out int camelTiredness, out int drinks)
 77		{
 78			Console.WriteLine("You found an oasis!");
 79			Console.WriteLine("The camel is rested and your thirst and canteen are replenished.");
 80			thirst = 0;
 81			drinks = 3;
 82			camelTiredness = 0;
 83		}
 84		static void Main(string[] args)
 85		{
 86			int milesTraveled = 0;
 87			int thirst = 0;
 88			int camelTiredness = 0;
 89			int drinks = 3;
 90			int nativeDistance = -20;
 91			string choice;
 92			string playAgain;
 93			bool done = false;
 94			Random random = new Random();
 95
 96			Console.WriteLine("Welcome to Camel!");
 97			Console.WriteLine("You have stolen a camel to make your way across the great Mobi desert.");
 98			Console.WriteLine("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.");
 99
100			while (!done)
101			{
102				Choices();
103				Console.Write("Enter Choice: ");
104				choice = Console.ReadLine();
105				if (string.Equals("Q", choice.ToUpper()))
106				{
107					done = true;
108				}
109
110				else if (string.Equals("A", choice.ToUpper()))
111				{
112					ChoiceA(ref thirst, ref drinks);
113				}
114
115				else if (string.Equals("B", choice.ToUpper()))
116				{
117					ChoiceB(ref milesTraveled, ref thirst, ref camelTiredness, ref drinks, ref nativeDistance, random);
118				}
119
120				else if (string.Equals("C", choice.ToUpper()))
121				{
122					ChoiceC(ref milesTraveled, ref thirst, ref camelTiredness, ref drinks, ref nativeDistance, random);
123				}
124
125				else if (string.Equals("D", choice.ToUpper()))
126				{
127					ChoiceD(ref nativeDistance, ref camelTiredness, random);
128				}
129
130				else if (string.Equals("E", choice.ToUpper()))
131				{
132					ChoiceE(milesTraveled, drinks, nativeDistance);
133				}
134
135				if (thirst > 6)
136				{
137					Console.WriteLine("You died of thirst.");
138					done = true;
139				}
140
141				else if (thirst > 4)
142				{
143					Console.WriteLine("You are thirsty.");
144				}
145
146				if (camelTiredness > 8 & !done)
147				{
148					Console.WriteLine("Your camel is dead.");
149					done = true;
150				}
151
152				else if (camelTiredness > 5)
153				{
154					Console.WriteLine("Your camel is getting tired.");
155				}
156
157				if (milesTraveled - nativeDistance <= 0 & !done)
158				{
159					Console.WriteLine("The natives caught you!");
160					done = true;
161				}
162
163				else if (milesTraveled - nativeDistance <= 15)
164				{
165					Console.WriteLine("The natives are getting close!");
166				}
167
168				if (milesTraveled >= 200 & !done)
169				{
170					Console.WriteLine("You escaped the natives!");
171					done = true;
172				}
173
174				if (done)
175				{
176					Console.Write("Play Again? (Y/N) ");
177					playAgain = Console.ReadLine();
178					if (string.Equals("Y", playAgain.ToUpper()))
179					{
180						done = false;
181					}
182					else if (string.Equals("N", playAgain.ToUpper()))
183					{
184						Console.WriteLine("Thanks for playing!");
185					}
186				}
187			}
188		}
189	}
190}

Camel Version 2

  1using System;
  2using System.Collections;
  3using System.Collections.Generic;
  4
  5namespace Camel
  6{
  7    class Program
  8    {
  9        // Initialize variables for use throughout the entire program
 10        static int playerPosition;
 11        static int hadesPosition;
 12        static int gameLength;
 13        static bool done;
 14        static int energy;
 15        static int maxEnergy = 20;
 16        static int drachmas;
 17        static int maxShops = 4;
 18        static int hadesMovement;
 19        static int turnCounter;
 20        static int positionDifference;
 21        static string distanceStatement;
 22        static string energyStatement;
 23        static int[] shops;
 24        static int movementModifier;
 25        static int hadesMovementModifier;
 26        static Dictionary<string, int> shopItems;
 27        static int speedBoostTurns;
 28        static int maxSpeedBoost = 5;
 29        static int roadBlockTurns;
 30        static int maxRoadBlock = 5;
 31        static bool purchaseMade;
 32        static bool moved;
 33        static bool exitShop;
 34        static string lineBreak = "-------------------------------------------------------------------------------------";
 35
 36        static void Main(string[] args)
 37        {
 38            // ----------------------------------------- SETUP FUNCTIONS FOR GAME USE -----------------------------------------
 39            void InitializeGame()
 40            {
 41                // Initialize game variables and general setup.
 42                hadesPosition = 0;
 43                // Set player position relative to Hades at the beginning of the game.
 44                playerPosition = SetPlayerPosition(hadesPosition);
 45                // Randomize the length that the player must travel.
 46                SetGameLength();
 47                // Get our list of shop locations.
 48                shops = DisperseShops();
 49                energy = maxEnergy;
 50                turnCounter = 0;
 51                // This is used to keep our game running until the player wins or is caught by Hades.
 52                done = false;
 53                hadesMovementModifier = 0;
 54                movementModifier = 0;
 55                shopItems = new Dictionary<string, int>();
 56                InitializeShop();
 57
 58                string gameStartTutorial;
 59                gameStartTutorial = "You are in ancient Greece and have just completed an undercover recon mission for Zeus. Hades has discovered " +
 60                    "what you have done and is now chasing you while you make your way back to Olympus! Get back to Olympus before Hades makes you pay " +
 61                    "the price!";
 62
 63                Console.WriteLine(gameStartTutorial);
 64                Console.WriteLine(lineBreak);
 65            }
 66
 67            // This function will set the Game's length every time it is started up.
 68            int SetGameLength()
 69            {
 70                gameLength = RandomNumber(45, 60);
 71                return gameLength;
 72            }
 73
 74            // Function for generating random numbers within the game.
 75            int RandomNumber(int min, int max)
 76            {
 77                Random random = new Random();
 78                return random.Next(min, max);
 79            }
 80
 81            // This function sets the players initial starting position with respect to the enemy's position.
 82            int SetPlayerPosition(int hadesLocation)
 83            {
 84                int playerLocation;
 85                playerLocation = hadesLocation + RandomNumber(1, 6);
 86                return playerLocation;
 87            }
 88
 89            int SetHadesPosition()
 90            {
 91                hadesMovement = RandomNumber(2, 5);
 92                if (hadesMovement - hadesMovementModifier < 0)
 93                {
 94                    hadesMovement = 0;
 95                }
 96                else
 97                {
 98                    hadesMovement = hadesMovement - hadesMovementModifier;
 99                }
100                hadesPosition += hadesMovement;
101                return hadesPosition;
102            }
103
104            int[] DisperseShops()
105            {
106                int previousShop;
107                int interval;
108                int[] shopLocations = new int[maxShops];
109
110                previousShop = 0;
111
112                for (int i = 0; i < maxShops; i++)
113                {
114                    interval = RandomNumber(4, 10);
115                    if (previousShop + 4 < gameLength && (previousShop + interval) < gameLength)
116                    {
117                        shopLocations[i] = previousShop + interval;
118                        previousShop = shopLocations[i];
119                    }
120                }
121
122                return shopLocations;
123            }
124
125            string GetEnergyStatement(int energy)
126            {
127                if (energy <= 3)
128                {
129                    return "You are exhausted...";
130                }
131                else if (energy > 3 && energy <= 10)
132                {
133                    return "You are starting to get tired...";
134                }
135                else if (energy > 10 && energy <= 15)
136                {
137                    return "You still feel moderately energetic.";
138                }
139                else
140                {
141                    return "You are pulsing with energy!";
142                }
143            }
144
145            void CheckForAncientRuins()
146            {
147                int random;
148                int drachmasGained;
149                random = RandomNumber(0, 26);
150                drachmasGained = RandomNumber(5, 15);
151                if (random == 12)
152                {
153                    Console.WriteLine("You have stumbled upon some ancient ruins. You have found " + drachmasGained + " drachmas and your energy has been restored!");
154                    drachmas += drachmasGained;
155                    energy = maxEnergy;
156                }
157            }
158
159            void Purchase(string itemName, int price)
160            {
161                string shopStatement = "";
162
163                if (itemName.Equals("Energy Drink") && drachmas >= price)
164                {
165                    energy = maxEnergy;
166                    shopStatement = "Your energy has been replenished!";
167                    shopItems.Remove("Energy Drink");
168                    drachmas -= price;
169                    purchaseMade = true;
170                }
171                else if (itemName.Equals("Speed Boost") && drachmas >= price)
172                {
173                    movementModifier = RandomNumber(2, 4);
174                    speedBoostTurns = maxSpeedBoost;
175
176                    shopStatement = "Your movement speed has been boosted by " + movementModifier +
177                        " for " + speedBoostTurns + " turns!";
178                    shopItems.Remove("Speed Boost");
179                    drachmas -= price;
180                    purchaseMade = true;
181                }
182                else if (itemName.Equals("Road Block") && drachmas >= price)
183                {
184                    hadesMovementModifier = RandomNumber(1, 3);
185                    roadBlockTurns = maxRoadBlock;
186                    shopStatement = "You have injured Hades and have restricted his movement by " +
187                        hadesMovementModifier + " for " + roadBlockTurns + " turns!";
188                    shopItems.Remove("Road Block");
189                    drachmas -= price;
190                    purchaseMade = true;
191                }
192                else if (drachmas < price)
193                {
194                    Console.WriteLine("You cannot afford that!");
195                    purchaseMade = false;
196                }
197                else
198                {
199                    Console.WriteLine("You have decided to leave.");
200                    exitShop = true;
201                }
202                if (purchaseMade)
203                {
204                    Console.WriteLine("You have purchased one " + itemName);
205                    Console.WriteLine(shopStatement);
206                }
207            }
208
209            void OpenShop()
210            {
211                string shopStatement = "You have stumbled upon a traveling merchant!";
212                int i = 1;
213                Console.WriteLine(shopStatement);
214                Dictionary<int, string> itemList = new Dictionary<int, string>();
215
216                foreach (KeyValuePair<string, int> item in shopItems)
217                {
218                    string displayItem = i + ". " + item.Key + " -------- " + item.Value;
219                    Console.WriteLine(displayItem);
220                    itemList.Add(i, item.Key);
221                    i += 1;
222                }
223
224                string leave = i + ". Leave";
225                itemList.Add(i, "Leave");
226                string playerDrachmas = "Your current held drachmas: " + drachmas;
227                string buy = "Would you like to make a purchase?";
228                Console.WriteLine(leave);
229                Console.WriteLine(playerDrachmas);
230                Console.WriteLine(buy);
231
232                purchaseMade = false;
233                exitShop = false;
234
235                while (!purchaseMade && !exitShop)
236                {
237                    string userInput = Console.ReadLine();
238
239                    try
240                    {
241                        string itemName;
242                        int price;
243
244                        itemList.TryGetValue(Convert.ToInt32(userInput), out itemName);
245                        shopItems.TryGetValue(itemName, out price);
246                        Purchase(itemName, price);
247                        exitShop = true;
248                    }
249                    catch
250                    {
251                        Console.WriteLine("Please enter a valid number.");
252                    }
253                }
254            }
255
256            void InitializeShop()
257            {
258                shopItems.Add("Energy Drink", 10);
259                shopItems.Add("Speed Boost", 25);
260                shopItems.Add("Road Block", 15);
261            }
262
263            void IncrementItemDuration()
264            {
265                if (speedBoostTurns > 0)
266                {
267                    speedBoostTurns -= 1;
268                }
269                if (roadBlockTurns > 0)
270                {
271                    roadBlockTurns -= 1;
272                }
273            }
274
275            void GetUserDecision()
276            {
277                string slow;
278                string medium;
279                string fast;
280                string rest;
281                string input;
282                string status;
283                string quit;
284                bool decided;
285                int drachmasGained = 0;
286
287                decided = false;
288
289                slow = "1. Slow and Steady...";
290                medium = "2. Keep a moderate pace.";
291                fast = "3. Full steam ahead!!!";
292                rest = "4. Stop and take a rest...";
293                status = "5. Journey Status.";
294                quit = "6. Quit Game.";
295
296                if (positionDifference >= 10)
297                {
298                    Console.WriteLine("Hades is very far away...");
299                }
300                else if (positionDifference >= 6)
301                {
302                    Console.WriteLine("Hades is getting closer.");
303                }
304                else
305                {
306                    Console.WriteLine("Hades is right on your tail!!!");
307                }
308                Console.WriteLine();
309                Console.WriteLine(slow + "\n" + medium + "\n" + fast + "\n" + rest + "\n" + status + "\n" + quit);
310                Console.WriteLine("What would you like to do?");
311
312                while (!decided)
313                {
314                    // Get user input and set up if statements to evaluate user input.
315                    input = Console.ReadLine();
316
317                    int distanceTraveled;
318                    int energyUsed;
319
320                    // If player has decided to take it slow...
321                    if (input.Equals("1"))
322                    {
323                        distanceTraveled = (RandomNumber(1, 3) + movementModifier);
324                        energyUsed = RandomNumber(-3, -1);
325                        playerPosition += distanceTraveled;
326                        distanceStatement = "You have decided to play it safe, and have traveled " + distanceTraveled + " miles. ";
327                        energyStatement = GetEnergyStatement(energy);
328                        drachmasGained = RandomNumber(1, 3);
329
330                        // Make sure we are not surpassing the maximum energy cap.
331                        if (energy - energyUsed < maxEnergy - energyUsed)
332                        {
333                            energy -= energyUsed;
334                        }
335                        else
336                        {
337                            energy = maxEnergy;
338                        }
339
340                        IncrementItemDuration();
341
342                        decided = true;
343                    }
344                    // If player has decided on medium travel speed...
345                    else if (input.Equals("2") && energy >= 4)
346                    {
347                        distanceTraveled = (RandomNumber(3, 5) + movementModifier);
348                        energyUsed = RandomNumber(2, 4);
349                        playerPosition += distanceTraveled;
350                        energy -= energyUsed;
351                        distanceStatement = "You have decided to move at a steady pace, and have traveled " + distanceTraveled + " miles. ";
352                        energyStatement = GetEnergyStatement(energy);
353                        drachmasGained = RandomNumber(2, 4);
354                        drachmas += drachmasGained;
355                        IncrementItemDuration();
356
357                        decided = true;
358                    }
359                    // If player has decided to go full speed...
360                    else if (input.Equals("3") && energy >= 8)
361                    {
362                        distanceTraveled = (RandomNumber(4, 8) + movementModifier);
363                        energyUsed = RandomNumber(6, 8);
364                        drachmasGained =
365                        playerPosition += distanceTraveled;
366                        energy -= energyUsed;
367                        distanceStatement = "You have decided to travel at full speed, and have traveled " + distanceTraveled + " miles. ";
368                        energyStatement = GetEnergyStatement(energy);
369                        drachmasGained = RandomNumber(3, 6);
370                        IncrementItemDuration();
371
372                        decided = true;
373                    }
374                    // If player has decided to rest...
375                    else if (input.Equals("4"))
376                    {
377                        energyUsed = RandomNumber(-10, -6);
378                        energy -= energyUsed;
379                        distanceStatement = "You have decided to take a rest and recover your energy. ";
380                        energyStatement = GetEnergyStatement(energy);
381                        IncrementItemDuration();
382
383                        decided = true;
384                    }
385                    else if (input.Equals("5"))
386                    {
387                        Console.WriteLine("----------------- STATUS REPORT -----------------\nEnergy: " + GetEnergyStatement(energy) +
388                            "\nDrachmas: " + drachmas + "\nHades is " + positionDifference + " miles behind you.");
389                        decided = false;
390                    }
391                    else if (input.Equals("6"))
392                    {
393                        bool decisionMade = false;
394                        Console.WriteLine("Are you sure you would like to quit?\n1. Yes\n2. No");
395                        string choice;
396
397                        while (!decisionMade)
398                        {
399                            choice = Console.ReadLine();
400
401                            if (choice.Equals("1"))
402                            {
403                                Console.WriteLine("You have exited the game.");
404                                done = true;
405                                decided = true;
406                                decisionMade = true;
407                            }
408                            else if (choice.Equals("2"))
409                            {
410                                decisionMade = true;
411                            }
412                            else
413                            {
414                                Console.WriteLine("Please enter either 1 or 2.");
415                            }
416                        }
417                    }
418                    // If player has entered anything that is not above or does not have enough energy...
419                    else
420                    {
421                        if ((input.Equals("2") && energy < 4) || (input.Equals("3") && energy < 8))
422                        {
423                            Console.WriteLine("You do not have enough energy for that!");
424                        }
425                        else
426                        {
427                            Console.WriteLine("That is not an option, please enter a number between 1 and 4.");
428                        }
429                        // Keep loop running.
430                        decided = false;
431                    }
432                }
433
434                // Update Hades position and print out the game status.
435                if (!done)
436                {
437                    SetHadesPosition();
438                    Console.WriteLine(distanceStatement + energyStatement);
439                    Console.WriteLine("While traveling you found " + drachmasGained + " drachmas!");
440                    drachmas += drachmasGained;
441                    turnCounter += 1;
442                }
443
444                for (int i = 0; i < shops.Length; i++)
445                {
446                    if (playerPosition == shops[i])
447                    {
448                        OpenShop();
449                    }
450                }
451            }
452            // -----------------------------------------------------------------------------------------------------------------------
453
454            // ----------------------------------------------------MAIN GAME SETUP----------------------------------------------------
455            InitializeGame();
456
457            // Run this loop while the game is not over.
458            while (!done)
459            {
460                string input;
461                bool playAgainDecision;
462                if (playerPosition < gameLength)
463                {
464                    if (playerPosition <= hadesPosition)
465                    {
466                        Console.WriteLine("You were caught! Game Over!");
467                        playAgainDecision = false;
468                        Console.WriteLine("Would you like to try again?\n1. Yes\n2. No");
469
470                        while (!playAgainDecision)
471                        {
472                            input = Console.ReadLine();
473
474                            if (input.Equals("1"))
475                            {
476                                InitializeGame();
477                                playAgainDecision = true;
478                                done = false;
479                            }
480                            else if (input.Equals("2"))
481                            {
482                                playAgainDecision = true;
483                                done = true;
484                            }
485                            else
486                            {
487                                Console.WriteLine("Invalid Input. Please enter either 1 or 2.");
488                                playAgainDecision = false;
489                            }
490                        }
491                    }
492                    else
493                    {
494                        CheckForAncientRuins();
495                        GetUserDecision();
496                        positionDifference = playerPosition - hadesPosition;
497                        Console.WriteLine(lineBreak);
498                    }
499                }
500                else
501                {
502                    Console.WriteLine("You win!");
503                    playAgainDecision = false;
504                    while (!playAgainDecision)
505                    {
506                        input = Console.ReadLine();
507
508                        if (input.Equals("1"))
509                        {
510                            InitializeGame();
511                            playAgainDecision = true;
512                            done = false;
513                        }
514                        else if (input.Equals("2"))
515                        {
516                            playAgainDecision = true;
517                            done = true;
518                        }
519                        else
520                        {
521                            Console.WriteLine("Invalid Input. Please enter either 1 or 2.");
522                            playAgainDecision = false;
523                        }
524                    }
525                }
526            }
527        }
528        // -----------------------------------------------------------------------------------------------------------------------
529    }
530}

Camel Version 3

  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Text;
  5using System.Threading.Tasks;
  6
  7namespace CamelGame
  8{
  9    class Program
 10    {
 11        private static readonly int MILES_TO_HIDEOUT = 200;
 12
 13        private static bool done;
 14        private static bool win;
 15        private static bool quit;
 16        private static int milesTraveled;
 17        private static int fillupsLeft;
 18        private static int policeMilesTraveled;
 19        private static int gasTankLeft;
 20        private static char userInput;
 21        private static bool validInput;
 22        private static readonly Random rand = new Random();
 23
 24        static bool FoundOasis(int findingNumber)
 25        {
 26            if (findingNumber == 15)
 27            {
 28                return true;
 29            }
 30            else
 31            {
 32                return false;
 33            }
 34        }
 35
 36        static void Main()
 37        {
 38            bool playAgain = true;
 39
 40            while (playAgain)
 41            {
 42                Console.WriteLine("Welcome to Bank Heist!\n" +
 43                "You have stolen one-million dollars from a bank and must escape to your secret hide out.\n" +
 44                "The police are hot on your tail and will stop at nothing to catch you!\n" +
 45                "Out run the cops and escape to your hideout to keep your freedom.\n");
 46
 47                done = false;
 48                win = false;
 49                validInput = true;
 50
 51                milesTraveled = 0;
 52                gasTankLeft = 0;
 53                fillupsLeft = 3;
 54
 55                policeMilesTraveled = -20;
 56
 57
 58                while (!done)
 59                {
 60                    Console.WriteLine();
 61                    Console.WriteLine("A. Ahead moderate speed.\n" +
 62                        "B. Ahead full speed.\n" +
 63                        "C. Stop to fill up the gas tank.\n" +
 64                        "D. Status check.\n" +
 65                        "Q. Quit.\n");
 66
 67                    Console.Write("What is your choice? ");
 68                    userInput = Console.ReadKey().KeyChar;
 69                    Console.WriteLine("\n");
 70
 71                    validInput = true;
 72
 73                    // The user chooses to quit the game.
 74                    if (char.ToUpper(userInput) == 'Q')
 75                    {
 76                        QuitGame();
 77                    }
 78                    // The user chooses to check their status.
 79                    else if (char.ToUpper(userInput) == 'D')
 80                    {
 81                        CheckStatus();
 82                    }
 83                    // The user chooses to hide for the night.
 84                    else if (char.ToUpper(userInput) == 'C')
 85                    {
 86                        StopToFillGas();
 87                    }
 88                    // The user chooses to move ahead full speed.
 89                    else if (char.ToUpper(userInput) == 'B')
 90                    {
 91                        MoveAhead(false);
 92                    }
 93                    // The user chooses to move ahead slowly.
 94                    else if (char.ToUpper(userInput) == 'A')
 95                    {
 96                        MoveAhead(true);
 97                    }
 98                    // The user input was invalid.
 99                    else
100                    {
101                        Console.WriteLine("You input was invalid.");
102                        validInput = false;
103                    }
104
105                    CheckIfCaught();
106
107                }
108
109                if (win)
110                {
111                    Console.WriteLine("\nCongratulations! You've escaped the police and won the game!");
112                }
113                else if (!win && !quit)
114                {
115                    Console.WriteLine("\nYou have lost the game.");
116                }
117                else
118                {
119                    Console.WriteLine("\nThanks for playing.");
120                }
121
122                Console.Write("Would you like to play again? (Y/N) ");
123                userInput = Console.ReadKey().KeyChar;
124                Console.WriteLine("\n");
125
126                if (char.ToUpper(userInput) == 'Y')
127                {
128                    playAgain = true;
129                }
130                else if (char.ToUpper(userInput) == 'N')
131                {
132                    playAgain = false;
133                }
134                else
135                {
136                    Console.WriteLine("You have entered an invalid value and the game will now close.\n");
137                    playAgain = false;
138                }
139            }
140
141            Console.WriteLine("Thank you for playing. Press any key to exit.");
142            _ = Console.ReadKey();
143        }
144
145        private static void CheckIfCaught()
146        {
147            if (char.ToUpper(userInput) != 'Q' && validInput)
148            {
149                if (gasTankLeft > 8 && !done)
150                {
151                    Console.WriteLine("Your car ran out of gas and you got caught.");
152                    done = true;
153                }
154                else if (gasTankLeft > 5)
155                {
156                    Console.WriteLine("Your gas is getting low.");
157                }
158
159                if ((milesTraveled - policeMilesTraveled) <= 0 && !done)
160                {
161                    Console.WriteLine("The police caught you.");
162                    done = true;
163                }
164                else if ((milesTraveled - policeMilesTraveled) <= 15)
165                {
166                    Console.WriteLine("The police are getting close!");
167                }
168
169                if (milesTraveled >= MILES_TO_HIDEOUT && !done)
170                {
171                    done = true;
172                    win = true;
173                }
174            }
175        }
176
177        static void QuitGame()
178        {
179            done = true;
180            quit = true;
181        }
182
183        static void CheckStatus()
184        {
185            Console.WriteLine("Miles traveled: " + milesTraveled);
186            Console.WriteLine("Gas fill-ups remaining: " + fillupsLeft);
187            Console.WriteLine("The police are " + (milesTraveled - policeMilesTraveled) +
188                " miles behind you.");
189        }
190
191        static void StopToFillGas()
192        {
193            gasTankLeft = 0;
194            fillupsLeft -= 1;
195            policeMilesTraveled += rand.Next(7, 15);
196
197            if (policeMilesTraveled < milesTraveled)
198            {
199                Console.WriteLine("Your gas tank is full.");
200            }
201        }
202
203        static void MoveAhead(bool slow)
204        {
205            int currentMilesTraveled;
206            if (!slow)
207            {
208                currentMilesTraveled = rand.Next(10, 21);
209                gasTankLeft += rand.Next(1, 4);
210            }
211            else
212            {
213                currentMilesTraveled = rand.Next(5, 13);
214                gasTankLeft++;
215            }
216            milesTraveled += currentMilesTraveled;
217            policeMilesTraveled += rand.Next(7, 15);
218            Console.WriteLine("You traveled " + currentMilesTraveled + " miles.");
219
220            int findingAHideout = rand.Next(19);
221
222            if (FoundOasis(findingAHideout) && milesTraveled < MILES_TO_HIDEOUT)
223            {
224                Console.WriteLine("You found an abandoned hideout!");
225                fillupsLeft = 3;
226                gasTankLeft = 0;
227            }
228        }
229
230    }
231}