Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // General initializations to prevent magic numbers
            int mapwidth = 5;
            int mapheight = 5;
            int xstartpos = 2;
            int ystartpos = 0;
            // Welcome the player
            Console.WriteLine("Welcome to a textbased adventure");
            Console.WriteLine("Before you can start your journey, you will have to enter your name.");

            string name = null;
            string input = null;

            // Check for the correct name
            // Refactored from do - while to improve readability by Michiel and Alex
            while(input != "Y") 
            {
                if( input == null || input == "N" )
                {
                    Console.WriteLine("Please enter your name and press enter:");
                    name = Console.ReadLine();
                }

                Console.WriteLine("Your name is {0}",name);
                Console.WriteLine("Is this correct? (y/n)");
                input = Console.ReadLine();
                input = input.ToUpper();
            }

            do
            {
                Game.JustDied = false;
                // Make the player
                Player player = new Player(name, 100);
                //Welcome the player
                Welcome(ref player);

                // Initialize the map
                Map map = new Map(mapwidth, mapheight, xstartpos, ystartpos);
                Game.Map = map;
                Game.Player = player;
                // Put the locations with their items on the map
                InitMap(ref map);
                // Start the game
                Start(ref map, ref player);
            } while (Game.JustDied);
            // End the program
            Quit();
        }
Ejemplo n.º 2
0
        static void Welcome(ref Player player)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
            string intro = "After 30 years of being a member of the \"SoLntsevskaya Bratva\" mafia,\nyou've decided to quit and start a new life. Tonight is a special night,\nwhere the biggest gala festival in Russia takes place.\nAfter sipping on a lot of the very expensive \"Iordanov Vodka\",\nyou decide to go the restroom. You start feeling dizzy, your body goes numb,\nand you get unconscious...\n\n";
            foreach (char c in intro)
            {
                Console.Write(c);
                Thread.Sleep(c == '.' || c == ',' ? 350 : 10);
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("Press any key to continue.");
            
            // Added newline to improve readability.


            //write an introduction
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Start(ref Map map, ref Player player)
        {
            List<string> menuItems = new List<string>();
            int choice;

            // Refactored by Michiel and Alex
            do
            {
                Console.Clear();
                if (Game.JustDied) break;
                map.GetLocation().Description();
                if (Game.JustDied) break;
                choice = ShowMenu(map, ref menuItems);

                if ( choice != menuItems.Count() )
                {
                    if ( validDirections.Contains( menuItems[choice] ) )
                    {
                        map.Move( menuItems[choice] );
                    }

                    switch ( menuItems[choice] )
                    {
                        case ACTION_SEARCH:
                            Console.Clear();
                            foreach (var item in map.GetLocation().GetItems())
                            {
                                item.Value.Description();
                                player.PickupItem(item.Value);
                            }
                            player.ShowInventory();
                            Console.WriteLine("Press any key to continue...");
                            Console.ReadKey();
                            // Add code to perform an item pickup
                        break;

                        case ACTION_FIGHT:
                            map.GetLocation().Fight();
                        break;

                        case ACTION_RUN:
                            // Add code for running here
                        break;

                        default:
                            if(map.GetLocation().quiz)
                            {
                                if (map.GetLocation().quizQuestions.Contains(menuItems[choice]))
                                {
                                    if(choice == map.GetLocation().quizAnswer)
                                    {
                                        map.GetLocation().OnQuizGoodAnswer();
                                    }
                                    else
                                    {
                                        map.GetLocation().OnQuizBadAnswer();
                                    }
                                }
                            }
                        break;
                    }
                }
            } 
            // When the choice is equal to the total item it means exit has been chosen.
            while ( choice < menuItems.Count() - 1);
        }