Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MazeGame
- {
- //Exercise4_3
- public class Maze
- {
- private Room startRoom;
- private Room winningRoom;
- private Room losingRoom;
- public Maze()
- {
- //Rooms
- Room bedroom = new Room("bedroom");
- Room kitchen = new Room("kitchen");
- Room boxroom = new Room("boxroom");
- Room garage = new Room("garage");
- Room childsRoom = new Room("childsRoom");
- Room garden = new Room("garden");
- Room livingroom = new Room("livingroom");
- //Connection
- garden.setConnectedRooms(null, livingroom, null, null);
- livingroom.setConnectedRooms(garden, bedroom, garage, null);
- bedroom.setConnectedRooms(livingroom, childsRoom, kitchen, null);
- childsRoom.setConnectedRooms(bedroom, null, boxroom, null);
- boxroom.setConnectedRooms(kitchen, null, null, childsRoom);
- kitchen.setConnectedRooms(garage, boxroom,null , bedroom);
- garage.setConnectedRooms(null, kitchen, null, livingroom);
- startRoom = kitchen;
- winningRoom = garden;
- losingRoom = childsRoom;
- }
- public Room getStartRoom()
- {
- return startRoom;
- }
- public Room getWinningRoom()
- {
- return winningRoom;
- }
- public Room getLosingRoom()
- {
- return losingRoom;
- }
- }
- //Exercise4_4
- public class Player
- {
- private Room currentRoom;
- public Player(Room _currentRoom)
- {
- currentRoom = _currentRoom;
- }
- public Room getCurrentRoom()
- {
- return this.currentRoom;
- }
- public bool move (char direction)
- {
- Room nextroom = currentRoom.getConnectedRoom(direction);
- if (nextroom == null)
- {
- return false;
- }
- else { currentRoom = nextroom;return true; }
- }
- }
- //Exercise4_2
- public class Room
- {
- private string name;
- private Room south;
- private Room north;
- private Room west;
- private Room east;
- public Room(string _name)
- {
- name = _name;
- }
- public string getName()
- {
- return this.name;
- }
- public void setConnectedRooms(Room north, Room south, Room west, Room east)
- {
- this.north = north;
- this.south = south;
- this.west = west;
- this.east = east;
- }
- public Room getConnectedRoom(char direction)
- {
- switch (direction)
- {
- case 'n': return north;
- case 'e': return east;
- case 's': return south;
- case 'w': return west;
- default: return null;
- }
- }
- }
- //Exercise4_5
- class Program
- {
- static void Main(string[] args)
- {
- Maze maze = new Maze();
- Player Kobosil = new Player(maze.getStartRoom());
- while (Kobosil.getCurrentRoom() != maze.getWinningRoom() && Kobosil.getCurrentRoom() != maze.getLosingRoom())
- {
- Console.WriteLine("You are in the " + Kobosil.getCurrentRoom().getName());
- Console.WriteLine("Type in 'n', 'e', 's' or 'w' to move to another room!");
- Console.WriteLine();
- char success = Convert.ToChar(Console.ReadLine());
- Console.WriteLine();
- if (Kobosil.move(success) == true)
- {
- Console.WriteLine("You moved to another Romm.");
- Console.WriteLine();
- }
- else Console.WriteLine("You ran into a wall. Idiot!");
- }
- if (Kobosil.getCurrentRoom() == maze.getWinningRoom())
- {
- Console.WriteLine("Awesome! You win");
- }
- else Console.WriteLine("To Bad! You Loose");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement