Inheritance: MonoBehaviour
Beispiel #1
0
        static List <FarmAnimal> ProcessInputFile(string inFileName)
        {
            List <FarmAnimal> animals = new List <FarmAnimal>();

            using (StreamReader sr = new StreamReader(inFileName))
            {
                while (!sr.EndOfStream)
                {
                    string   line    = sr.ReadLine();
                    string[] details = line.Split("|");

                    FarmAnimal newAnimal;
                    switch (details[1])
                    {
                    case "Elephant": newAnimal = new Elephant(); break;

                    case "Goat": newAnimal = new Goat(); break;

                    default: newAnimal = new Goat(); break;
                    }

                    newAnimal.Name = details[0];
                    string[] food = details[2].Split(", ");
                    foreach (string f in food)
                    {
                        newAnimal.Food.Add(f);
                    }
                    animals.Add(newAnimal);
                }
            }
            return(animals);
        }
Beispiel #2
0
        public void OnGet()
        {
            Goats = new List <Goat>();

            // This is a terrible/primitive way to get data from a database, but it works
            // Please do not write code like this. Thanks
            using (conn = new SqlConnection(config.GetConnectionString("MainDatabase")))
            {
                try
                {
                    conn.Open();
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "SELECT * from products";
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Goat goat = new Goat();
                        goat.Id          = reader.GetInt32(0);
                        goat.Name        = reader.GetString(1);
                        goat.Description = reader.GetString(2);
                        goat.Image       = reader.GetString(3);
                        Goats.Add(goat);
                    }
                }
                finally
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
        }
Beispiel #3
0
        static void Main()
        {
            // Список левого берега
            // Список правого берега
            // Добавляем в левый берег объекты
            // Старт игры
            // Выбираем объект для перевозки
            // Помещаем его на лодку
            // Сравниваем все объекты на берегах
            // Если нет проблем, то перемещаем
            // Иначе игра завершается

            Cabbage cabbage = new Cabbage();

            Goat goat = new Goat();

            goat.WriteGameObjectThatCanEat(cabbage);

            Wolf wolf = new Wolf();

            wolf.WriteGameObjectThatCanEat(goat);

            GameObject[] gameObjects = new GameObject[] { cabbage, goat, wolf };
            Game         game        = new Game();

            game.LoadGameObjects(gameObjects);
            game.StartTheGame();
        }
        public void Delete_Goat_Test()
        {
            // arrange
            List <Goat> goats = new List <Goat>();
            var         goat  = new Goat()
            {
                GoatName = "Molly Mea", ID = 1
            };

            goats.Add(goat);
            const string NAME = "Maggie Sue";

            goat = new Goat()
            {
                GoatName = NAME, ID = 2
            };
            goats.Add(goat);

            var target = new GoatController(new FakeGoatRepository(goats));

            // act
            target.DeleteConfirmed(2);

            // assert
            Assert.AreEqual(1, goats.Count);
            Assert.AreNotEqual(NAME, goats[0].GoatName);
        }
    private static Goat GetProductionStatistics(string type)
    {
        var goat = new Goat();

        // Some processing...
        return(goat);
    }
Beispiel #6
0
    // Use this for initialization
    void Start()
    {
        //fishes.Initialize (new Vector3 (1000, -2, 1000), 10);
        //int fishCount = 5;
        int fishCount = 0;
        int goatCount = 0;
        int birdCount = 0;


        hm   = gen.heightMap;
        step = gen.step;

        int meshSide    = gen.meshSideLength;
        int featureSize = gen.featureSize;

        // positio in world space veector3 ( x * step, hm[x,z], z*step)

        //goats
        for (int x = 0; x < meshSide; x++)
        {
            for (int z = 0; z < meshSide; z++)
            {
                if (hm[x, z] >= 10f && Random.value < 0.01 && goatCount <= nbGoats)
                {
                    //spawn goats
                    Goat g = (Goat)(Instantiate(goat)) as Goat;
                    g.transform.position = new Vector3(x * step, hm[x, z] + 2f, z * step);
                    goatCount++;
                }
            }
        }
        //fishes
        while (fishCount <= nbFishSchools)
        {
            int x = Random.Range(0, meshSide);
            int z = Random.Range(0, meshSide);
            if (hm[x, z] < 0f)
            {
                //spawn fishes
                fishes.Initialize(new Vector3(x * step, -2, z * step), 5);
                fishCount++;
            }
        }


        //birds
        for (int x = 0; x < meshSide; x += featureSize)
        {
            for (int z = 0; z < meshSide; z += featureSize)
            {
                if (hm[x, z] > step && Random.value < 0.4 && birdCount <= nbFlocks)
                {
                    //spawn  birds
                    birds.Initialize(new Vector3(x * step, hm[x, z] + 10f, z * step), 4);
                    birdCount++;
                }
            }
        }
    }
