3 Ocak 2018 Çarşamba

C# Inheritance, Foreach

Program.cs tarafı kodları

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    class Program
    {
        static gameEngine oyun = new gameEngine();
        static void Main(string[] args)
        {
            oyun.Init();
            Console.WriteLine("------- OYUNCULAR -----");
            foreach (oyuncu oyuncu in oyun.oyuncular)
            {
                foreach (koy koy in oyuncu.koyler)
                {
                    Console.WriteLine(oyuncu.adiSoyadi + " koy adi " + koy.koyAdi
                        + "yeniceri:" + koy.yeniceriler.Count
                        + " sipahi :" + koy.sipahiler.Count
                        + " humbaraci:" + koy.humbaracilar.Count);
                }
            }
            Console.ReadLine();
        }
    }
}
----------------------------------------------------------------------------------------------------------------



Class tarafı
HUMBARACI clası

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    public class humbaraci
    {
        public int str { get; set; }
        public int dex { get; set; }
        public int mana { get; set; }
        public int attackPower { get; set; }
        public int defencePower { get; set; }

        public humbaraci (int prmStr, int prmDex, int prmMana, int prmAttackPower, int prmDefencePower)
        {
            str = prmStr;
            dex = prmDex;
            mana = prmMana;
            attackPower = prmAttackPower;
            defencePower = prmDefencePower;
        }
        public int hit()
        {
            return (str * attackPower) - bombaciBonusu();
        }
        public int defence()
        {
            return (mana * defencePower) - dex;
        }
        public int speed()
        {
            return dex;
        }
        public int bombaciBonusu()
        {
            return 100;
        }

       }
    }

---------------------------------------------------------------------------
sipahi tarafı class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    public class siphayi
    {
      
        public int str { get; set; }
        public int dex { get; set; }
        public int mana { get; set; }
        public int attackPower { get; set; }
        public int defencePower { get; set; }

        public siphayi(int prmStr, int prmDex, int prmMana, int prmAttackPower, int prmDefencePower)
        {
            str = prmStr;
            dex = prmDex;
            mana = prmMana;
            attackPower = prmAttackPower;
            defencePower = prmDefencePower;
        }
        public int hit()
        {
            return (str * attackPower);
        }
        public int defence()
        {
            return (mana * defencePower) - dex;
        }
        public int speed()
        {
            return dex + atliBonusu();
        }
        public int atliBonusu()
        {
            return 100;
        }
    }
}

YENİÇERİ TARAFI CLASS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    public class yeniCeri
    {
        public int str { get; set; }
        public int dex { get; set; }
        public int mana { get; set; }
        public int attackPower { get; set; }
        public int defencePower { get; set; }

        public yeniCeri(int prmStr, int prmDex, int prmMana, int prmAttackPower, int prmDefencePower)
        {
            str = prmStr;
            dex = prmDex;
            mana = prmMana;
            attackPower = prmAttackPower;
            defencePower = prmDefencePower;
        }
        public int hit()
        {
            return (str * attackPower);
        }

        public int defence()

        {
            return (mana * defencePower) - dex;
        }
        public int speed()
        {
            return dex;
        }
    }
}
---------------------------------------------


GAMEENGINE TARAFI

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

    namespace App26
{
   public class gameEngine
    {
        public List<oyuncu> oyuncular = new List<oyuncu>();

        public void Init()
        {
            oyunculariEkle();
            koyleriEkle();
            askerleriEkle();
        }
        public void oyunculariEkle()
        {
            oyuncular.Add(new oyuncu("beren", "2002", "Burak EREN"));
            oyuncular.Add(new oyuncu("karani", "2002", "Karani UYAR"));
            oyuncular.Add(new oyuncu("onur", "2002", "Onur SARI"));
            oyuncular.Add(new oyuncu("devran", "2002", "Devran DEMİR"));
            oyuncular.Add(new oyuncu("hakan", "2002", "Hakan YILDIRIM"));
        }
        public void koyleriEkle()
        {
            int X = 1;
            int Y = 1;
            foreach (oyuncu oyuncu in oyuncular)
            {
                oyuncu.koyler.Add(new App26.koy(X, Y, oyuncu.kullaniciAdi + " koyu"));
                X++;
                Y++;
            }
        }
        public void askerleriEkle()
        {
            foreach (oyuncu oyuncu in oyuncular)
            {
                foreach (koy koy in oyuncu.koyler)
                {
                    Thread.Sleep(100);
                    Random rnd = new Random();
                    int rndmAskerSayisi = rnd.Next(1, 100);
                    for (int i = 0; i < rndmAskerSayisi; i++)
                    {
                        koy.addYeniceri();
                    }
                    rndmAskerSayisi = rnd.Next(1, 100);
                    for (int i = 0; i < rndmAskerSayisi; i++)
                    {
                        koy.addhumbaraci();
                    }
                    rndmAskerSayisi = rnd.Next(1, 100);
                    for (int i = 0; i < rndmAskerSayisi; i++)
                    {
                        koy.addsipahi();
                    }
                }
            }
        }
          
    }
}

----------------------------------------------------------------------------

