Advertisement
Guest User

Untitled

a guest
Oct 30th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1. using System;
  2.  
  3. // Two 'Person' collect stones in a 'Quarry'
  4. // when 10 stones collected --> change stones for money
  5.  
  6. namespace InTheQuarry
  7. {
  8.     public class MainClass
  9.     {
  10.  
  11.         public static void Main(string[] args)
  12.         {
  13.            
  14.             Quarry quarry1 = new Quarry();
  15.             Person person1 = new Person("Mike");
  16.             StoneDealer stoneDealer1 = new StoneDealer("MyStoneDealer");
  17.  
  18.             for (int i = 0; i < 1000; i++)
  19.             {
  20.                 System.Threading.Thread.Sleep(500); // implement later into the work-method
  21.                 person1.Work(quarry1, person1);
  22.                 person1.SellWorkedStones(person1, stoneDealer1);
  23.  
  24.                 Console.WriteLine("{0} stones in the quarry.", quarry1.Stone);
  25.             }
  26.            
  27.             Console.Read();
  28.         }
  29.     }
  30.  
  31.     public class Quarry
  32.     {
  33.         private int stone;
  34.         public int Stone { get; set; }
  35.        
  36.         public Quarry()
  37.         {
  38.             Stone = 10000;
  39.         }
  40.  
  41.         public void WorkInQuarry(Quarry q, QuarryWorker[] workers)  // method
  42.         {
  43.             throw new NotImplementedException();
  44.         }
  45.        
  46.     }
  47.  
  48.     public abstract class QuarryWorker
  49.     {
  50.         //public abstract void Work(Quarry quarry);
  51.     }
  52.  
  53.     public class Machine : QuarryWorker
  54.     {
  55.         public void Work(Quarry quarry)
  56.         {
  57.             throw new NotImplementedException();
  58.         }
  59.     }
  60.  
  61.     public class Person : QuarryWorker
  62.     {
  63.         private string name;
  64.         public string Name { get; set; }
  65.  
  66.         private int workedStone;
  67.         public int WorkedStone { get; set; }
  68.  
  69.         private int money;
  70.         public int Money { get; set; }
  71.  
  72.         public Person(string n)
  73.         {
  74.             WorkedStone = 0;
  75.             Money = 0;
  76.             Name = n;                
  77.             Console.WriteLine("New Person created!");
  78.         }
  79.  
  80.         public void Work(Quarry quarry, Person person)
  81.         {
  82.             WorkedStone += 1;
  83.             quarry.Stone -= 1;
  84.         }
  85.  
  86.         public void SellWorkedStones(Person person, StoneDealer stoneDealer)
  87.         {
  88.             if (person.WorkedStone >= 10)
  89.             {
  90.                 Console.WriteLine("{0} wants to sell his workedStone", person.Name);
  91.                 StoneDealer.ChangeStonesToMoney(person, stoneDealer);
  92.             }
  93.         }
  94.     }
  95.  
  96.     public class StoneDealer
  97.     {
  98.         private string name;
  99.         public string Name { get; set; }
  100.  
  101.         private int workedStone;
  102.         public int WorkedStone { get; set; }
  103.  
  104.         private int money;
  105.         public int Money { get; set; }
  106.  
  107.         public StoneDealer(string n)
  108.         {
  109.             WorkedStone = 0;
  110.             Money = 3000;
  111.             Name = n;
  112.         }
  113.  
  114.         // static - because I don't need an instance here
  115.         public static void ChangeStonesToMoney(Person person, StoneDealer stoneDealer)
  116.         {
  117.             Console.WriteLine("{0} comes to the {1}.", person.Name, stoneDealer.Name);
  118.             person.WorkedStone -= 10;
  119.             stoneDealer.WorkedStone += 10;
  120.             person.Money += 1;
  121.             stoneDealer.Money -= 1;
  122.  
  123.             Console.WriteLine("{0} has now {1} dollar.", person.Name, person.Money);
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement