Example #1
0
        public override void VehicleApproach(Vehicle v)
        {
            if (!(v is GasolineCar))
            {
                throw new NotImplementedException();
            }
            GasolineCar c = v as GasolineCar;

            foreach (CityPath p in c.path)
            {
                if (p == priority)
                {
                    inside.Add(v);
                    return;
                }
            }
            if (Util.StopDistance(c.speed, GasolineCar.DEACCELERATION) + 25 < c.DistanceToNodeOnPath(priority.e))
            {
                return;
            }
            if (inside.Count > 0)
            {
                waiting.Add(v);
            }
            else
            {
                inside.Add(v);
            }
        }
    public static void Main(string[] args)
    {
        var car1 = new GasolineCar("Ford", "Focus", true);
        var car2 = new GasolineCar("Ford", "Focus", false);

        Console.WriteLine("car1 " + (car1.Equals(car2) ? "does" : "does not") + " equal car2.");
    }
Example #3
0
        public void InheritanceTest()
        {
            GasolineCar gasolineCar = new GasolineCar();

            gasolineCar.Color = "검정";
            gasolineCar.Size  = "SUV";

            ElectronicCar electronicCar = new ElectronicCar();

            electronicCar.Color = "초록";
            electronicCar.Size  = "경차";

            Console.WriteLine("{0}색 {1}가", gasolineCar.Color, gasolineCar.Size);
            gasolineCar.Go();
            gasolineCar.InputGas();

            Console.WriteLine("{0}색 {1}가", electronicCar.Color, electronicCar.Size);
            electronicCar.Left();
            electronicCar.InputGas();
        }
Example #4
0
        public Commuter(CityNode start, CityNode home = null, CityNode work = null, GasolineCar car = null)
        {
            this.x = start.x;
            this.y = start.y;

            this.home   = home;
            this.work   = work;
            lastVisited = start;
            goal        = start;

            this.car = car;
            if (car != null)
            {
                car.owner = this;
            }

            int possibilites = (2 * 60 + 30) / Sim.MINUTES_PER_SECOND;

            homeLeaveTime = 5 * 60 + 30 + r.Next(possibilites) * Sim.MINUTES_PER_SECOND;
            workLeaveTime = 16 * 60 + 30 + r.Next(possibilites) * Sim.MINUTES_PER_SECOND;

            Console.WriteLine("Leave to work: " + Util.GetTimeString(homeLeaveTime) + ", leave back home: " + Util.GetTimeString(workLeaveTime));
        }
Example #5
0
        /// <summary>
        /// Initialize graphics settings (screen size etc'), and call SetupGame.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            graphics.PreferredBackBufferWidth  = GAME_WIDTH;
            graphics.PreferredBackBufferHeight = GAME_HEIGHT;
            graphics.ApplyChanges();

            IsFixedTimeStep   = true;
            TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / Util.ToTicks(1));

            IsMouseVisible = true;

            sideMenu = new StackPanel(GAME_WIDTH - 350, 0, 350, GAME_HEIGHT);

            CityBuilder builder = new CityBuilder();

            BuilderTrafficCircleNode i1 = new BuilderTrafficCircleNode(430, 415);
            BuilderAllWayStopNode    i2 = new BuilderAllWayStopNode(940, 415);

            BuilderDeadEndNode e1top    = new BuilderDeadEndNode(430, 50, 0);
            BuilderDeadEndNode e1left   = new BuilderDeadEndNode(65, 415, MathHelper.ToRadians(-90));
            BuilderDeadEndNode e1bottom = new BuilderDeadEndNode(430, 780, MathHelper.ToRadians(180));

            BuilderDeadEndNode e2top    = new BuilderDeadEndNode(940, 50, MathHelper.ToRadians(0));
            BuilderDeadEndNode e2right  = new BuilderDeadEndNode(1310, 415, MathHelper.ToRadians(90));
            BuilderDeadEndNode e2bottom = new BuilderDeadEndNode(940, 780, MathHelper.ToRadians(180));

            CityBuilderParkingTwoLanePath connection = new CityBuilderParkingTwoLanePath(i1, i2);

            i1.right = connection;
            i2.left  = connection;

            CityBuilderParkingTwoLanePath i1top = new CityBuilderParkingTwoLanePath(i1, e1top);

            i1.top = i1top;
            CityBuilderParkingTwoLanePath i1left = new CityBuilderParkingTwoLanePath(i1, e1left);

            i1.left = i1left;
            CityBuilderParkingTwoLanePath i1bottom = new CityBuilderParkingTwoLanePath(i1, e1bottom);

            i1.bottom = i1bottom;

            CityBuilderParkingTwoLanePath i2right = new CityBuilderParkingTwoLanePath(i2, e2right);

            i2.right = i2right;
            CityBuilderParkingTwoLanePath i2top = new CityBuilderParkingTwoLanePath(i2, e2top);

            i2.top = i2top;
            CityBuilderParkingTwoLanePath i2bottom = new CityBuilderParkingTwoLanePath(i2, e2bottom);

            i2.bottom = i2bottom;

            builder.nodes.Add(i1);
            builder.nodes.Add(i2);
            builder.nodes.Add(e1top);
            builder.nodes.Add(e1left);
            builder.nodes.Add(e1bottom);
            builder.nodes.Add(e2right);
            builder.nodes.Add(e2top);
            builder.nodes.Add(e2bottom);
            builder.paths.Add(connection);
            builder.paths.Add(i1top);
            builder.paths.Add(i1bottom);
            builder.paths.Add(i1left);
            builder.paths.Add(i2right);
            builder.paths.Add(i2top);
            builder.paths.Add(i2bottom);
            city = builder.Build();

            Random r = new Random();

            foreach (CityNode n in city.nodes)
            {
                if (n is ParkingNode)
                {
                    //vehicles.Add(new GasolineCar(n));
                }
            }

            CityNode work1 = new CityNode(1200, 300);
            CityNode work2 = new CityNode(1100, 600);

            city.nodes.Add(work1);
            city.nodes.Add(work2);

            CityNode n1 = city.NearestNode(1200, 300, CityPathType.pedestrians);

            work1.Connect(n1, CityPathType.pedestrians);
            n1.Connect(work1, CityPathType.pedestrians);
            CityNode n2 = city.NearestNode(1100, 600, CityPathType.pedestrians);

            work2.Connect(n2, CityPathType.pedestrians);
            n2.Connect(work2, CityPathType.pedestrians);


            CityNode[] homes = new CityNode[]
            {
                new CityNode(250, 200),
                new CityNode(270, 300),
                new CityNode(120, 300),
                new CityNode(570, 100),
                new CityNode(570, 210),
                new CityNode(220, 560),
                new CityNode(550, 560),
                new CityNode(580, 700),
                new CityNode(750, 560),
                new CityNode(780, 720),
                new CityNode(780, 310),
                new CityNode(1080, 720),
                new CityNode(1080, 100),
            };

            foreach (CityNode home in homes)
            {
                city.nodes.Add(home);
                CityNode n = city.NearestNode((int)home.x, (int)home.y, CityPathType.pedestrians);
                home.Connect(n, CityPathType.pedestrians);
                n.Connect(home, CityPathType.pedestrians);

                CityNode park = City.ClosestParking(n);

                GasolineCar c = new GasolineCar(park);
                vehicles.Add(c);

                Commuter guy = new Commuter(home, home, r.Next(2) == 0 ? work1 : work2, c);
                debugObjects.Add(guy);
            }
        }