예제 #1
0
파일: Program.cs 프로젝트: scrumvdabgenk/T1
        static void DoTerrateam()
        {
            // do some Console stuff
            Console.BackgroundColor = ConsoleColor.Black;
            Console.CursorVisible   = false;
            Console.Clear();
//          Console.SetWindowSize(cnGrootteY+1, cnGrootteX+1);
            //Console.SetBufferSize(cnGrootteY+1, cnGrootteX+1);

            // create speelveld and additional data
            Random    rnd       = new Random();
            Speelveld speelveld = new Speelveld(cnGrootteY, cnGrootteX, cnDisplayModel);

            int rndspeelveld      = speelveld.GrootteX * speelveld.GrootteY;
            int rndspeelveld1     = speelveld.GrootteX + speelveld.GrootteY;
            int rndValuePlant     = (cnGrootteX + cnGrootteY) / 2;
            int rndValueherbivoor = (cnGrootteX + cnGrootteY) / 2;
            int rndValueCarnivoor = cnGrootteX + cnGrootteY;
            int rndValueMens      = cnGrootteX + cnGrootteY;

            ////////int rndValuePlant = rnd.Next(1, ((rndspeelveld / rndspeelveld1) / 5)+1);
            ////////int rndValueherbivoor = rnd.Next(1, ((rndspeelveld / rndspeelveld1) / 4)+1);
            ////////int rndValueCarnivoor = rnd.Next(1, ((rndspeelveld / rndspeelveld1) / 4)+1);
            ////////int rndValueMens = rnd.Next(1, ((rndspeelveld / rndspeelveld1) / 4)+1);

            List <Plant> planten = Plant.CreatePlanten(rndValuePlant);

            speelveld.AddPlantenToSpeelveld(planten);

            List <Herbivoor> herbivoren = Herbivoor.CreateHerbivoren(rnd.Next(1, rndValueherbivoor));

            speelveld.AddHerbivorenToSpeelveld(herbivoren);

            List <Carnivoor> carnivoren = Carnivoor.CreateCarnivoren(rnd.Next(1, rndValueCarnivoor));

            speelveld.AddCarnivorenToSpeelveld(carnivoren);

            List <Mens> mensen = Mens.CreateMensen(rnd.Next(1, rndValueMens));

            speelveld.AddMensenToSpeelveld(mensen);

            speelveld.ToonSpeelveld();;
            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                int lnReturn = speelveld.DoActionsOf1Day(mensen, carnivoren, herbivoren, planten);

                speelveld.ToonSpeelveld();

                speelveld.ResetAllStappen(herbivoren, carnivoren);
                speelveld.RemoveDeletedCarnivoren(ref carnivoren);
                speelveld.RemoveDeletedHerbivoren(ref herbivoren);
                speelveld.RemoveDeletedMensen(ref mensen);

                if (lnReturn == -1)
                {
                    break;  // stop while loop
                }
            }
            Console.CursorVisible = true;
        }
예제 #2
0
파일: Program.cs 프로젝트: scrumvdabgenk/T1
        static void DoTest3()
        {
            Console.Clear();

            // test 1
            Speelveld speelveld = new Speelveld(3, 3, 0);

            // . . .
            // . . .
            // . . .

            List <Plant> planten = Plant.CreatePlanten(1);

            planten[0].PosX = 2;
            planten[0].PosY = 1;
            speelveld.AddPlantenToSpeelveld(planten, true);

            // . . .
            // . . .
            // P H .

            List <Herbivoor> herbivoren = Herbivoor.CreateHerbivoren(4);

            herbivoren[0].PosX = 0;
            herbivoren[0].PosY = 1;
            //herbivoren[1].PosX = 0;
            //herbivoren[1].PosY = 2;
            herbivoren[1].PosX = 1;
            herbivoren[1].PosY = 0;
            herbivoren[2].PosX = 1;
            herbivoren[2].PosY = 2;
            herbivoren[3].PosX = 2;
            herbivoren[3].PosY = 1;
            speelveld.AddHerbivorenToSpeelveld(herbivoren, true);

            // . H .
            // H . H
            // P H .

            List <Carnivoor> carnivoren = Carnivoor.CreateCarnivoren(3);

            carnivoren[0].PosX = 0;
            carnivoren[0].PosY = 0;
            carnivoren[1].PosX = 1;
            carnivoren[1].PosY = 1;
            carnivoren[2].PosX = 2;
            carnivoren[2].PosY = 2;
            speelveld.AddCarnivorenToSpeelveld(carnivoren, true);

            // C H .
            // H C H
            // H P C

            List <Mens> mensen = Mens.CreateMensen(1);

            mensen[0].PosX = 0;
            mensen[0].PosY = 2;
            speelveld.AddMensenToSpeelveld(mensen, true);

            speelveld.DoActionsOf1Day(mensen, carnivoren, herbivoren, planten, 10);

            Console.WriteLine("Press a key");
            Console.ReadLine();
        }
예제 #3
0
파일: Program.cs 프로젝트: scrumvdabgenk/T1
        static void DoTest1()
        {
            Console.Clear();

            // test 1
            Speelveld speelveld = new Speelveld(3, 3, 0);

            // . . .
            // . . .
            // . . .

            List <Plant> planten = Plant.CreatePlanten(2);

            planten[0].PosX = 1;
            planten[0].PosY = 2;
            planten[1].PosX = 2;
            planten[1].PosY = 1;
            speelveld.AddPlantenToSpeelveld(planten, true);

            // . . .
            // . . P
            // . P .

            List <Herbivoor> herbivoren = Herbivoor.CreateHerbivoren(2);

            herbivoren[0].PosX = 0;
            herbivoren[0].PosY = 1;
            herbivoren[1].PosX = 2;
            herbivoren[1].PosY = 0;
            speelveld.AddHerbivorenToSpeelveld(herbivoren, true);

            // . H .
            // . . P
            // H P .

            List <Carnivoor> carnivoren = Carnivoor.CreateCarnivoren(2);

            carnivoren[0].PosX         = 0;
            carnivoren[0].PosY         = 0;
            carnivoren[1].Levenskracht = 10;
            carnivoren[1].PosX         = 1;
            carnivoren[1].PosY         = 1;
            carnivoren[1].Levenskracht = 10;
            //carnivoren[1].PosX = 1;
            //carnivoren[1].PosY = 0;
            //carnivoren[1].Levenskracht = 10;
            speelveld.AddCarnivorenToSpeelveld(carnivoren, true);

            // C H .
            // . C P
            // H P .

            List <Mens> mensen = Mens.CreateMensen(2);

            mensen[0].PosX         = 1;
            mensen[0].PosY         = 0;
            mensen[0].Levenskracht = 10;
            mensen[1].PosX         = 1;
            mensen[1].PosY         = 1;
            mensen[1].Levenskracht = 15;
            speelveld.AddMensenToSpeelveld(mensen, true);

            // C H .
            // M C P
            // H P M

            speelveld.DoActionsOf1Day(mensen, carnivoren, herbivoren, planten, 10);

            Console.WriteLine("Press a key");
            Console.ReadLine();
        }
