Beispiel #1
0
		public Model()
		{
			CrossingController = new CrossingController
			{
				Sensor = new BarrierSensor(),
				Motor = new BarrierMotor(),
				Radio = new RadioModule(),
				Timer = new Timer(),
				TrainSensor = new TrainSensor()
			};

			TrainController = new TrainController
			{
				Brakes = new Brakes(),
				Odometer = new Odometer(),
				Radio = new RadioModule()
			};

			Bind(nameof(Barrier.Speed), nameof(CrossingController.Motor.Speed));
			Bind(nameof(CrossingController.Sensor.BarrierAngle), nameof(Barrier.Angle));

			Bind(nameof(Train.Acceleration), nameof(TrainController.Brakes.Acceleration));
			Bind(nameof(CrossingController.TrainSensor.TrainPosition), nameof(Train.Position));

			Bind(nameof(TrainController.Radio.RetrieveFromChannel), nameof(Channel.Receive));
			Bind(nameof(TrainController.Radio.DeliverToChannel), nameof(Channel.Send));

			Bind(nameof(CrossingController.Radio.RetrieveFromChannel), nameof(Channel.Receive));
			Bind(nameof(CrossingController.Radio.DeliverToChannel), nameof(Channel.Send));

			Bind(nameof(TrainController.Odometer.TrainPosition), nameof(Train.Position));
			Bind(nameof(TrainController.Odometer.TrainSpeed), nameof(Train.Speed));
		}
Beispiel #2
0
    /// <summary>
    /// Spawns a consist on a track section
    /// </summary>
    /// <param name="startSection"></param>
    /// <returns>The lead car of this consist</returns>
    public TrainController Spawn(TrackSection startSection)
    {
        Driver driverInstance = null;

        if (driver != null)
        {
            driverInstance = GameObject.Instantiate(driver.gameObject).GetComponent <Driver>();
        }

        TrainController controller;
        TrainController previous = null;
        TrainController lead     = null;

        TrackSection currentSection;

        currentSection = startSection;
        // Spawn from the end of the track
        float spawnPosition = currentSection.length - 10.0f;

        // Spawn vehicles front to back
        for (int i = 0; i < vehicles.Length; i++)
        {
            controller = GameObject.Instantiate(vehicles[i].vehicleController.gameObject).GetComponent <TrainController>();
            //TODO: TrackVehicle facing directions works but gets ignored by driving logic, e.g. it's only visual.
            controller.trackVehicle = new TrackVehicle(currentSection, spawnPosition, Direction.Forward, vehicles[i].faceDirection, controller.length, controller.wheelBase);

            if (i == 0)
            {
                lead = controller;
            }

            // Add engines to driver if we have one
            TrainEngineController engine = controller as TrainEngineController;
            if (engine != null && driverInstance != null)
            {
                driverInstance.AddEngine(engine);
            }

            if (previous != null)
            {
                previous.next       = controller;
                controller.previous = previous;

                //Move ourselfs back on the track
                controller.trackVehicle.SetDirection(Direction.Reverse);
                controller.trackVehicle.Move(controller.length * 0.5f + previous.length * 0.5f);
                controller.trackVehicle.SetDirection(Direction.Forward);
                //Change spawn position to our new location
                spawnPosition -= controller.length * 0.5f + previous.length * 0.5f;
            }
            previous = controller;
        }

        if (driverInstance != null)
        {
            driverInstance.RecalculateTrain();
        }

        return(lead);
    }
    void OnTrainDied(TrainController train)
    {
        if (playerTrain == null)
        {
            return;
        }

        trainsInScene.Remove(train);

        if (train == playerTrain)
        {
            GameOverSequence();
            return;
        }

        if (trainsInScene.Count == 1)
        {
            TrainController lastTrain = trainsInScene[0];
            if (lastTrain == playerTrain)
            {
                VictorySequence();
            }
            else
            {
                GameOverSequence();
            }
        }
    }
Beispiel #4
0
        public Model()
        {
            CrossingController = new CrossingController
            {
                Sensor      = new BarrierSensor(),
                Motor       = new BarrierMotor(),
                Radio       = new RadioModule(),
                Timer       = new Timer(),
                TrainSensor = new TrainSensor()
            };

            TrainController = new TrainController
            {
                Brakes   = new Brakes(),
                Odometer = new Odometer(),
                Radio    = new RadioModule()
            };

            Bind(nameof(Barrier.Speed), nameof(CrossingController.Motor.Speed));
            Bind(nameof(CrossingController.Sensor.BarrierAngle), nameof(Barrier.Angle));

            Bind(nameof(Train.Acceleration), nameof(TrainController.Brakes.Acceleration));
            Bind(nameof(CrossingController.TrainSensor.TrainPosition), nameof(Train.Position));

            Bind(nameof(TrainController.Radio.RetrieveFromChannel), nameof(Channel.Receive));
            Bind(nameof(TrainController.Radio.DeliverToChannel), nameof(Channel.Send));

            Bind(nameof(CrossingController.Radio.RetrieveFromChannel), nameof(Channel.Receive));
            Bind(nameof(CrossingController.Radio.DeliverToChannel), nameof(Channel.Send));

            Bind(nameof(TrainController.Odometer.TrainPosition), nameof(Train.Position));
            Bind(nameof(TrainController.Odometer.TrainSpeed), nameof(Train.Speed));
        }
Beispiel #5
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MyDbContext     context         = new MyDbContext();
                TrainController trainController = new TrainController();
                Train           train           = new Train(txtTrainType.Text, txtNumberTrain.Text);

                if (trainController.AddTrain(train))
                {
                    MessageBox.Show("Поезд успешно добавлен.");
                    TrainDataGrid.ClearValue(ItemsControl.ItemsSourceProperty);
                    List <Train> trains = context.Trains.ToList();
                    TrainDataGrid.ItemsSource = trains;
                }
                else
                {
                    MessageBox.Show("Этот поезд уже существует или введенные данные имеют неверный формат.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    void OnTriggerEnter(Collider other)
    {
        TrainController train = other.GetComponent <TrainController>();

        if (train != null)
        {
            train.GoToNextTarget();

            /*
             * float horizontalAxis =                       Input.GetAxis("Horizontal");
             * RotationalWaypoint nextWaypoint =            null;
             *
             * if (horizontalAxis < 0 && leftPoint != null)
             *      nextWaypoint =                          leftPoint;
             * else if (horizontalAxis > 0 && rightPoint != null)
             *      nextWaypoint =                          rightPoint;
             * else
             *      nextWaypoint =                          forwardPoint;
             *
             * train.waypointTarget =                       nextWaypoint;
             */
        }

        /*
         * Transform otherTrans =           other.transform;
         *
         * Vector3 rotToApply = transform.rotation.eulerAngles;
         * rotToApply.y -=              90;
         *
         * otherTrans.rotation =            Quaternion.Euler(rotToApply);
         */
        //PlayerMovement pm = other.GetComponent<PlayerMovement>();
        //pm.HandleAutomaticMovement();
    }
    public Transform left; // reference to the left edge transform of the track tile

    /// <summary>
    /// on trigger enter
    /// </summary>
    /// <param name="other"></param>
    void OnTriggerEnter(Collider other)
    {
        if (trainPassingTransform == true) // if the bool for train passing transform is true
        {
            return; // exit

        }
        if (other.CompareTag("Train")) // if the object colliding with us is tagged Train
        {
            TrainController script = other.gameObject.GetComponent<TrainController>(); // access the game object and get the train controller script from it (saves us having to assign manually)

            if (script != null && script.previousTarget != right) // if the train controller's previous target was not the right transform
            {
                script.previousTarget = left; // set the previous target on the train controller script to the left transform
                script.currentTarget = right; // set the current target on the train controller script to the right transform of the track tile
                trainPassingTransform = true; // set the train passing transform bool to true
            }
            if (script != null && script.previousTarget == right) // if the previous target on the train controller script is the right transform
            {
                script.previousTarget = left; // set the previous target on the train controller script to the left transform
                trainPassingTransform = true; // set the train passing transform bool to true
                if (closestEdge != null)
                {
                    script.currentTarget = closestEdge; // set the current target on the train controller script to the closest edge transform of the track tile
                }
            }
        }

        if (other.CompareTag("TrackEdge")) // if the thing colliding with us is tagged TrackEdge
        {
            closestEdge = other.transform; // set the closest edge transform to the transform of the object that just collided with us.
            hapticsController.trackConnected = true; // set the bool for track connected to true on the  haptics controller script
            hapticsController.PlayTrackConnectionClip(); // call the function to play the track connection clip fom the haptics controller script
        }
    }
Beispiel #8
0
    void LateUpdate()
    {
        if (target)
        {
            if (Input.GetMouseButton(1))
            {
                x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
                y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

                y = ClampAngle(y, yMinLimit, yMaxLimit);
            }
            distance -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;

            Quaternion rotation = Quaternion.Euler(y, x + target.eulerAngles.y, 0);
            Vector3    position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position + Vector3.up;

            transform.rotation = rotation;
            transform.position = position;
            //TRAINS
            //Code to move along the train
            TrainController train = target.GetComponent <TrainController>();
            if (train != null)
            {
                if (Input.GetKeyDown(KeyCode.LeftArrow) && train.next != null)
                {
                    target = train.next.transform;
                }
                else if (Input.GetKeyDown(KeyCode.RightArrow) && train.previous != null)
                {
                    target = train.previous.transform;
                }
            }
        }
    }
        public void Index_Without_TrainName_Test()
        {
            // Arrange
            var data = new List <Train>()
            {
                new Train()
                {
                    TrainId = 1, TrainName = "WXG-123"
                },
                new Train()
                {
                    TrainId = 2, TrainName = "XYZ-543"
                }
            }.AsQueryable();

            var mockSet = Substitute.For <DbSet <Train>, IQueryable <Train> >();

            ((IQueryable <Train>)mockSet).Provider.Returns(data.Provider);
            ((IQueryable <Train>)mockSet).Expression.Returns(data.Expression);
            ((IQueryable <Train>)mockSet).ElementType.Returns(data.ElementType);
            ((IQueryable <Train>)mockSet).GetEnumerator().Returns(data.GetEnumerator());

            var db = Substitute.For <WebPayment>();

            db.Train.Returns(mockSet);

            var sut = new TrainController(db);

            // Act
            var result = sut.Index(null) as ViewResult;
            var actual = result.Model as List <Train>;

            // Assert
            Assert.Equal(2, actual.Count);
        }
        public void Index_With_TrainName_Test()
        {
            // Arrange
            var data = new List <Train>()
            {
                new Train()
                {
                    TrainId = 1, TrainName = "WXG-123"
                },
                new Train()
                {
                    TrainId = 2, TrainName = "XYZ-543"
                }
            }.AsQueryable();

            var trainMockSet = Substitute.For <DbSet <Train>, IQueryable <Train> >();

            WireUpTheIQueryableImplementation(trainMockSet, data);

            var db = Substitute.For <WebPayment>();

            db.Train.Returns(trainMockSet);

            var sut = new TrainController(db);

            // Act
            var result = sut.Index("123") as ViewResult;
            var actual = result.Model as List <Train>;

            // Assert
            Assert.Single(actual);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            Console.Clear();
            TrainController tc = new TrainController();

            tc.Run();
        }
        public void Create_With_Invalid_Model_Test()
        {
            // Arrange
            var db           = Substitute.For <WebPayment>();
            var trainMockSet = Substitute.For <DbSet <Train> >();

            db.Train.Returns(trainMockSet);

            var sut = new TrainController(db);

            sut.ModelState.AddModelError("TrainName", "請輸入火車名稱");
            var train = new Train()
            {
                TrainId = 3, TrainName = "ZZZ-555"
            };
            var expected = new { TrainId = 3, TrainName = "ZZZ-555" };

            // Act
            var result = sut.Create(train) as ViewResult;

            // Assert
            db.Train.DidNotReceiveWithAnyArgs().Add(new Train());
            db.DidNotReceiveWithAnyArgs().SaveChanges();
            Assert.NotNull(result.ViewBag.TrainTypeList);
            expected.ToExpectedObject().ShouldMatch(result.Model);
        }
Beispiel #13
0
    public void SpawnTrain()
    {
        TrainController trainScript = (TrainController)EnemyTrain.GetComponent(typeof(TrainController));

        trainScript.gameState = gameState;
        Instantiate(EnemyTrain, new Vector3(transform.position.x + (float)Mathf.Cos(-(transform.eulerAngles.y - 90) * Mathf.PI / 180), transform.position.y + 2.5f, transform.position.z + (float)Mathf.Sin(-(transform.eulerAngles.y - 90) * Mathf.PI / 180)), Quaternion.Euler(270, transform.eulerAngles.y + 90, 0));
    }
    void FixedUpdate()
    {
        if (!parent.running)
        {
            return;
        }

        if (cooldown <= 0)
        {
            TrainController tc = Instantiate(trainPrefab, transform.position, Quaternion.identity);
            tc.transform.parent = parent.terrainObject.transform;
            tc.parent           = parent;
            tc.direction        = direction;
            tc.squirrel         = squirrel;
            tc.SetFlip();

            cooldown = 210 - Random.Range(0, 70);
        }
        cooldown -= 1;

        if (transform.position.x < -1)
        {
            Destroy(gameObject);
        }
    }
Beispiel #15
0
    /// <summary>
    /// Updates internal list of train vehicles.
    /// </summary>
    public void RecalculateTrain()
    {
        HashSet <TrainController> uniqueVehicles = new HashSet <TrainController>();

        if (Engines.Count > 0)
        {
            TrainController vehicle = Engines[0];
            uniqueVehicles.Add(vehicle);
            while (vehicle.next != null)
            {
                vehicle = vehicle.next;
                uniqueVehicles.Add(vehicle);
            }
            vehicle = Engines[0];
            while (vehicle.previous != null)
            {
                vehicle = vehicle.previous;
                uniqueVehicles.Add(vehicle);
            }
        }
        foreach (TrainController vehicle in trainVehicles)
        {
            vehicle.driver = null;
        }

        trainVehicles.Clear();
        trainVehicles.AddRange(uniqueVehicles);

        foreach (TrainController vehicle in uniqueVehicles)
        {
            vehicle.driver = this;
        }
    }
    public Transform left;   // reference to the left edge transform of the track tile

    void OnTriggerEnter(Collider other)
    {
        //if (trainPassingTransform == true)
        //{
        //return;

        //}
        if (other.CompareTag("Train"))
        {
            TrainController script = other.gameObject.GetComponent <TrainController>();

            if (script.previousTarget == left)
            {
                script.previousTarget = centre;
                script.currentTarget  = right;
            }

            if (script.previousTarget != left)
            {
                script.previousTarget = centre;
                script.currentTarget  = left;
                //trainPassingTransform = true;
            }
        }
    }
Beispiel #17
0
 void Awake()
 {
     m_train              = GetComponent <TrainController>();
     m_source             = GetComponent <AudioSource>();
     m_source.playOnAwake = false;
     m_source.loop        = true;
     m_source.clip        = m_clip;
 }
    /// <summary>
    /// Detects collisions between trains
    /// </summary>
    /// <param name="collision"></param>
    void OnTriggerStay(Collider other)
    {
        TrainController tc = other.gameObject.GetComponent <TrainController>();

        if (tc != null)
        {
            OnCollisionDetected(tc);
        }
    }
        private bool configSendMail(IdentityMessage message)
        {
            var subject     = message.Subject;
            var body        = message.Body;
            var destination = message.Destination;

            //
            return(TrainController.SendEmailImplicitSsl(destination, subject, body));
        }
    public void SetRotation(int Id, Vector3 fwd)
    {
        TrainController controller = GetController(Id);

        if (controller != null)
        {
            controller.train.transform.forward = fwd;
        }
    }
Beispiel #21
0
    void Start()
    {
        #region init
        _trainController = new TrainController();
        _railGrid        = GetComponent <RailGridController>();
        #endregion

        _trainSpawner.SpawnTrain(5);
    }
Beispiel #22
0
    public void SpawnDemoConsists()
    {
        TrainController leadCar = consist.Spawn(TrackCollection.instance.Get(1));

        trains.Add(leadCar);

        leadCar = consist2.Spawn(TrackCollection.instance.Get(15));
        trains.Add(leadCar);
    }
 // Use this for initialization
 void Start()
 {
     train_placeholder = GameObject.Find("train_placeholder");
     moveTrain         = train_placeholder.GetComponent <TrainController>();
     if (train_placeholder == null)
     {
         Debug.Log("moveTrain is null");
     }
 }
        private ListViewItem createListViewItem(TrainController tc)
        {
            ListViewItem lvi = new ListViewItem(new string[] {
                tc.name, tc.contribution.name
            });

            lvi.Tag = tc;
            return(lvi);
        }
        public void VelocityControllerTest()
        {
            TrackBlock               startingBlock     = new TrackBlock("Block1", TrackOrientation.EastWest, new Point(123, 456), 100, 50, 1, true, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "previousBlock", "nextBlock");
            ITrain                   myTrain           = new Train("train1", startingBlock, Direction.East);
            TrainController          myTrainController = new TrainController(myTrain);
            PrivateObject            param0            = new PrivateObject(myTrainController);
            TrainController_Accessor target            = new TrainController_Accessor(param0);

            int lastCommand = 0;

            target.m_powerCommand = 200000;
            target.m_brakeFailure = true;

            lastCommand = target.VelocityController();

            Assert.AreEqual(1, lastCommand);
            Assert.AreEqual(200000, target.m_powerCommand);

            target.EmergencyBrake = true;
            target.m_brakeFailure = false;

            lastCommand = target.VelocityController();

            Assert.AreEqual(1, lastCommand);
            Assert.AreEqual(200000, target.m_powerCommand);

            target.EmergencyBrake       = false;
            target.m_currentIntegral    = 0;
            target.m_currentSample      = 0;
            target.m_setPoint           = 0;
            target.m_currentState.Speed = 0;

            lastCommand = target.VelocityController();

            Assert.AreEqual(0, lastCommand);
            Assert.AreEqual(0.0, target.m_lastIntegral);
            Assert.AreEqual(0.0, target.m_lastSample);
            Assert.AreEqual(0.0, target.m_currentSample);
            Assert.AreEqual(0.0, target.m_powerCommand);

            target.m_powerCommand       = 200000;
            target.m_currentState.Speed = 100;

            lastCommand = target.VelocityController();

            Assert.AreEqual(2, lastCommand);
            Assert.AreEqual(-100.0, target.m_currentSample);
            Assert.AreEqual(200000, target.m_powerCommand);

            target.m_setPoint           = 15;
            target.m_currentState.Speed = 0;
            lastCommand = target.VelocityController();

            Assert.AreEqual(3, lastCommand);
            Assert.AreEqual(120000, target.m_powerCommand);
        }
Beispiel #26
0
        public void Index()
        {
            // Arrange
            TrainController controller = new TrainController();

            // Act
            ViewResult result = controller.SearchTrains() as ViewResult;

            // Assert
            Assert.AreEqual("Modify this template to jump-start your ASP.NET MVC application.", result.ViewBag.Message);
        }
Beispiel #27
0
        public void Contact()
        {
            // Arrange
            TrainController controller = new TrainController();

            // Act
            ViewResult result = controller.Contact() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Beispiel #28
0
        /// <summary>
        /// Gets a reference to the train controller of the train
        /// </summary>
        /// <param name="train"></param>
        /// <returns></returns>
        public TrainController GetTrainController(ITrain train)
        {
            TrainController controller = null;

            if (m_trainControllerTable.ContainsKey(train))
            {
                controller = m_trainControllerTable[train];
            }

            return(controller);
        }
    public void OnDerail(object o, EventArgs e)
    {
        if (isDerailed)
        {
            return;
        }

        if (previous != null)
        {
            if (previous.previous == this)
            {
                previous.previous = null;
            }
            else if (previous.next == this)
            {
                previous.next = null;
            }
            previous = null;
        }
        if (next != null)
        {
            if (next.previous == this)
            {
                next.previous = null;
            }
            else if (next.next == this)
            {
                next.next = null;
            }
            next = null;
        }

        BoxCollider b = GetComponentInChildren <BoxCollider>();

        if (b != null)
        {
            b.isTrigger = false;
        }

        Rigidbody r = GetComponentInChildren <Rigidbody>();

        if (r != null)
        {
            r.isKinematic = false;
            r.useGravity  = true;
            r.mass        = mass;
            r.velocity    = CalculateVelocityVector();
        }

        Debug.Log("Train Derailed!");
        driver = null;

        isDerailed = true;
    }
Beispiel #30
0
 private void SetLevel()
 {
     train = GameObject.FindGameObjectWithTag("Train").GetComponent <TrainController>();
     if (GameObject.FindGameObjectWithTag("UI") != null)
     {
         ui = GameObject.FindGameObjectWithTag("UI").GetComponent <UIManager>();
     }
     isBroken   = false;
     freeCamera = true;
     isComplete = false;
 }
        public void SpeedTest()
        {
            TrackBlock               startingBlock     = new TrackBlock("Block1", TrackOrientation.EastWest, new Point(123, 456), 100, 50, 1, true, false, 70, TrackAllowedDirection.Both, false, "controller1", "controller2", "previousBlock", "nextBlock");
            ITrain                   myTrain           = new Train("train1", startingBlock, Direction.East);
            TrainController          myTrainController = new TrainController(myTrain);
            PrivateObject            param0            = new PrivateObject(myTrainController);
            TrainController_Accessor target            = new TrainController_Accessor(param0);

            target.m_currentState.Speed = 10.0;

            Assert.AreEqual(36.0, target.Speed);
        }
Beispiel #32
0
 private UILabel appkeyLabel;    //用来接收用户输入的appkey
 void Start()
 {
     //获得引用,赋值等操作,并将一开始不显示的组件隐藏
     trainController = TrainController.GetInstance();
     query.SetActive(false);
     trainInfoShow.SetActive(false);
     stationInfoShow.SetActive(false);
     backButton.gameObject.SetActive(false);
     nextButton.gameObject.SetActive(false);
     errorShow.SetActive(false);
     trainLabel = trainInfoShow.transform.FindChild("TrainLabel").GetComponent<UITextList>();
     stationLabel = stationInfoShow.transform.FindChild("StationLabel").GetComponent<UITextList>();
     errorLabel = errorShow.transform.FindChild("ErrorLabel").GetComponent<UILabel>();
     appkeyLabel = appkey.transform.FindChild("AppKeyInput Field/Label").GetComponent<UILabel>();
     stationModelsList = new List<StationModel>();
 }