ptrelford

Last Assignment (Text based adventure at GameCraft)

Nov 30th, 2013
280
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public static class Game
  5. {
  6.     public static bool Ended = false;
  7. }
  8.  
  9. public class State
  10. {
  11.     public State(string message, params string[] options)
  12.     {
  13.         Message = message;
  14.         Options = options;
  15.     }
  16.  
  17.     public string Message { get; private set;  }
  18.     public string[] Options { get; private set; }
  19.     public string Theme { get; private set; }    
  20. }
  21.  
  22. public static class Choice
  23. {
  24.     public static int Taken { get; set; }
  25. }
  26.  
  27. class Program
  28. {
  29.     static void Main(string[] args)
  30.     {            
  31.         // Console Runner
  32.         foreach (var state in Play())
  33.         {
  34.             Prompt(state);
  35.         }        
  36.  
  37.         // For XNA/MonoGame
  38.         /*
  39.         var e = Play().GetEnumerator();
  40.         while (e.MoveNext())
  41.         {                    
  42.             State state = e.Current;
  43.             Prompt(state);
  44.         }        
  45.         */
  46.     }
  47.  
  48.     private static void Prompt(State state)
  49.     {
  50.         Console.WriteLine(state.Message);
  51.         int n = 1;
  52.         foreach (var option in state.Options)
  53.         {
  54.             Console.WriteLine(string.Format("{0}: {1}", n, option));
  55.             ++n;
  56.         }
  57.         if (state.Options.Length == 0)
  58.         {
  59.             Console.WriteLine("THE END");
  60.             Console.ReadLine();
  61.             return;
  62.         }
  63.         Choice.Taken = 0;
  64.         do {
  65.             Console.Write("> ");
  66.             var s = Console.ReadLine();
  67.             n = 0;
  68.             Int32.TryParse(s, out n);
  69.             Choice.Taken = n;
  70.         } while (Choice.Taken < 1 || Choice.Taken > state.Options.Length);
  71.         Console.WriteLine();        
  72.     }      
  73.  
  74.     public static IEnumerable<State> Play()
  75.     {
  76.         Game.Ended = false;
  77.         foreach (var state in RansomNote()) yield return state;
  78.         foreach (var state in BankRobbery()) yield return state;
  79.         if (Game.Ended) yield break;
  80.         foreach (var state in Assignment()) yield return state;
  81.         if (Game.Ended) yield break;
  82.         foreach (var state in Rookie()) yield return state;
  83.         if (Game.Ended) yield break;
  84.         foreach (var state in DropOff()) yield return state;
  85.         if (Game.Ended) yield break;
  86.         foreach (var state in Chase()) yield return state;
  87.         if (Game.Ended) yield break;
  88.         yield return new State(
  89.             "Your last assignment is complete.\r\n" +
  90.             "You receive a badge of honour and a full police pension!\r\n" +
  91.             "Case closed."
  92.             );
  93.     }
  94.  
  95.     public static IEnumerable<State> RansomNote()
  96.     {
  97.         yield return new State(
  98.             "You arrive at the murder scene on the top of a tower.\r\n" +
  99.             "There's a dead girl in the pool.\r\n",
  100.             "Search the scene");
  101.         yield return new State(
  102.             "You find a ransom note:\r\n" +
  103.             "\"To the City of San Francisco, I will enjoy killing one person " +
  104.             "every day until you pay me one hundred thousand dollars ($100,000).\r\n" +
  105.             "If you agree say so tomorrow morning in Personal Column San Francisco Chronicle " +
  106.             "and I will set up meeting.\r\n" +
  107.             "If I do not hear from you it will be my next pleasure to kill " +
  108.             "a Catholic priest.\"",
  109.             "Sh*t"          
  110.             );      
  111.     }
  112.  
  113.     public static IEnumerable<State> BankRobbery()
  114.     {
  115.         // Hot dog
  116.         yield return new State(
  117.             "Your park up near Pine Street in front of an adult book shop, and saunter into the local Burger Den." +
  118.             "You order",
  119.             "Big Mac fries to go",
  120.             "A jumbo hot dog");
  121.         if (Choice.Taken == 1) yield break;
  122.         // Bank robbery
  123.         yield return new State(
  124.             "From the bank across the street you hear a gun shot.",
  125.             "You unholster your gun and head towards the bank",
  126.             "Call and wait for backup");
  127.         if (Choice.Taken == 2) yield break;
  128.         // First robber
  129.         yield return new State(
  130.             "The first armed robber leaves the bank",
  131.             "You shoot",
  132.             "Take cover");
  133.         if (Choice.Taken == 2) goto wounded;
  134.         // Car
  135.         yield return new State(
  136.             "The second robber drives towards you",
  137.             "You shoot",
  138.             "Take cover");
  139.         if (Choice.Taken == 2) goto wounded;
  140.         yield return new State(
  141.             "You missed.",
  142.             "Shoot again",
  143.             "Take cover");
  144.         if (Choice.Taken == 2) goto wounded;
  145.         yield return new State(
  146.             "You fire twice.\r\n" +
  147.             "The car veers off and hits a fire hydrant and flips over.\r\n" +
  148.             "A third robber appears from the bank.",
  149.             "You shoot",
  150.             "Take cover"
  151.         );
  152.         // Wounded
  153.         if (Choice.Taken == 2) goto wounded;
  154.         yield return new State(
  155.             "The shot robber lies wounded with a gun next to him." +
  156.             "\"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum, the most powerful handgun in the world, and would blow your head clean off, you've got to ask yourself one question: Do I feel lucky? Well, do ya punk?\"",
  157.             "He goes for the gun",
  158.             "He pushes the gun away"
  159.             );
  160.         if (Choice.Taken == 2) yield break;        
  161.         // Bang bang
  162.         yield return new State(
  163.             "You blow his brains out.\r\n" +
  164.             "The police arrive, you are arrested and discharged.");
  165.         goto ended;
  166.     wounded:
  167.         yield return Shot();
  168.     ended:
  169.         Game.Ended = true;
  170.     }
  171.  
  172.     public static State Shot()
  173.     {
  174.         return new State(
  175.             "You awake in a white room with a nurse leaning over you." +
  176.             "You were shot." +
  177.             "The case has been reassigned");
  178.     }
  179.  
  180.     public static IEnumerable<State> Assignment()
  181.     {
  182.         yield return new State(
  183.             "You're sat outside the major's office.\r\n" +
  184.             "They've kept you waiting for 45 minutes.",
  185.             "You storm in",
  186.             "Keep waiting");
  187.         if (Choice.Taken == 1) goto kicked;
  188.         yield return new State(
  189.             "The major wants to pay the ransom and asks you to do the drop off.",
  190.             "You don't do deals with criminals",
  191.             "Tacitaly accept"
  192.             );
  193.         if (Choice.Taken == 2) yield break;
  194.     kicked:
  195.         Game.Ended = true;
  196.         yield return new State(
  197.             "It's the last straw for the major.\r\n" +
  198.             "You're off the case!");
  199.     }
  200.  
  201.     public static IEnumerable<State> Rookie()
  202.     {
  203.         yield return new State(
  204.             "One way or another this will be your last assignment.\r\n" +
  205.             "Just 2 weeks left on the force before you retire.\r\n" +
  206.             "Back at the police station",
  207.             "You get a black coffee and a donut",
  208.             "A chai latte and a cup cake");
  209.         if (Choice.Taken == 2) goto imposter;
  210.         yield return new State(
  211.             "Your new partner introduces himself.",
  212.             "You give him a stern look",
  213.             "Ignore him");        
  214.         yield return new State(
  215.             "\"Why do they call ya 'Dirty Harry'?\"",
  216.             "Make up your own mind kid",
  217.             "Turn up your eye brow"
  218.             );      
  219.         yield break;
  220.     imposter:
  221.         Game.Ended = true;
  222.         yield return new State(
  223.             "You have been exposed as an imposter.\r\n" +
  224.             "Cops don't drink coffee, keep it real!");
  225.     }
  226.  
  227.     public static IEnumerable<State> DropOff()
  228.     {
  229.         yield return new State(
  230.             "Time for the drop off.\r\n" +
  231.             "The lieutenant tells you no funny business.",
  232.             "Go unarmed",
  233.             "Pick up a wire, pack a knife and hide old faithfull (.44 Magnum)"
  234.             );
  235.         var unarmed = (Choice.Taken == 1);
  236.         yield return new State(
  237.             "You arrive at the drop off point with $100,000.",
  238.             "Drop the bag in the bin"
  239.             );
  240.         yield return new State(
  241.             "You turn the corner",
  242.             "Carry on walking",
  243.             "Wait and watch");
  244.         if (Choice.Taken == 1) goto shot;
  245.         var combatOptions =
  246.             unarmed
  247.             ? new[] { "Freeze", "Use your elbow"}
  248.             : new[] { "Freeze", "Use the knife"};
  249.         yield return new State(
  250.             "You feel a gun against the back of your head",
  251.             combatOptions
  252.             );
  253.         if (Choice.Taken == 1)
  254.             foreach (var state in Taken()) yield return state;
  255.         else
  256.             yield return new State(
  257.                 "You wake up on the ground.\r\n" +
  258.                 "You feel a lump on the back of your head.",
  259.                 "Get up"
  260.             );
  261.                
  262.         yield break;            
  263.     shot:
  264.         Game.Ended = true;
  265.         yield return new State(
  266.             "You fall.\r\n" +
  267.             "The sniper got you");
  268.     }
  269.  
  270.     public static IEnumerable<State> Taken()
  271.     {
  272.         yield return new State(
  273.             "\"Walk on\"",
  274.             "You walk on",
  275.             "\"Go on shoot me, ya know ya want to punk\""
  276.             );
  277.         if (Choice.Taken == 2) goto shot;        
  278.         yield break;
  279.      shot:
  280.         Game.Ended = true;
  281.         yield return Shot();
  282.     }
  283.  
  284.     public static IEnumerable<State> Chase()
  285.     {
  286.         yield return new State(
  287.             "Your partner catches up with you.\r\n" +
  288.             "\"I tailed that punk, he's hiding out at Ugly Mug Joe's\"\r\n",
  289.             "\"What are you waiting for kid, lets go?\"",
  290.             "\"Wait here kid\"");
  291.         var partnerTaken = (Choice.Taken == 1);
  292.         yield return new State(
  293.             "Ugly Mug Joe's is a downtown dive bar full of low lifes.\r\n" +
  294.             "As you enter the bar you are spotted.\r\n" +
  295.             "He makes a run for it.",
  296.             "Take a shot",
  297.             "Chase after him"
  298.             );
  299.         if (Choice.Taken == 1)
  300.         {
  301.             if (partnerTaken)
  302.             {
  303.                 yield return new State(
  304.                     "He turns and shoots.\r\n" +
  305.                     "Your partner is down.",
  306.                     "Chase after him"
  307.                     );
  308.             }
  309.             else goto dead;
  310.         }
  311.         yield return new State(
  312.             "He slides into his car and takes off.",
  313.             "Shoot",
  314.             "Hot pursuit");
  315.         if (Choice.Taken == 1) goto dead;
  316.         yield return new State(
  317.             "Your gaining on him.",
  318.             "Shoot",
  319.             "Ram him"
  320.             );
  321.         if (Choice.Taken == 1) goto dead;
  322.         yield return new State(
  323.             "He crashes into a fire hydrant.\r\n" +
  324.             "You approach and find him unconcious.\r\n",
  325.             "You read him his rights");
  326.         yield break;
  327.     dead:
  328.         Game.Ended = true;
  329.         yield return new State(
  330.             "You miss.\r\n" +
  331.             "He turns and shoots back.\r\n" +
  332.             "Game Over"
  333.             );
  334.     }
  335. }
RAW Paste Data