KOY CLASS TARAFI

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    public class koy
    {
        public int x { get; set; }
        public int y { get; set; }
        public string koyAdi { get; set; }
        public List<yeniCeri> yeniceriler { get; set; }
        public List<siphayi> sipahiler { get; set; }
        public List<humbaraci> humbaracilar { get; set; }

        public koy(int prmx, int prmy, string prmkoyAdi)
        {
            x = prmx;
            x = prmy;
            koyAdi = prmkoyAdi;
            yeniceriler = new List<yeniCeri>();
            sipahiler = new List<siphayi>();
            humbaracilar = new List<humbaraci>();
        }
        public void addYeniceri()
        {
            yeniceriler.Add(new yeniCeri(10, 5, 5, 25, 10));
        }
        public void addsipahi()
        {
            sipahiler.Add(new siphayi(30, 15, 15, 75, 30));
        }
        public void addhumbaraci()
        {
            humbaracilar.Add(new humbaraci(15, 10, 10, 40, 100));
        }
        public void koyAdiDegistir(string prmkoyadi)
        {
            koyAdi = prmkoyadi;
        }
        public void killYeniceri()
        {
            if (yeniceriler.Count > 0)
            {
                yeniceriler.RemoveAt(yeniceriler.Count - 1);
            }
        }
        public void killsipahi()
        {
            if (yeniceriler.Count > 0)
            {
                sipahiler.RemoveAt(sipahiler.Count - 1);
            }
        }
        public void killhumbaraci()
        {
            if (yeniceriler.Count > 0)
            {
                humbaracilar.RemoveAt(humbaracilar.Count - 1);
            }
        }
    }
}


---------------------------------------------

OYUNCU CLASI

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    public class oyuncu
    {
        public string kullaniciAdi { get; set; }
        public string sifresi { get; set; }
        public string adiSoyadi { get; set; }
        public List<koy> koyler { get; set; }

        public oyuncu(string prmkullaniciadi, string prmsifresi, string  prmadiSoyadi)
        {
            kullaniciAdi = prmkullaniciadi;
            sifresi = prmsifresi;
            adiSoyadi = prmadiSoyadi;
            koyler = new List<koy>();
        }
    }
}

---------------------------------------------------------------



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App26
{
    class Program
    {
        static gameEngine oyun = new gameEngine();
        static void Main(string[] args)
        {
            oyun.Init();
            Console.WriteLine("------- OYUNCULAR -----");
            oyunculariYazdir();

            oyuncu saldiranOyuncu = oyun.oyuncular.Find((x) => x.kullaniciAdi == "beren");
            oyuncu savunanOyuncu = oyun.oyuncular.Find((x) => x.kullaniciAdi == "devran");

            int saldiranınTumaskerleriSaldiriGucu = getSavasGucu(saldiranOyuncu, true);
            int savunanınTumaskerleriDefansGucu = getSavasGucu(saldiranOyuncu, false);

            if (saldiranınTumaskerleriSaldiriGucu > savunanınTumaskerleriDefansGucu)
            {
                killAll(savunanOyuncu);
            }
            else
            {
                killAll(saldiranOyuncu);
            }
           
            Console.WriteLine("\n --------- SAVAŞ SONUCU-------");
            oyunculariYazdir();
            Console.ReadLine();
        }

        static void oyunculariYazdir()
        {
            foreach (oyuncu oyuncu in oyun.oyuncular)
            {
                foreach (koy koy in oyuncu.koyler)
                {
                    Console.WriteLine(oyuncu.adiSoyadi + " koy adi " + koy.koyAdi
                        + "yeniceri:" + koy.yeniceriler.Count
                        + " sipahi :" + koy.sipahiler.Count
                        + " humbaraci:" + koy.humbaracilar.Count);
                }
            }
        }

        static void killAll(oyuncu prmOyuncu)
        {
            foreach (koy koy in prmOyuncu.koyler)
            {

                koy.yeniceriler.Clear();
                koy.sipahiler.Clear();
                koy.humbaracilar.Clear();

            }
        }

        static int getSavasGucu(oyuncu prmOyuncu, bool prmIsSaldiran)
        {
            int rtrnValue = 0;
            foreach (koy koy in prmOyuncu.koyler)
            {
                foreach (yeniCeri yeniceri in koy.yeniceriler)
                {
                    if (prmIsSaldiran)
                    {
                        rtrnValue += yeniceri.hit();
                    }
                    else
                    {
                        rtrnValue += yeniceri.defence();
                    }
                }
                foreach (siphayi sipahi in koy.sipahiler)
                {
                    if (prmIsSaldiran)
                    {
                        rtrnValue += sipahi.hit();
                    }
                    else
                    {
                        rtrnValue += sipahi.defence();
                    }
                }
                foreach (humbaraci humbaraci in koy.humbaracilar)
                {
                    if (prmIsSaldiran)
                    {
                        rtrnValue += humbaraci.hit();
                    }
                    else
                    {
                        rtrnValue += humbaraci.defence();
                    }
                }
            }
            return rtrnValue;
        }
    }
}



Hiç yorum yok:

Yorum Gönder

Mac adres formatı excel

excel iki nokta mac addres formatı Mac adresi karakterlerini üst üste iki nokta : iki nokta üst üste olacak şekilde excel dosyasında ayırır....