예제 #4
0
        public int DoActionsOf1Day(List <Mens> mensen, List <Carnivoor> carnivoren, List <Herbivoor> herbivoren, List <Plant> planten, int enOffsetX = 0)
        {
            vandaagVal++;
            foreach (Mens m in mensen)
            {
                m.Levenskracht--;
                if (m.Levenskracht <= 0)
                {
                    m.Delete();
                    this.Terrarium[m.PosX, m.PosY] = null;
                }
            }

            foreach (Herbivoor h in herbivoren)
            {
                h.Levenskracht--;
                if (h.Levenskracht <= 0)
                {
                    h.Delete();
                    this.Terrarium[h.PosX, h.PosY] = null;
                }
            }
            foreach (Carnivoor c in carnivoren)
            {
                c.Levenskracht--;
                if (c.Levenskracht <= 0)
                {
                    c.Delete();
                    this.Terrarium[c.PosX, c.PosY] = null;
                }
            }

            foreach (Plant p in planten)
            {
                p.Levenskracht--;
                if (p.Levenskracht <= 0)
                {
                    p.Delete();
                    this.Terrarium[p.PosX, p.PosY] = null;
                }
            }

            int lnOffset = 0;

            for (int i = 0; i <= this.CountAmounOfCarnivorenInSpeelveld(); i++)
            {
            }

            this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Start");
            lnOffset++;

            List <Herbivoor> nieuweherbivoren = new List <Herbivoor>();

            /////////////////////////////////////////////////
            // carnivoren business
            /////////////////////////////////////////////////
            foreach (Carnivoor C in carnivoren)
            {
                if (!C.IsDeleted)
                {
                    Dier dier = null;

                    if ((C.PosY + 1 < this.GrootteY) &&
                        (this.Terrarium[C.PosX, C.PosY + 1] != null) &&
                        (this.Terrarium[C.PosX, C.PosY + 1].GetType() == typeof(Dier)))
                    {
                        dier = (Dier)this.Terrarium[C.PosX, C.PosY + 1];
                    }

                    C.Eet(this, dier);
                    C.Vecht(this, dier);
                    C.Beweeg(this);

                    this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Carni");
                    lnOffset++;
                }
            }

            /////////////////////////////////////////////////
            // herbivoren business
            /////////////////////////////////////////////////
            foreach (Herbivoor H in herbivoren)
            {
                if (!H.IsDeleted)
                {
                    Dier dier = null;

                    if ((H.PosY + 1 < this.GrootteY) &&
                        (this.Terrarium[H.PosX, H.PosY + 1] != null) &&
                        (this.Terrarium[H.PosX, H.PosY + 1].GetType() == typeof(Dier)))
                    {
                        dier = (Dier)this.Terrarium[H.PosX, H.PosY + 1];
                    }

                    H.Eet(this, dier);
                    H.Beweeg(this);
                    Herbivoor nieuweherbivoor = H.PlantVoort(this, herbivoren);
                    if (nieuweherbivoor != null)
                    {
                        nieuweherbivoren.Add(nieuweherbivoor);
                    }
                    this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Herbi");
                    lnOffset++;
                }
            }

            this.AddHerbivorenToSpeelveld(nieuweherbivoren);
            if (nieuweherbivoren != null)
            {
                foreach (Herbivoor Dier in nieuweherbivoren)
                {
                    herbivoren.Add(Dier);
                }
            }
            this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Paren");
            lnOffset++;

            /////////////////////////////////////////////////
            // mensen business
            /////////////////////////////////////////////////
            foreach (Mens M in mensen)
            {
                if (!M.IsDeleted)
                {
                    Dier dier = null;

                    if ((M.PosY + 1 < this.GrootteY) &&
                        (this.Terrarium[M.PosX, M.PosY + 1] != null) &&
                        (this.Terrarium[M.PosX, M.PosY + 1].GetType() == typeof(Dier)))
                    {
                        dier = (Dier)this.Terrarium[M.PosX, M.PosY + 1];
                    }

                    M.Vecht(this, dier);
                    M.Eet(this, dier);
                    M.Beweeg(this);
                    this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Mens");
                    lnOffset++;
                }
            }

            /////////////////////////////////////////////////
            // planten business
            /////////////////////////////////////////////////
            List <Plant> nieuweplanten = Plant.CreatePlanten((this.GrootteX * this.GrootteY) / (this.GrootteX + this.GrootteY));

            this.AddPlantenToSpeelveld(nieuweplanten);
            foreach (var plant in nieuweplanten)
            {
                planten.Add(plant);
            }
            this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Plant");
            lnOffset++;
            //Console.ReadLine();
            //Thread.Sleep(500);
            //Console.ReadLine();

            /////////////////////////////////////////////////
            // input business
            /////////////////////////////////////////////////
            System.IO.Directory.CreateDirectory("c:\\Temp\\");
            string lcFilename = "c:\\Temp\\TerrariumSettings.txt";
            int    lnReturn   = 0;

            Console.WriteLine("[Enter] Volgende dag, (B)ewaar, (L)ees, (V)ulkaan, (A)ardbeving,  (S)top");
            string lcInput = Console.ReadLine().ToLower();

            switch (lcInput)
            {
            case "b":
                this.SaveSpeelveld(lcFilename, mensen, carnivoren, herbivoren, planten);
                break;

            case "l":
                this.LoadSpeelveld(lcFilename, ref mensen, ref carnivoren, ref herbivoren, ref planten);
                break;

            case "v":
                this.Volcano(ref mensen, ref carnivoren, ref herbivoren, ref planten, this);
                this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Vulcano");
                break;

            case "a":
                this.Earthquake(ref mensen, ref carnivoren, ref herbivoren, ref planten, this);
                this.ToonSpeelveld(enOffsetX * lnOffset, 0, "Earthquake");
                break;

            case "s":
                lnReturn = -1;
                break;
            }

            return(lnReturn);
        }