public Location(string name, string description, bool visited,
                 Place address, Doors neighbours)
 {
     Name        = name;
     Description = description;
     Visited     = visited;
     Address     = address;
     Neighbours  = neighbours;
 }
        private static bool checkValidPath(Location[,] World, Place dir, string arrowKey)
        {
            bool condition = true;

            {
                Doors validRoom = World[dir.X, dir.Y].Neighbours;

                if (validRoom.East.X != -1 && arrowKey == "East")
                {
                    condition = true;
                }
                else if (validRoom.East.X == -1 && arrowKey == "East")
                {
                    Console.WriteLine("Can not go East, try again!: ");
                    condition = false;
                }

                if (validRoom.West.X != -1 && arrowKey == "West")
                {
                    condition = true;
                }
                else if (validRoom.West.X == -1 && arrowKey == "West")
                {
                    Console.WriteLine("Can not go that way, try again!: ");
                    condition = false;
                }

                if (validRoom.North.Y != -1 && arrowKey == "North")
                {
                    condition = true;
                }
                else if (validRoom.North.X == -1 && arrowKey == "North")
                {
                    Console.WriteLine("Can not go that way, try again!: ");
                    condition = false;
                }

                if (validRoom.South.Y != -1 && arrowKey == "South")
                {
                    condition = true;
                }
                else if (validRoom.South.X == -1 && arrowKey == "South")
                {
                    Console.WriteLine("Can not go that way, try again!: ");
                    condition = false;
                }
            }
            return(condition);
        }
Esempio n. 3
0
        private static bool getDir(Location[,] World, string keyPress, Place currentPlace)
        {
            bool  condition = false;
            Doors validRoom = World[currentPlace.Y, currentPlace.X].Neighbours;

            if (validRoom.East.X != -1 && keyPress == "East")
            {
                condition = true;
            }
            if (validRoom.West.X != -1 && keyPress == "West")
            {
                condition = true;
            }
            if (validRoom.North.Y != -1 && keyPress == "North")
            {
                condition = true;
            }
            if (validRoom.South.Y != -1 && keyPress == "South")
            {
                condition = true;
            }
            return(condition);
        }
        // Open the door in the direction of Dir. The neighbour in that direction
        // needs the opposite door opening.
        static void SetDoor(ref Location[,] World, string Dir, Place address)
        {
            // Get current neighbours, so we don't lose them
            Doors doors = World[address.Y, address.X].Neighbours;

            // Which door?
            switch (Dir)
            {
            case "East":
                // You can only have an eastern neighbour if not on east edge
                if (address.X < World.GetLength(1) - 1)
                {
                    // Set the east door to point to eastern neighbour
                    doors.East = new Place(address.Y, address.X + 1);
                    // Set our eastern neighbour's west door
                    Doors doorsNeighbour = World[address.Y, address.X + 1].Neighbours;
                    doorsNeighbour.West = address;
                    World[address.Y, address.X + 1].Neighbours = doorsNeighbour;
                }
                break;

            case "West":
                // You can only have an western neighbour if not on west edge
                if (address.X > 0)
                {
                    // Set the east door to point to western neighbour
                    doors.West = new Place(address.Y, address.X - 1);
                    // Set our eastern neighbour's east door
                    Doors doorsNeighbour = World[address.Y, address.X - 1].Neighbours;
                    doorsNeighbour.East = address;
                    World[address.Y, address.X - 1].Neighbours = doorsNeighbour;
                }
                break;

            case "South":
                if (address.Y < World.GetLength(0) - 1)
                {
                    // Set the south door to point to southern neighbour
                    doors.South = new Place(address.Y + 1, address.X);
                    // Set our eastern neighbour's north door
                    Doors doorsNeighbour = World[address.Y + 1, address.X].Neighbours;
                    doorsNeighbour.North = address;
                    World[address.Y + 1, address.X].Neighbours = doorsNeighbour;
                }
                break;

            case "North":
                if (address.Y > 0)
                {
                    // Set the north door to point to northern neighbour
                    doors.North = new Place(address.Y - 1, address.X);
                    // Set our eastern neighbour's south door
                    Doors doorsNeighbour = World[address.Y - 1, address.X].Neighbours;
                    doorsNeighbour.South = address;
                    World[address.Y - 1, address.X].Neighbours = doorsNeighbour;
                }
                break;
            }

            // Put this address's modified doors back
            World[address.Y, address.X].Neighbours = doors;
        }