Beispiel #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Goat goat = db.Goats.Find(id);

            db.Goats.Remove(goat);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void This_is_because_cows_and_goats_are_milkable()
        {
            IMilkable cow = new Cow(); //Cow IMPLEMENTS the IMilkable contract
            IMilkable goat = new Goat(); //Goat IMPLEMENTS the IMilkable contract

            // TODO Please remove the incorrect assertion.
            Assert.Throws<ThisIsntMilkableException>(() => cow.Milk());
            Assert.DoesNotThrow(() => goat.Milk());
        }
        public void This_is_because_cows_and_goats_are_milkable()
        {
            IMilkable cow  = new Cow();  //Cow IMPLEMENTS the IMilkable contract
            IMilkable goat = new Goat(); //Goat IMPLEMENTS the IMilkable contract

            // TODO Please remove the incorrect assertion.
            Assert.Throws <ThisIsntMilkableException>(() => cow.Milk());
            Assert.DoesNotThrow(() => goat.Milk());
        }
        public void The_same_farm_can_give_us_goats_milk_too()
        {
            var goat = new Goat();
            var farm = new DairyFarm(goat); //This is the essence of 'dependency injection'

            // TODO Please remove the incorrect assertion.
            Assert.That(farm.GetProduce(), Is.EqualTo("Cow's milk"));
            Assert.That(farm.GetProduce(), Is.EqualTo("Goat's milk"));
        }
        public void The_same_farm_can_give_us_goats_milk_too()
        {
            var goat = new Goat();
            var farm = new DairyFarm(goat); //This is the essence of 'dependency injection'

            // TODO Please remove the incorrect assertion.
            Assert.That(farm.GetProduce(), Is.EqualTo("Cow's milk"));
            Assert.That(farm.GetProduce(), Is.EqualTo("Goat's milk"));
        }
Beispiel #12
0
        public void PersonAttack()
        {
            var person = new Person();
            var goat   = new Goat();

            Assert.True(goat.IsAlive);
            person.Attack(goat);
            Assert.AreEqual(0, goat.HitPoints);
            Assert.False(goat.IsAlive);
        }
Beispiel #13
0
        public void SpeakTest()
        {
            //arrane
            Goat G = new Goat("Hilda");
            //act
            string talk = G.Speak();

            //assert
            Assert.AreEqual(talk, "I am Goat. Hear me Bahh");
        }
Beispiel #14
0
 public ActionResult Edit([Bind(Include = "GoatID,GoatName,GoatColor,GoatType,GoatGender")] Goat goat)
 {
     if (ModelState.IsValid)
     {
         db.Entry(goat).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(goat));
 }
Beispiel #15
0
        public void EatTest()
        {
            //arrange
            Goat G = new Goat("Henry");
            //act
            string snacks = G.Eat();

            //assert
            Assert.AreEqual(snacks, "Snackkks!!");  //this take two parameters
        }
Beispiel #16
0
        public ActionResult Create([Bind(Include = "GoatID,GoatName,GoatColor,GoatType,GoatGender")] Goat goat)
        {
            if (ModelState.IsValid)
            {
                db.Goats.Add(goat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(goat));
        }
Beispiel #17
0
        /// <summary>
        /// Загрузка объектов этой игры по умолчанию.
        /// </summary>
        public void LoadDefaultGameObjects()
        {
            Cabbage cabbage = new Cabbage();
            Goat    goat    = new Goat();

            goat.WriteGameObjectThatCanEat(cabbage);
            Wolf wolf = new Wolf();

            wolf.WriteGameObjectThatCanEat(goat);

            _gameObjects = new GameObject[] { cabbage, goat, wolf };
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            //build a farm
            Mouse   Cheryll  = new Mouse();
            Chicken Martha   = new Chicken();
            Goat    Spot     = new Goat();
            Sheep   Beatrice = new Sheep();

            Console.WriteLine("Hello and welcome to my farm!");
            Console.WriteLine("Let me introduce you to our animals");
            Console.WriteLine();
        }
Beispiel #19
0
 public PettingZooV20(Child aChild, string animalType)
 {
     TheChild = aChild;
     if (animalType == "Rabbit")
     {
         TheAnimal = new Rabbit("A white Rabbit");
     }
     else
     {
         TheAnimal = new Goat("Cute little Goat");
     }
 }
Beispiel #20
0
        // GET: Goat/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Goat goat = db.Goats.Find(id);

            if (goat == null)
            {
                return(HttpNotFound());
            }
            return(View(goat));
        }
        // GET: Goat/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Goat goat = repo.GetGoatByID((int)id);

            //Goat goat = db.Goats.Find(id);
            if (goat == null)
            {
                return(HttpNotFound());
            }
            return(View(goat));
        }
        public async Task CreateWithNoStream()
        {
            var serializer = new JsonEventSerializer(JsonSerializer.CreateDefault());
            var settings   = new VerifiableEventStoreSettings(serializer);
            var eventStore = new VerifiableEventStore(settings);

            var aggregate = Goat.Create("g047");
            await aggregate.CommitAsync(eventStore);

            eventStore.VerifyAppendToStream(aggregate, ExpectedVersion.NoStream, verify => verify
                                            .Event(GoatCreated.EventType, e =>
            {
                Assert.Equal("g047", e.Name);
            })
                                            );
        }
Beispiel #23
0
        private void SelectHero()
        {
            Console.WriteLine($"Select the hero{Environment.NewLine}1 - Rabbit{Environment.NewLine}2 - Duck{Environment.NewLine}3 - Goat");
            try
            {
                ConsoleKeyInfo entry = Console.ReadKey(intercept: true);
                switch (entry.Key)
                {
                case ConsoleKey.D1:
                {
                    PlayerHero = new Rabbit(100, new Point {
                            X = 1, Y = 1
                        });
                    break;
                }

                case ConsoleKey.D2:
                {
                    PlayerHero = new Duck(150, new Point {
                            X = 1, Y = 1
                        });
                    break;
                }

                case ConsoleKey.D3:
                {
                    PlayerHero = new Goat(125, new Point {
                            X = 1, Y = 1
                        });
                    break;
                }

                default:
                {
                    Console.WriteLine($"Invalid number");
                    SelectHero();
                    break;
                }
                }
            }
            catch (Exception)
            {
                Console.WriteLine($"Invalid number");
                SelectHero();
            }
        }
        private IAnimal CreateAnimal(int age)
        {
            IAnimal aRabbit = new Rabbit("A White Rabbit");
            IAnimal aGoat   = new Goat("A cute little Goat");

            if (age >= aGoat.AgeMinimum)
            {
                return(aGoat);
            }
            else if (age >= aRabbit.AgeMinimum)
            {
                return(aRabbit);
            }
            else
            {
                return(null);
            }
        }
        public void Create_Goat_Test()
        {
            // arrange
            List <Goat> goats  = new List <Goat>();
            var         target = new GoatController(new FakeGoatRepository(goats));

            // act
            const string NAME = "Molly Mea";
            var          goat = new Goat()
            {
                GoatName = NAME
            };

            target.Create(goat);

            // assert
            Assert.AreEqual(NAME, goats[0].GoatName);
        }
Beispiel #26
0
        public PettingZooV40(Child aChild)
        {
            TheChild = aChild;
            IAnimal aRabbit = new Rabbit("A White Rabbit");
            IAnimal aGoat   = new Goat("A cute little Goat");

            if (aChild.Age >= aGoat.AgeMinimum)
            {
                TheAnimal = aGoat;
            }
            else if (aChild.Age >= aRabbit.AgeMinimum)
            {
                TheAnimal = aRabbit;
            }
            else
            {
                //...?
            }
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            //I created a farm in the Main() method.  I did not include my
            //animal classes.  I couldn't find a way create a messase for
            //namespace that is missing.
            try
            {
                Animal dog = new Animal();
                dog.Speak();

                Horse horse = new Horse();
                horse.Speak();
                horse.Move();
                horse.Action();
                horse.Eat();
                Console.ReadKey();

                Goat goat = new Goat();
                goat.Speak();
                goat.Move();
                goat.Action();
                goat.Eat();
                Console.ReadKey();

                Pig pig = new Pig();
                pig.Speak();
                pig.Move();
                pig.Action();
                pig.Eat();
                Console.ReadKey();

                Chicken chicken = new Chicken();
                chicken.Speak();
                chicken.Move();
                chicken.Action();
                chicken.Eat();
                Console.ReadKey();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #28
0
        public void GoatAttack()
        {
            var person = new Person {
                HitPoints = 5
            };
            var goat = new Goat();

            Assert.True(goat.Attack(person));
            Assert.AreEqual(4, person.HitPoints);

            /*
             * arena
             * person attack goat
             * goat attack person
             * dodge, strength, hit points
             * level > threshold cant attack
             *
             */
        }
Beispiel #29
0
        private List <FarmAnimal> ProcessInputFile(string inFileName)
        {
            List <FarmAnimal> animals = new List <FarmAnimal>( );

            //open file for reading
            using (StreamReader sr = new StreamReader(inFileName))
            {
                while (!sr.EndOfStream)
                {
                    string   line    = sr.ReadLine();
                    string[] details = line.Split("|");

                    //create a farm animal for every line
                    //name | type|comma delimited list of what it eats

                    //details[0] => name, details[1] => type, details[2] => comma delimited listof food
                    FarmAnimal newAnimal; //declare up here so it's scoped to the while loop
                    switch (details[1])
                    {
                    case "Elephant": newAnimal = new Elephant(); break;

                    case "Goat": newAnimal = new Goat(); break;

                    case "Horse": newAnimal = new Horse(); break;

                    case "Snake": newAnimal = new Snake(); break;

                    default: newAnimal = new Elephant(); break;
                    }


                    newAnimal.Name = details[0];
                    string[] food = details[2].Split(",");
                    foreach (string f in food)
                    {
                        newAnimal.Food.Add(f);
                    }
                    animals.Add(newAnimal);
                }
            }
            return(animals);
        }
Beispiel #30
0
 private void buttonAdd_Click_Goat(object sender, EventArgs e)
 {
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         button3.Enabled = resetButton.Enabled = false;
         foreach (string url in openFileDialog.FileNames)
         {
             progressBar.Value = 0;
             Goat goat = Goat.load(url);
             animals.Add(goat);
             progressBar.PerformStep();
             listBox1.Items.Add("id= " + goat.getId().ToString());
             progressBar.PerformStep();
             loadGoat(goat);
         }
         MessageBox.Show("load complete");
         button3.Enabled    = resetButton.Enabled = true;
         this.ActiveControl = this.enterDataControl;
         txtButton.Enabled  = wordButton.Enabled = excelButton.Enabled = true;
     }
 }
Beispiel #31
0
        public IAnimal CreateAnimal(int age)
        {
            IAnimal aRabbit = new Rabbit("A white Rabbit");
            IAnimal aGoat   = new Goat("A cute little Goat");
            IAnimal aPony   = new Pony("Li'l Sebastian");

            if (age >= aPony.AgeMinimum)
            {
                return(aPony);
            }
            else if (age >= aGoat.AgeMinimum)
            {
                return(aGoat);
            }
            else if (age >= aRabbit.AgeMinimum)
            {
                return(aRabbit);
            }
            else
            {
                return(null);
            }
        }
        public async Task SetupAggregate_VerifyAppendToStream()
        {
            var serializer = new JsonEventSerializer(JsonSerializer.CreateDefault());
            var settings   = new VerifiableEventStoreSettings(serializer);
            var eventStore = new VerifiableEventStore(settings);

            var aggregate = Goat.Create("g047");

            aggregate.Rename("goatl");
            await aggregate.CommitAsync(eventStore);

            eventStore.VerifyAppendToStream(aggregate, ExpectedVersion.NoStream, verify => verify
                                            .Event(GoatCreated.EventType, e =>
            {
                Assert.Equal("g047", e.Name);
            })
                                            .Event(GoatRenamed.EventType, e =>
            {
                Assert.Equal("goatl", e.Name);
            })
                                            );

            var streamVersion = eventStore.CurrentVersion(aggregate);

            var retrieved = await Goat.FromAsync(eventStore, aggregate.Id);

            retrieved.Rename("meh");
            await retrieved.CommitAsync(eventStore);

            eventStore.VerifyAppendToStream(aggregate, streamVersion, verify => verify
                                            .Event(GoatRenamed.EventType, e =>
            {
                Assert.Equal("meh", e.Name);
            })
                                            );
        }
Beispiel #33
0
	void Awake(){
		instance = this;
	}