Четверг, Сентябрь 24, 2020

Home1

//Одни только комнаты, без наружных дверей

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Home
{
    public partial class Form1 : Form
    {
        Location location;
        Room diningRoom;
        Room kitchen;
        Room livingRoom;
        public Form1()
        {
            InitializeComponent();
            CreateObject();
            MoveToANewLocation(diningRoom);
        }
        private void CreateObject()
        {
            diningRoom = new Room("Столовая", "хрустальная люстра");
            kitchen = new Room("Кухня", "плита из нержавеющей стали");
            livingRoom = new Room("Гостиная", "старинный ковер");
            diningRoom.Exits = new Location[] { kitchen, livingRoom };
            kitchen.Exits = new Location[] { diningRoom };
            livingRoom.Exits = new Location[] { diningRoom };
        }
        private void MoveToANewLocation(Location newLocation)
        {
            location = newLocation;
            description.Text = location.Description;
        }
    }
    abstract class Location
    {
        private string name;
        public string Name
        {
            get { return name; }
        }
        public Location(string name)
        {
            this.name = name;
        }
        public Location[] Exits;
        public virtual string Description
        {
            get
            {
                string desc = "Вы находитесь в " + name + ". Вы видите двери ведущие в:";
                for (int i = 0; i < Exits.Length; i++)
                {
                    desc += Exits[i].name;
                    if (i != Exits.Length - 1)
                        desc += ",";
                }
                desc += ".";
                return desc;
            }
        }
    }
    class Room : Location
    {
        private string decoration;
        public Room(string name, string decoration)
            : base(name)
        {
            this.decoration = decoration;
        }
        public override string Description
        {
            get
            {
                return base.Description + "Вы видите " + decoration + ".";
            }
        }
    }
}


 

НАЗАД                                                                                                                                         ДАЛЕЕ


Back to Top