コード例 #1
0
        public void Run()
        {
            Console.WriteLine("Welcome to the Dungeon, we have fun and games...");
            Console.WriteLine("\nPlease enter the player's name. ");
            Character1 character = new Character1()
            {
            };

            character.name = Console.ReadLine();
            Console.WriteLine($"\nHello, {character.name}.");

            Rooms B1RA = new Rooms()
            {
            };
            Rooms B1RB = new Rooms()
            {
            };
            Rooms B1RC = new Rooms()
            {
            };
            Rooms B1RD = new Rooms()
            {
            };
            Rooms B1RE = new Rooms()
            {
            };
            Rooms B2RA = new Rooms()
            {
            };
            Rooms B2RB = new Rooms()
            {
            };
            Rooms B2RC = new Rooms()
            {
            };
            Rooms B2RD = new Rooms()
            {
            };
            Rooms B3RA = new Rooms()
            {
            };

            B1RA.Room("Room A", 1, null, B1RD, B1RC, B1RB);
            B1RB.Room("Room B", 1, null, B1RE, B1RA, null);
            B1RC.Room("Room C", 1, null, null, null, B1RA);
            B1RD.Room("Room D", 1, B1RA, B2RA, null, B1RE);
            B1RE.Room("Room E", 1, B1RB, null, B1RD, null);
            B2RA.Room("Room A", 2, null, B2RC, B3RA, B2RB);
            B2RB.Room("Room B", 2, null, B2RD, B2RA, null);
            B2RC.Room("Room C", 2, B2RA, null, null, B2RD);
            B2RD.Room("Room D", 2, B2RB, null, B2RC, null);
            B3RA.Room("Room A", 3, B1RD, null, null, B2RA);

            Rooms start = new Rooms();

            start.GoToRoom(B1RA, character);
        }
コード例 #2
0
 public void Items(Rooms room, Character1 character)
 {
     Console.WriteLine($"You have found a {Convert.ToString(room)}");
     Console.WriteLine($"The {room} has been added to your inventory");
     character.inventory.Add(Convert.ToString(room), Convert.ToInt32(room));
 }
コード例 #3
0
        public void GoToRoom(Rooms room, Character1 character)
        {
            bool up    = false;
            bool down  = false;
            bool right = false;
            bool left  = false;

            Console.WriteLine($"\nYou are in Building {room.building} - {room.name}.");
            FoundItem items = new FoundItem();


            Console.WriteLine("\nYou can go:");
            if (room.up != null && room.up.building != room.building)
            {
                Console.WriteLine($"UP to Building {Convert.ToString(room.up.building)} - {Convert.ToString(room.up.name)}");
                up = true;
            }
            else if (room.up != null)
            {
                Console.WriteLine($"UP to {Convert.ToString(room.up.name)}");
                up = true;
            }

            if (room.down != null && room.down.building != room.building)
            {
                Console.WriteLine($"DOWN to Building {Convert.ToString(room.down.building)} - {Convert.ToString(room.down.name)}");
                down = true;
            }
            else if (room.down != null && room.down.building == room.building)
            {
                Console.WriteLine($"DOWN to {Convert.ToString(room.down.name)}");
                down = true;
            }


            if (room.right != null && room.right.building != room.building)
            {
                Console.WriteLine($"RIGHT to Building {Convert.ToString(room.right.building)} - {Convert.ToString(room.right.name)}");
                right = true;
            }
            else if (room.right != null)
            {
                Console.WriteLine($"RIGHT to {Convert.ToString(room.right.name)}");
                right = true;
            }

            if (room.left != null && room.left.building != room.building)
            {
                Console.WriteLine($"LEFT to Building {Convert.ToString(room.left.building)} - {Convert.ToString(room.left.name)}");
                left = true;
            }
            else if (room.left != null)
            {
                Console.WriteLine($"LEFT to {Convert.ToString(room.left.name)}");
                left = true;
            }

            string response = Console.ReadLine().ToLower();

            Console.Clear();
            switch (response)
            {
            case "up":
                if (up)
                {
                    room.GoToRoom(room.up, character);
                }
                break;

            case "down":
                if (down)
                {
                    room.GoToRoom(room.down, character);
                }
                break;

            case "right":
                if (right)
                {
                    room.GoToRoom(room.right, character);
                }
                break;

            case "left":
                if (left)
                {
                    room.GoToRoom(room.left, character);
                }
                break;

            default:
                Console.WriteLine("Please choose a valid option...");
                GoToRoom(room, character);
                break;
            }
            Console.WriteLine("Please choose a valid option...");
            GoToRoom(room, character);
        }