Advertisement
csaki

Gladiátoros feladat

Apr 4th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. // A feladat maga: http://aries.ektf.hu/~hz/wiki7/mprog2gy/gyak_08
  7.  
  8. namespace gladiator
  9. {
  10.     enum Szinkod { Sárga, Piros, Fekete }
  11.     enum Szarmazas { Római, Trak, Gall, Hispán, Pun }
  12.     enum Fegyver { Kard, Lándzsa, Buzogány, Acélháló }
  13.  
  14.     class Gladiator
  15.     {
  16.         // Fields, properties
  17.         public Szinkod szin;
  18.         public Szarmazas szarmazas;
  19.         public bool szabad_e;
  20.         protected int _ev;
  21.         public int ev
  22.         {
  23.             get { return _ev; }
  24.             set
  25.             {
  26.                 if (0 < value && value <= 10)
  27.                 {
  28.                     _ev = value;
  29.                 }
  30.         else throw new Exception("Hibás érték! (év)");
  31.             }
  32.         }
  33.  
  34.         // Constructors
  35.         public Gladiator(int p_ev, Szarmazas p_szarm)
  36.         {
  37.             ev = p_ev;
  38.             szarmazas = p_szarm;
  39.             szabad_e = false;
  40.      
  41.             if (_ev <= 2)
  42.             {
  43.                 szin = Szinkod.Sárga;
  44.             }
  45.             else if (_ev <= 5)
  46.             {
  47.                 szin = Szinkod.Piros;
  48.             }
  49.             else szin = Szinkod.Fekete;
  50.         }
  51.  
  52.         // Methods
  53.         public virtual void Oregszik()
  54.         {
  55.             if (ev < 10)
  56.             {
  57.                 ev++;
  58.                 if (ev == 10) szabad_e = true;
  59.                 else Fejlodik(ev); // nem praktikus, de mindegy
  60.             }
  61.         }
  62.  
  63.         public void Fejlodik(int ev)
  64.         {
  65.             switch (ev)
  66.             {
  67.                 case 3:
  68.                     szin = Szinkod.Piros;
  69.                     break;
  70.                 case 6:
  71.                     szin = Szinkod.Fekete;
  72.                     break;
  73.                 default:
  74.                     // ..
  75.                     break;
  76.             }
  77.         }
  78.  
  79.         /* public void Felszabadit()
  80.         {
  81.             szabad_e = true;
  82.         }*/
  83.     }
  84.  
  85.     class KepzettGladiator : Gladiator
  86.     {
  87.         // Fields, properties
  88.         public Fegyver fegyver;
  89.         protected string _becenev;
  90.         public string becenev
  91.         {
  92.             get { return _becenev; }
  93.             set
  94.             {
  95.                 if (2 < value.Length && value.Length < 16)
  96.                 {
  97.                     _becenev = value;
  98.                 }
  99.         else throw new Exception("Hibás érték! (becenév)");
  100.             }
  101.         }
  102.  
  103.         // Methods
  104.         public override void Oregszik()
  105.         {
  106.             if (ev >= 6)
  107.             {
  108.                 ev = ev + 2;
  109.             }
  110.             else if (ev < 10)
  111.             {
  112.                 ev++;
  113.                 if (ev == 10)
  114.                 {
  115.                     szabad_e = true; // sokkkkkkal egyszerűbb...
  116.                     //Felszabadit();
  117.                     return;
  118.                 }
  119.                 else Fejlodik(ev); // nem praktikus, de mindegy
  120.             }
  121.             else szabad_e = true;
  122.  
  123.         }
  124.  
  125.         // Constructor
  126.         public KepzettGladiator(int p_ev, string p_bece, Szarmazas p_szarm, Fegyver p_fegyv)
  127.             : base(p_ev, p_szarm)
  128.         {
  129.             ev = p_ev;
  130.             fegyver = p_fegyv;
  131.             szarmazas = p_szarm;
  132.             becenev = p_bece;
  133.             szabad_e = false;                
  134.             if (ev <= 2)
  135.             {
  136.                 szin = Szinkod.Sárga;
  137.             }
  138.             else if (ev <= 5)
  139.             {
  140.                 szin = Szinkod.Piros;
  141.             }
  142.             else szin = Szinkod.Fekete;
  143.         }
  144.     }
  145.  
  146.     class Arena
  147.     {
  148.         static Random rand = new Random();
  149.         protected static List<KepzettGladiator> lista = new List<KepzettGladiator>();
  150.  
  151.         private static void Harc()
  152.         {
  153.             int x1, x2;
  154.             do
  155.             {
  156.                 x1 = rand.Next(lista.Count);
  157.                 x2 = rand.Next(lista.Count);
  158.             } while (x1 == x2);
  159.  
  160.             if ((int)lista[x1].szin > (int)lista[x2].szin)
  161.             {
  162.                 lista.RemoveAt(x2);
  163.             }
  164.             else if ((int)lista[x1].szin < (int)lista[x2].szin)
  165.             {
  166.                 lista.RemoveAt(x1);
  167.             }
  168.             else lista.RemoveAt(Szavaz(x1, x2));
  169.         }
  170.  
  171.         private static int Szavaz(int x1, int x2)
  172.         {
  173.             bool x = rand.Next(2) == 1 ? true : false;
  174.             if (x) return x1;
  175.             else return x2;
  176.         }
  177.  
  178.         static string msh = "qwrtzpsdfghjklxvbnm";
  179.         static string mgh = "euioay";
  180.  
  181.         public static void Valogat()
  182.         {
  183.             while (lista.Count < 10)
  184.             {
  185.                 List<char> beceList = new List<char>();
  186.  
  187.                 beceList.Add(msh[rand.Next(msh.Length)]);
  188.                 int nameLength = rand.Next(5, 12);
  189.                 for (int i = 1; i < nameLength; i++)
  190.                 {
  191.                     if (i % 2 == 0)
  192.                         beceList.Add(msh[rand.Next(msh.Length)]);
  193.                     else beceList.Add(mgh[rand.Next(mgh.Length)]);
  194.                 }
  195.                 string gBecenev = string.Join("", beceList.ToArray());
  196.                 gBecenev = char.ToUpper(gBecenev[0]) + gBecenev.Substring(1);
  197.  
  198.                 lista.Add(new KepzettGladiator(rand.Next(10), gBecenev, (Szarmazas)rand.Next(5), (Fegyver)rand.Next(4)));
  199.             }
  200.         }
  201.  
  202.         public static KepzettGladiator TornaIndul()
  203.         {
  204.             while (lista.Count != 1)
  205.             {
  206.                 Harc();
  207.             }
  208.             lista[0].Oregszik();
  209.             return lista[0];
  210.         }
  211.     }
  212.  
  213.     class Program
  214.     {
  215.         static void Main(string[] args)
  216.         {
  217.                 KepzettGladiator kg = null;
  218.                 for (int i = 0; i < 3; i++)
  219.                 {
  220.                     Arena.Valogat();
  221.                     if (i == 2)
  222.                     {
  223.                         kg = Arena.TornaIndul();
  224.                         break;
  225.                     }
  226.                     Arena.TornaIndul();
  227.                 }
  228.  
  229.                 Console.WriteLine("A három torna győztes gladiátora:\n-------------------------");
  230.                 Console.WriteLine("Becenév: {0}", kg.becenev);
  231.                 Console.WriteLine("Év: {0}", kg.ev);
  232.                 Console.WriteLine("Származás: {0}", kg.szarmazas);
  233.                 Console.WriteLine("Fegyver: {0}", kg.fegyver);
  234.                 Console.WriteLine("Színkód: {0}", kg.szin);
  235.                 Console.WriteLine("Szabad-e: {0}", kg.szabad_e ? "igen" : "nem");
  236.                 Console.ReadLine();
  237.         }
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement