예제 #1
0
 private void swapButton_Click(object sender, EventArgs e)
 {
     var temp = lloyd;
     lloyd = lucinda;
     lucinda = temp;
     MessageBox.Show("Elephants were swapped");
 }
예제 #2
0
        public Form1()
        {
            InitializeComponent();

            lucinda = new Elephant() {EarSize = 33, Name = "Lucinda"};
            lloyd = new Elephant() {Name = "Lloyd", EarSize = 40};
        }
예제 #3
0
        public swap()
        {
            InitializeComponent();

            lucinda = new Elephant() { Name = "Lucinda", EarSize = 33};
            lloyd = new Elephant() { Name = "Lloyd", EarSize = 40 };
        }
예제 #4
0
        /// <summary>
        /// Constructor with one param: side
        /// side = 0: BLACK
        /// side = 1: RED
        /// </summary>
        /// <param name="side"></param>
        public Player(int side)
        {
            AdvisorPieces[0] = new Advisor();
            AdvisorPieces[1] = new Advisor();
            ElephantPieces[0] = new Elephant();
            ElephantPieces[1] = new Elephant();
            ChariotPieces[0] = new Chariot();
            ChariotPieces[1] = new Chariot();
            CannonPieces[0] = new Cannon();
            CannonPieces[1] = new Cannon();
            HorsePieces[0] = new Horse();
            HorsePieces[1] = new Horse();
            SoldierPieces[0] = new Soldier();
            SoldierPieces[1] = new Soldier();
            SoldierPieces[2] = new Soldier();
            SoldierPieces[3] = new Soldier();
            SoldierPieces[4] = new Soldier();

            if (side == 0) // BLACK
            {
                //Side = 0;
                KingPiece.Init(0, "KING", 0, 1, true, 0, 4);
                AdvisorPieces[0].Init(0, "ADVISOR", 0, 1, true, 0, 3);
                AdvisorPieces[1].Init(0, "ADVISOR", 1, 1, true, 0, 5);
                ElephantPieces[0].Init(0, "ELEPHANT", 0, 1, true, 0, 2);
                ElephantPieces[1].Init(0, "ELEPHANT", 1, 1, true, 0, 6);
                HorsePieces[0].Init(0, "HORSE", 0, 1, true, 0, 1);
                HorsePieces[1].Init(0, "HORSE", 1, 1, true, 0, 7);
                ChariotPieces[0].Init(0, "CHARIOT", 0, 1, true, 0, 0);
                ChariotPieces[1].Init(0, "CHARIOT", 1, 1, true, 0, 8);
                CannonPieces[0].Init(0, "CANNON", 0, 1, true, 2, 1);
                CannonPieces[1].Init(0, "CANNON", 1, 1, true, 2, 7);
                SoldierPieces[0].Init(0, "SOLDIER", 0, 1, true, 3, 0);
                SoldierPieces[1].Init(0, "SOLDIER", 1, 1, true, 3, 2);
                SoldierPieces[2].Init(0, "SOLDIER", 2, 1, true, 3, 4);
                SoldierPieces[3].Init(0, "SOLDIER", 3, 1, true, 3, 6);
                SoldierPieces[4].Init(0, "SOLDIER", 4, 1, true, 3, 8);
            }
            else    // RED
            {
                //Side = 1;
                KingPiece.Init(1, "KING", 0, 1, false, 9, 4);
                AdvisorPieces[0].Init(1, "ADVISOR", 0, 1, false, 9, 3);
                AdvisorPieces[1].Init(1, "ADVISOR", 1, 1, false, 9, 5);
                ElephantPieces[0].Init(1, "ELEPHANT", 0, 1, false, 9, 2);
                ElephantPieces[1].Init(1, "ELEPHANT", 1, 1, false, 9, 6);
                HorsePieces[0].Init(1, "HORSE", 0, 1, false, 9, 1);
                HorsePieces[1].Init(1, "HORSE", 1, 1, false, 9, 7);
                ChariotPieces[0].Init(1, "CHARIOT", 0, 1, false, 9, 0);
                ChariotPieces[1].Init(1, "CHARIOT", 1, 1, false, 9, 8);
                CannonPieces[0].Init(1, "CANNON", 0, 1, false, 7, 1);
                CannonPieces[1].Init(1, "CANNON", 1, 1, false, 7, 7);
                SoldierPieces[0].Init(1, "SOLDIER", 0, 1, false, 6, 0);
                SoldierPieces[1].Init(1, "SOLDIER", 1, 1, false, 6, 2);
                SoldierPieces[2].Init(1, "SOLDIER", 2, 1, false, 6, 4);
                SoldierPieces[3].Init(1, "SOLDIER", 3, 1, false, 6, 6);
                SoldierPieces[4].Init(1, "SOLDIER", 4, 1, false, 6, 8);
            }
        }
예제 #5
0
 private void button3_Click(object sender, EventArgs e)
 {
     Elephant holder;
     holder = lloyd;
     lloyd = lucinda;
     lucinda = holder;
     MessageBox.Show("Objects swaped");
 }
예제 #6
0
        private void button4_Click(object sender, EventArgs e)
        {
            lloyd.TellMe("Hi", lucinda);
            lloyd.SpeakTo(lucinda, "Hello");

            lloyd = lucinda;
            lloyd.EarSize = 4321;
            lloyd.WhoAmI();
        }
        public void TestSimple()
        {
            Elephant elephant = new Elephant() { Name = "Hanibal" };
            
            Debug.WriteLine("Transporting an elephant with SimpleTransportation...");
            new SimpleTransportation().TransportAnimal(elephant);

            Debug.WriteLine("Transporting an elephant with FlexibleTransportation...");
            new FlexibleTransportation().TransportAnimal(elephant);
        }
    static void Main()
    {
        Elephant e = new Elephant("Eli", 4500);
        Console.WriteLine(e.Weight);
        Console.WriteLine(e.Name);
        //e.Weight = 5000; //error - readonly field
        
        //constant:
        Console.WriteLine(Elephant.Size);

    } 
예제 #9
0
        public void WhenElephantTurnsFromC1ToD2_ThenItChangesCurrentPosition()
        {
            // Arrange
            // задаём слону стартовую позицию
            string   elephantStartPosition = "C1";
            string   elephantEndPosition   = "D2";
            Elephant elephant = new Elephant(elephantStartPosition);

            // Act and
            elephant.Turn(elephantEndPosition);

            //Assert
            // проверяем, что конструктор выкидывает ошибку, если клетка не C1
            Assert.Equal(elephantEndPosition, elephant.CurrentPosition);
        }
예제 #10
0
        public void FindPosibleWaysWithEnemies()
        {
            Elephant elephant      = new Elephant(new Position(5, 1), whitePlayer);
            var      elephantEnemy = new Elephant(new Position(4, 2), blackPlayer);

            map[4, 2] = elephantEnemy;
            var result   = elephant.FindPosibleWays(map);
            var expected = new[]
            {
                new Position(4, 0), new Position(6, 0), new Position(4, 2),
                new Position(6, 2), new Position(7, 3),
            };

            Assert.That(result.ToArray(), Is.EquivalentTo(expected));
        }
예제 #11
0
        public void FeedMeTest()
        {
            // Arrange
            var ellie = new Elephant();

            ellie.Health = 50f;
            float expected = 55f;
            float actual;

            // Act
            ellie.FeedMe(10);
            actual = ellie.Health;

            // Assert
            Assert.AreEqual(actual, expected);
        }
예제 #12
0
 public void updateOnFrame()
 {
     for (int i = elephants.Count - 1; i >= 0; i--)
     {
         if (elephants[i].shouldDieOfOldAge())
         {
             Elephant e = elephants[i];
             elephants.RemoveAt(i);
             Destroy(e.gameObject);
         }
         else
         {
             elephants[i].updatePosition();
         }
     }
 }
예제 #13
0
        public void FindPosibleWaysWithoutEnemies()
        {
            Elephant elephant = new Elephant(new Position(5, 1), whitePlayer);
            var      expected = new[]
            {
                new Position(4, 0), new Position(6, 0), new Position(4, 2),
                new Position(6, 2), new Position(3, 3), new Position(7, 3),
                new Position(2, 4), new Position(1, 5), new Position(0, 6)
            };

            map       = new IFigure[8, 8];
            map[5, 1] = elephant;
            var result = elephant.FindPosibleWays(map);

            Assert.That(result.ToArray(), Is.EquivalentTo(expected));
        }
예제 #14
0
    public void LandAirCraft(Transform airCraft)
    {
        heliObj = airCraft.gameObject;
        Sequence seq = DOTween.Sequence();

        seq.Append(airCraft.transform.DOMove(this.transform.position - new Vector3(0, 0.8f, 0), landTime).SetEase(easeType))
        .Join(airCraft.transform.DORotate(this.transform.eulerAngles, landTime).SetEase(easeType));
        wingRotate.slowingDown = true;
        //heliObj.transform.eulerAngles = new Vector3(0, 180, 0);
        animateHeli.enabled = false;
        wingRotate.winGame  = true;
        joyCon.CloseAllAlerts();
        Elephant.LevelCompleted(PlayerPrefs.GetInt("Level"));

        Invoke(nameof(RestartScene), 7f);
    }
예제 #15
0
        public IAnimal CreateAnimal(AnimalType animalType)
        {
            IAnimal animal = null;

            switch (animalType)
            {
            case AnimalType.Shark:
                animal = new Shark();
                break;

            case AnimalType.Elephant:
                animal = new Elephant();
                break;
            }
            return(animal);
        }
예제 #16
0
        public void RetardTest()
        {
            // Arrange
            var ellie = new Elephant();

            ellie.Health = 50f;
            float expected = 45f;
            float actual;

            // Act
            ellie.Retard(10);
            actual = ellie.Health;

            // Assert
            Assert.AreEqual(actual, expected);
        }
예제 #17
0
 public override void AddPieceTypes()
 {
     //	Add in all types from Shatranj
     base.AddPieceTypes();
     //	Upgrade the Elephant with non-capturing Dababbah move
     Elephant.StepMoveOnly(new Direction(2, 0));
     Elephant.StepMoveOnly(new Direction(-2, 0));
     Elephant.StepMoveOnly(new Direction(0, 2));
     Elephant.StepMoveOnly(new Direction(0, -2));
     Elephant.MidgameValue = 165;
     Elephant.EndgameValue = 165;
     //	Add the Silver General
     AddPieceType(SilverGeneral = new SilverGeneral("Silver General", "S", 285, 285));
     //	Change value of Rook
     Rook.MidgameValue = 500;
     Rook.EndgameValue = 550;
 }
예제 #18
0
        public void FindPosibleWaysWithEnemies()
        {
            Elephant elephant1 = new Elephant(new Position(1, 2), whitePlayer);
            Elephant elephant2 = new Elephant(new Position(3, 2), whitePlayer);
            Pawn     pawn      = new Pawn(new Position(2, 1), blackPlayer);

            map[1, 2] = elephant1;
            map[3, 2] = elephant2;
            map[2, 1] = pawn;
            var result   = pawn.FindPosibleWays(map);
            var expected = new[]
            {
                new Position(1, 2), new Position(3, 2), new Position(2, 2), new Position(2, 3)
            };

            Assert.That(result.ToArray(), Is.EquivalentTo(expected));
        }
예제 #19
0
        // GET: PetAnimals
        public ActionResult Index()
        {
            Lion     lion     = new Lion("Lion Name", 6, "Male");
            Tiger    tiger    = new Tiger("Tiger Name", 4, "Female");
            Elephant elephant = new Elephant("Elephant Name", 9, "Female");
            Zebra    zebra    = new Zebra("Zebra Name", 8, "Male");
            Monkey   monkey   = new Monkey("Monkey", 45, "Male");

            List <AnimalsViewModel> obj = new List <AnimalsViewModel>();

            obj.Add(new AnimalsViewModel(zebra.Name, zebra.Count, zebra.GenderType));
            obj.Add(new AnimalsViewModel(monkey.Name, monkey.Count, monkey.GenderType));
            obj.Add(new AnimalsViewModel(lion.Name, lion.Count, lion.GenderType));
            obj.Add(new AnimalsViewModel(tiger.Name, tiger.Count, tiger.GenderType));
            obj.Add(new AnimalsViewModel(elephant.Name, elephant.Count, elephant.GenderType));
            return(View(obj));
        }
예제 #20
0
        public async Task Get_ReturnsNullWhenIdIsNotFound()
        {
            var      inputId          = "67890";
            Elephant elephantResult   = null;
            var      mockElephantRepo = new Mock <IElephantRepo>();

            mockElephantRepo.Setup(x => x.Get(inputId)).ReturnsAsync(
                elephantResult
                );

            ElephantService _tests = new ElephantService(mockElephantRepo.Object);

            var result = await _tests.Get(inputId);

            Assert.Null(result);
            mockElephantRepo.VerifyAll();
        }
예제 #21
0
        static void Main(string[] args)
        {
            // Создание объектов классов животных
            Animal sova          = new Bird(1, "Плотоядное", "Самка", "Сова", 2.3);
            Animal asianElephant = new Elephant(3, "Травоядное", "Самец", "Индийский слон", 4.9);
            Animal bulldog       = new Dog(4, "Плотоядное", "Самец", "Бульдог", "Английский бульдог");

            // Инициализация массива состоящего из этих объектов
            Animal[] myZoo = new Animal[] { sova, asianElephant, bulldog };

            // Вывод данных об этих объектах
            for (int i = 0; i < myZoo.Length; i++)
            {
                Console.WriteLine(myZoo[i]);
                Console.WriteLine(myZoo[i].move());
                Console.WriteLine();
            }
        }
예제 #22
0
    private void SortSpeciesName(List <Animal> list)
    {
        Sort(zAnimal);
        Console.WriteLine("Pick the species you want to sort by: Tiger, Elephant or Owl.");
        string input = Console.ReadLine().ToLower();
        int    count = 0;

        if (input == "owl")
        {
            foreach (Animal anim in zAnimal)
            {
                if (anim is Owl)
                {
                    Owl temp = anim as Owl;
                    Console.WriteLine("ID: " + zAnimal[count].Id + ", Species: " + zAnimal[count] + ", Name: " + zAnimal[count].Name + ", Weight: " + zAnimal[count].Weight + ", Age: " + zAnimal[count].Age + ", Wingspan: " + temp.Wingspan + "cm");
                }
                count++;
            }
        }
        if (input == "tiger")
        {
            foreach (Animal anim in zAnimal)
            {
                if (anim is Tiger)
                {
                    Tiger temp = anim as Tiger;
                    Console.WriteLine("ID: " + zAnimal[count].Id + ", Species: " + zAnimal[count] + ", Name: " + zAnimal[count].Name + ", Weight: " + zAnimal[count].Weight + ", Age: " + zAnimal[count].Age);
                }
                count++;
            }
        }
        if (input == "elephant")
        {
            foreach (Animal anim in zAnimal)
            {
                if (anim is Elephant)
                {
                    Elephant temp = anim as Elephant;
                    Console.WriteLine("ID: " + zAnimal[count].Id + ", Species: " + zAnimal[count] + ", Name: " + zAnimal[count].Name + ", Weight: " + zAnimal[count].Weight + ", Age: " + zAnimal[count].Age + ", Trunk length: " + temp.TrunkLength + "cm");
                }
                count++;
            }
        }
    }
예제 #23
0
        public void FindPosibleWaysWithEnemies()
        {
            var      map           = new Map();
            Elephant elephantWhite = new Elephant(new Position(3, 4), whitePlayer);
            Elephant elephantBlack = new Elephant(new Position(1, 0), blackPlayer);
            Horse    horseWhite    = new Horse(new Position(2, 2), whitePlayer);
            var      expected      = new[]
            {
                new Position(1, 0), new Position(0, 1), new Position(3, 0), new Position(4, 1),
                new Position(0, 3), new Position(1, 4), new Position(4, 3)
            };

            map[3, 4] = elephantWhite;
            map[1, 0] = elephantBlack;
            map[2, 2] = horseWhite;
            var result = horseWhite.FindPosibleWays(map);

            Assert.That(result.ToArray(), Is.EquivalentTo(expected));
        }
예제 #24
0
    private void CreateElephantBodies()
    {
        if (elephantList != null)
        {
            for (int i = 0; i < elephantList.Count; i++)
            {
                GameObject.Destroy(elephantList[i].gameObject); //Es carrega tots els boomerangs existents
            }
        }

        elephantList = new List <Elephant>();
        //Itera per crear tots els nous boo merangs
        for (int i = 0; i < elephantpopulationSize; i++)
        {
            Elephant boomer = ((GameObject)Instantiate(elephantPrefab, new Vector3(UnityEngine.Random.Range(-60f, 60f), 0, UnityEngine.Random.Range(-40f, 40f)), elephantPrefab.transform.rotation)).GetComponent <Elephant>(); //Crea un boomerang i en pilla el punter a la mateix linia
            //boomer.Init(elephantnets[i], rabbitVector); //Valors inicials del boomerang, com la neural net que usa o on esta l'hexagon
            elephantList.Add(boomer);
        }
    }
예제 #25
0
        public void FindPosibleWaysWithEnemies()
        {
            var      map      = new Map();
            King     king     = new King(new Position(2, 2), whitePlayer);
            Elephant elephant = new Elephant(new Position(3, 1), whitePlayer);
            Pawn     pawn     = new Pawn(new Position(1, 1), blackPlayer);
            var      expected = new[]
            {
                new Position(1, 1), new Position(2, 1), new Position(1, 2), new Position(3, 2),
                new Position(1, 3), new Position(2, 3), new Position(3, 3)
            };

            map[3, 1] = elephant;
            map[1, 1] = pawn;
            map[2, 2] = king;
            var result = king.FindPosibleWays(map);

            Assert.That(result.ToArray(), Is.EquivalentTo(expected));
        }
예제 #26
0
        public void GetElephant_ReturnsOne()
        {
            //arrange
            var searchedGuid    = Guid.NewGuid();
            var correctElephant = new Elephant()
            {
                Name = "Sam",
                Id   = searchedGuid,
                Note = "This is the elephant we want to get"
            };
            var incorrectElephant1 = new Elephant()
            {
                Name = "Barry",
                Id   = Guid.NewGuid(),
                Note = "This is NOT the elephant we want to get"
            };
            var incorrectElephant2 = new Elephant()
            {
                Name = "Steve",
                Id   = Guid.NewGuid(),
                Note = "This is NOT the elephant we want to get"
            };

            var elephantList = new List <Elephant>();

            elephantList.Add(correctElephant);
            elephantList.Add(incorrectElephant1);
            elephantList.Add(incorrectElephant2);
            var controller = new ElephantController(_elephantService.Object);

            _elephantService.Setup(x => x.GetElephants(It.IsAny <string>())).ReturnsAsync(elephantList);

            //act
            var response = controller.GetElephant(searchedGuid);
            var result   = (OkObjectResult)response.Result;

            //assert
            Assert.NotNull(result.Value);
            Assert.Equal(correctElephant, result.Value);
            Assert.True(result is OkObjectResult);
            Assert.IsType <Elephant>(result.Value);
            Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
        }
예제 #27
0
        private int encounterNumber = 0; // how many times has this factory been used already?
        public override Monster Create(int playerLevel)
        {
            if (Index.RNG(0, 100) < 20)
            {
                return(null);                        // Elephants have spawn rate of 20%
            }
            Monster monster;

            if (encounterNumber % 5 == 0) // return evolved elephant every third encounter
            {
                monster = new ElephantEvolved(playerLevel);
            }
            else
            {
                monster = new Elephant(playerLevel);
            }
            encounterNumber++;
            return(monster);
        }
예제 #28
0
    public static IAnimal Load(String type)
    {
        IAnimal animal = null;

        switch (type)
        {
        case "Zebra":
            animal = new Zebra();
            break;

        case "Elephant":
            animal = new Elephant();
            break;

        default:
            throw new Exception();
        }
        return(animal);
    }
예제 #29
0
파일: Program.cs 프로젝트: jnleon/jleon-c
        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);
        }
예제 #30
0
        public void FindPosibleWaysWithEnemies()
        {
            var      map           = new Map();
            Elephant elephantWhite = new Elephant(new Position(5, 1), whitePlayer);
            Elephant elephantBlack = new Elephant(new Position(2, 4), blackPlayer);
            Rook     rookWhite     = new Rook(new Position(2, 1), whitePlayer);
            var      expected      = new[]
            {
                new Position(2, 0), new Position(0, 1), new Position(1, 1), new Position(3, 1),
                new Position(4, 1), new Position(2, 2), new Position(2, 3), new Position(2, 4)
            };

            map[5, 1] = elephantWhite;
            map[2, 4] = elephantBlack;
            map[2, 1] = rookWhite;
            var result = rookWhite.FindPosibleWays(map);

            Assert.That(result.ToArray(),
                        Is.EquivalentTo(expected));
        }
예제 #31
0
        public void AddAnimalsInZooPark()
        {
            for (int i = 1; i <= 5; i++)
            {
                Monkey monkey = new Monkey();
                animalsInZooPark.Add(monkey);
            }

            for (int i = 1; i <= 5; i++)
            {
                Lion lion = new Lion();
                animalsInZooPark.Add(lion);
            }

            for (int i = 1; i <= 5; i++)
            {
                Elephant elephant = new Elephant();
                animalsInZooPark.Add(elephant);
            }
        }
예제 #32
0
        private void CreateElephant_Click(object sender, EventArgs e)
        {
            amountofelephants += 1;
            listBox.Items.Add(Convert.ToString(Elephant.Name()) + Convert.ToString(amountofelephants) + " Energy:" + (Convert.ToString(Elephant.Energy())));


            if (createTable == true)
            {
                dtbl.Columns.Add("Animal");
                dtbl.Columns.Add("Energy");
                dataGridView.DataSource = dtbl;
                dtbl.Rows.Add(Convert.ToString(Elephant.Name()) + Convert.ToString(amountofelephants), Elephant.Energy());
                createTable = false;
            }
            else
            {
                dataGridView.DataSource = dtbl;
                dtbl.Rows.Add(Convert.ToString(Elephant.Name()) + Convert.ToString(amountofelephants), Elephant.Energy());
            }
        }
예제 #33
0
    public void StartGame()
    {
        GameAnalytics.NewProgressionEvent(GAProgressionStatus.Start, "Start The Game");
        Elephant.LevelStarted(level);


        level     = PlayerPrefs.GetInt("Level", level);
        totalCoin = PlayerPrefs.GetInt("Coin", totalCoin);
        GameSceneManager.instance.GoldText.text  = totalCoin.ToString();
        GameSceneManager.instance.levelText.text = "Level " + level.ToString();
        if (level > 10)
        {
            PlatformManager.instance.maxDistance = 500;
        }
        if (!PlatformManager.instance.isPlatformSet)
        {
            PlatformManager.instance.SetPlatform();
        }
        //GameSceneManager.instance.isGameRunning = true;
        GameSceneManager.instance.player.transform.position = GameSceneManager.instance.startPos.transform.position;
    }
예제 #34
0
        public void Add(string nickname, Species spices)
        {
            Animal animal = null;

            switch (spices)
            {
            case Species.Bear:
                animal = new Bear(nickname);
                break;

            case Species.Elephant:
                animal = new Elephant(nickname);
                break;

            case Species.Fox:
                animal = new Fox(nickname);
                break;

            case Species.Lion:
                animal = new Lion(nickname);
                break;

            case Species.Tiger:
                animal = new Tiger(nickname);
                break;

            case Species.Wolf:
                animal = new Wolf(nickname);
                break;
            }

            if (!_animals.ContainsKey(nickname))
            {
                _animals.Add(nickname, animal);
            }
            else
            {
                Console.WriteLine("FAIL! Nickname of the animal already exist!");
            }
        }
예제 #35
0
    void FillPolymorphicAnimalArray()
    {
        for (int i = 0; i < animals.Length; i++)
        {
            // every second Animal is a Cat instead of an Elephant
            if (i % 2 == 0)
            {
                animals[i] = new Elephant();
            }
            else
            {
                animals[i] = new Cat();
            }
        }

        for (int i = 0; i < animals.Length; i++)
        {
            // because the abstract Animal class guarantees implementation of the Talk() method,
            // we can just call it on every animal without worry
            animals[i].Talk();
        }
    }
예제 #36
0
        private static void CreateAnimalsAndAddToList()
        {
            Elephant el1 = new Elephant(20);
            Elephant el2 = new Elephant(100);
            Elephant el3 = new Elephant(100);
            Elephant el4 = new Elephant(100);
            Elephant el5 = new Elephant(100);

            allAnimals.Add(el1);
            allAnimals.Add(el2);
            allAnimals.Add(el3);
            allAnimals.Add(el4);
            allAnimals.Add(el5);

            Giraff gir1 = new Giraff(100);
            Giraff gir2 = new Giraff(100);
            Giraff gir3 = new Giraff(100);
            Giraff gir4 = new Giraff(100);
            Giraff gir5 = new Giraff(100);

            allAnimals.Add(gir1);
            allAnimals.Add(gir2);
            allAnimals.Add(gir3);
            allAnimals.Add(gir4);
            allAnimals.Add(gir5);

            Monkey mon1 = new Monkey(100);
            Monkey mon2 = new Monkey(100);
            Monkey mon3 = new Monkey(100);
            Monkey mon4 = new Monkey(100);
            Monkey mon5 = new Monkey(100);

            allAnimals.Add(mon1);
            allAnimals.Add(mon2);
            allAnimals.Add(mon3);
            allAnimals.Add(mon4);
            allAnimals.Add(mon5);
        }
예제 #37
0
        public async Task Post_ReturnsAddedElephantToListOfElephants()
        {
            var newElephant = new Elephant()
            {
                name = "Andrew"
            };
            var returnedElephant = newElephant;

            returnedElephant.id = Guid.NewGuid().ToString();

            var mockElephantRepo = new Mock <IElephantRepo>();

            mockElephantRepo.Setup(x => x.Add(newElephant)).ReturnsAsync(
                returnedElephant
                );

            ElephantService _tests = new ElephantService(mockElephantRepo.Object);

            var result = await _tests.Add(newElephant);

            Assert.Equal(newElephant.name, result.name);
            Assert.NotNull(result.id);
        }
예제 #38
0
        private void button2_Click(object sender, EventArgs e)
        {
            Elephant[] elephants = new Elephant[7];

            elephants[0] = new Elephant() { Name = "Lloyd", EarSize = 40 };
            elephants[1] = new Elephant() { Name = "Lucinda", EarSize = 33 };
            elephants[2] = new Elephant() { Name = "Larry", EarSize = 42 };
            elephants[3] = new Elephant() { Name = "Lucille", EarSize = 32 };
            elephants[4] = new Elephant() { Name = "Lars", EarSize = 44 };
            elephants[5] = new Elephant() { Name = "Linda", EarSize = 37 };
            elephants[6] = new Elephant() { Name = "Humphrey", EarSize = 45 };

            Elephant biggestEars = elephants[0];
            for (int i = 1; i < elephants.Length; i++)
            {
                if (elephants[i].EarSize > biggestEars.EarSize)
                {
                    biggestEars = elephants[i];
                }
            }

            MessageBox.Show(biggestEars.EarSize.ToString());
        }
예제 #39
0
        static void Main(string[] args)
        {
            //We can create an Object from the base class if the base class is not abstract.
            Animal georgeTheAnimalSteel = new Animal();

            georgeTheAnimalSteel.GetMad();

            //A few objects built from subclasses of Animal.

            Bear barryTheBear = new Bear();

            barryTheBear.LatinName = "Ursidae";
            barryTheBear.GetMad();
            barryTheBear.EatHiker();
            barryTheBear.numberOfSalmonPerDay = 10;
            barryTheBear.StateType();

            Cat coryTheCat = new Cat();

            Dog donnie = new Dog();

            Elephant eleanor = new Elephant();
        }