コード例 #1
0
        public Map()
        {
            //defining nodes
            Area a = new Area("Entrance", "it looks dark and spooky, are you sure you should be here?");
            Area b = new Area("Dickbutt palace", "are you really sure you should be HERE?");
            Area c = new Area("The basement", "it's locked and damp");
            Area d = new Area("The crypt", "The tombs have already been raided :(");

            //Area e = new Area("The crypt", "The tombs have already been raided :(");

            //adding areas to list
            areas = new List <Area>();
            areas.Add(a);
            areas.Add(b);
            areas.Add(c);
            areas.Add(d);
            //areas.Add(e);

            //defining edges
            a.AddArea(c, Directions.West);
            c.AddArea(a, Directions.East);
            c.AddArea(d, Directions.West);
            d.AddArea(c, Directions.East);
            a.AddArea(b, Directions.North);
            b.AddArea(a, Directions.South);

            startingPosition = a;
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //defining nodes
            Area a = new Area("A", "");
            Area b = new Area("B", "");
            Area c = new Area("C", "");
            Area d = new Area("D", "");

            //defining edges
            a.AddArea(c, Directions.West);
            c.AddArea(a, Directions.East);
            c.AddArea(d, Directions.West);
            d.AddArea(c, Directions.East);
            a.AddArea(b, Directions.North);
            b.AddArea(a, Directions.South);

            //starting area
            Area currentArea = a;

            //read input
            string command = Console.ReadLine();

            //split it to separate, e.g. "go east" into {"go", "east"}
            string[] inputs = command.Split(' ');
            switch (inputs[0])
            {
            //the "go" command is given
            case "go":
            case "Go":
                switch (inputs[1])
                {
                case "east":
                    GoToDirection(Directions.East, ref currentArea);
                    break;

                case "west":
                    GoToDirection(Directions.West, ref currentArea);
                    break;

                case "south":
                    GoToDirection(Directions.South, ref currentArea);
                    break;

                case "north":
                    GoToDirection(Directions.North, ref currentArea);
                    break;
                }
                break;

            default:
                break;
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //defining nodes
            Area a = new Area("Entrance", "it looks dark and spooky, are you sure you should be here?");
            Area b = new Area("Dickbutt palace", "are you really sure you should be HERE?");
            Area c = new Area("The basement", "it's locked and damp");
            Area d = new Area("The crypt", "The tombs have already been raided :(");

            //defining edges
            a.AddArea(c, Directions.West);
            c.AddArea(a, Directions.East);
            c.AddArea(d, Directions.West);
            d.AddArea(c, Directions.East);
            a.AddArea(b, Directions.North);
            b.AddArea(a, Directions.South);

            //starting area
            Area currentArea = a;

            //gameplay loop
            while (true)
            {
                //let's print where we are
                Console.WriteLine("You are in " + currentArea.name);

                //read input
                string command = Console.ReadLine();
                //split it to separate, e.g. "go east" into {"go", "east"}
                string[] inputs = command.Split(' ');
                switch (inputs[0])
                {
                //the "go" command is given
                case "go":
                case "Go":
                    switch (inputs[1])
                    {
                    case "east":
                        GoToDirection(Directions.East, ref currentArea);
                        break;

                    case "west":
                        GoToDirection(Directions.West, ref currentArea);
                        break;

                    case "south":
                        GoToDirection(Directions.South, ref currentArea);
                        break;

                    case "north":
                        GoToDirection(Directions.North, ref currentArea);
                        break;
                    }
                    break;

                case "examine":
                    //give some info about current area
                    Console.WriteLine(currentArea.description);
                    Console.WriteLine();

                    //for each key in neighbors
                    foreach (Directions dir in currentArea.neighbors.Keys)
                    {
                        Console.WriteLine("To the " + dir.ToString().ToLower() + " there is a " + currentArea.neighbors[dir].name);
                    }
                    break;

                case "quit":
                    Environment.Exit(0);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Area a = new Area("Silent Hills", "It seems like a place you don't wanna be..");
            Area b = new Area("Misty fields", "Mist enshrouds the fields..");
            Area c = new Area("Town Center", "All empty but something eerie fills the place..");
            Area d = new Area("Town Church", "What should have been holy, is now damned..");

            a.AddArea(c, Directions.West);
            c.AddArea(a, Directions.East);
            c.AddArea(d, Directions.West);
            d.AddArea(c, Directions.East);
            a.AddArea(b, Directions.North);
            b.AddArea(a, Directions.South);

            Area currentArea = a;

            //Start of intro
            Console.Write("Welcome to the Silent Hills");

            int dots = 3;

            for (int i = 0; i < dots; i++)
            {
                Console.Write(".");
                System.Threading.Thread.Sleep(1000);
            }
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("You don't want to enter, but you cannot go back from whence you came");

            for (int j = 0; j < dots; j++)
            {
                Console.Write(".");
                System.Threading.Thread.Sleep(1000);
            }
            System.Threading.Thread.Sleep(1000);



            while (true)
            {
                //read input
                string command = Console.ReadLine();
                //splits the string and removes the empty space
                string[] inputs = command.Split(' ');

                //Takes the first word of the

                switch (inputs[0])
                {
                case "go":
                case "Go":
                case "gO":
                case "GO":
                    switch (inputs[1])
                    {
                    case "east":
                        GoToDirection(Directions.East, ref currentArea);
                        Console.WriteLine("You are now in " + currentArea.name);
                        System.Threading.Thread.Sleep(3000);
                        Console.WriteLine(currentArea.description);
                        Console.WriteLine();
                        if (currentArea.neighbors.ContainsKey(Directions.East))
                        {
                            Console.WriteLine("Your path is blocked by something...");
                        }
                        break;

                    case "west":
                        GoToDirection(Directions.West, ref currentArea);
                        Console.WriteLine("You are now in " + currentArea.name);
                        System.Threading.Thread.Sleep(3000);
                        Console.WriteLine(currentArea.description);
                        Console.WriteLine();
                        if (currentArea.neighbors.ContainsKey(Directions.West))
                        {
                            currentArea = a.neighbors[Directions.West];
                        }
                        else
                        {
                            Console.WriteLine("There's nothing there");
                        }
                        break;

                    case "south":
                        GoToDirection(Directions.South, ref currentArea);
                        Console.WriteLine("You are now in " + currentArea.name);
                        System.Threading.Thread.Sleep(3000);
                        Console.WriteLine(currentArea.description);
                        Console.WriteLine();
                        if (currentArea.neighbors.ContainsKey(Directions.West))
                        {
                            currentArea = a.neighbors[Directions.South];
                        }
                        else
                        {
                            Console.WriteLine("You cannot go there..");
                        }
                        break;

                    case "north":
                        GoToDirection(Directions.North, ref currentArea);
                        Console.WriteLine("You are now in " + currentArea.name);
                        System.Threading.Thread.Sleep(3000);
                        Console.WriteLine(currentArea.description);
                        Console.WriteLine();
                        if (currentArea.neighbors.ContainsKey(Directions.North))
                        {
                            currentArea = a.neighbors[Directions.North];
                        }
                        else
                        {
                            Console.WriteLine("Nope, not today my friend");
                        }
                        break;
                    }
                    break;


                default:
                    Console.WriteLine("You are currently in " + currentArea.name);
                    break;

                case "quit":
                    Environment.Exit(0);
                    break;

                case "examine":
                    //The examine "function"
                    Console.WriteLine(currentArea.description);
                    Console.WriteLine();

                    foreach (Directions dir in currentArea.neighbors.Keys)
                    {
                        Console.WriteLine("To the " + dir.ToString().ToLower() + "there is a " + currentArea.neighbors[dir].name);
                    }

                    break;
                }
            }
        }