Пример #1
0
        public void ModifiedFirstExampleShouldWork()
        {
            using (StringWriter sw = new StringWriter())
            {
                TextWriter stdout = Console.Out;
                Console.SetOut(sw);
                Organism organism = new Organism(5, 10);
                Console.WriteLine(organism);
                organism.Move(-100, 50);
                Console.WriteLine(organism);
                organism.Move(500, 22);
                Console.WriteLine(organism);


                Console.SetOut(stdout);
                string example = "x: 5; y: 10\nx: -95; y: 60\nx: 405; y: 82\n";
                Assert.AreEqual(example, sw.ToString().Replace("\r\n", "\n"), "Moving an organism should move it!");
            }
        }
Пример #2
0
        public void FirstExampleShouldWork()
        {
            using (StringWriter sw = new StringWriter())
            {
                TextWriter stdout = Console.Out;
                Console.SetOut(sw);
                Organism organism = new Organism(20, 30);
                Console.WriteLine(organism);
                organism.Move(-10, 5);
                Console.WriteLine(organism);
                organism.Move(50, 20);
                Console.WriteLine(organism);


                Console.SetOut(stdout);
                string example = "x: 20; y: 30\nx: 10; y: 35\nx: 60; y: 55\n";
                Assert.AreEqual(example, sw.ToString().Replace("\r\n", "\n"), "The examples should work as such!");
            }
        }
Пример #3
0
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Vector3 screenPosition     = Camera.main.WorldToScreenPoint(organism.transform.position);
            Vector3 dependantDirection = Input.mousePosition - screenPosition;

            inputDirection = new Vector3(dependantDirection.x * (1f / (float)Screen.width), dependantDirection.y * (1f / (float)Screen.height));

            organism.Move(-inputDirection);
        }
        else if (Input.GetMouseButtonUp(0))
        {
            organism.Deactivate();
        }
    }
Пример #4
0
    void Update()
    {
        //decide position
        if (lastDecision + decisionFrequency < Time.time)
        {
            moveTarget = transform.localPosition + new Vector3(Random.Range(-5f, 5f),
                                                               Random.Range(-5f, 5f),
                                                               0);
            lastDecision = Time.time;
        }



        if (action == Action.idle)
        {
            pushVector = new Vector2(moveTarget.x - transform.localPosition.x,
                                     moveTarget.y - transform.localPosition.y);
        }
        organism.Move(pushVector);
    }