Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. enum Fruit
  2. {
  3. None = -1,
  4.  
  5. Apple,
  6. Orange,
  7. Banana,
  8. Lemon,
  9.  
  10. Max,
  11. }
  12.  
  13. class Market
  14. {
  15. public Market(int nCount)
  16. {
  17. if (nCount <= 0) { Console.WriteLine("error"); return; }
  18. m_seller = new Seller[nCount];
  19. Random rt = new Random();
  20. for (int i = 0; i < nCount; ++i)
  21. {
  22. Seller m = new Seller();
  23. int nRand = rt.Next((int)Fruit.Max);
  24. int FruitCount = rt.Next(9) + 1;
  25. m.SetParent(this, nRand, FruitCount);
  26. m_seller[i] = m;
  27. }
  28. }
  29.  
  30. public bool Sold(Buyer buyer,int count)
  31. {
  32. for(int i = 0; i < m_seller.Length; i++)
  33. {
  34. for(int j = 0; j < m_seller.Length; j++)
  35. {
  36. if ((int)buyer.Type == (int)m_seller[j].Type)
  37. {
  38. if (m_seller[j].FruitCount == count + i)
  39. {
  40. m_seller[j].Info();
  41. m_seller[j].Sold(this, buyer, count);
  42. m_seller[j].Info();
  43. return true;
  44. }
  45. if (m_seller[j].FruitCount == count - i)
  46. {
  47. m_seller[j].Info();
  48. m_seller[j].Sold(this, buyer, count - i);
  49. m_seller[j].Info();
  50. return true;
  51. }
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57.  
  58. public void Info()
  59. {
  60. Console.WriteLine("판매 대금 : " + m_nGold);
  61. }
  62.  
  63. public void result(int Gold)
  64. {
  65. m_nGold += Gold;
  66. }
  67. Seller[] m_seller;
  68. int m_nGold;
  69. }
  70.  
  71. class Buyer
  72. {
  73. int m_nGold;
  74. int m_nFruitCount;
  75. Fruit m_fType;
  76. public Buyer()
  77. {
  78. m_nGold = 100000;
  79. m_nFruitCount = 0;
  80. m_fType = Fruit.None;
  81. }
  82. public Buyer(int Gold, Fruit Type)
  83. {
  84. m_nGold = Gold;
  85. m_nFruitCount = 0;
  86. m_fType = Type;
  87. }
  88.  
  89. public int FruitCount { get { return m_nFruitCount; } }
  90. public int Gold { get { return m_nGold; } }
  91. public Fruit Type { get { return m_fType; } }
  92.  
  93. public void Buy(Seller s, int count)
  94. {
  95. m_nGold -= s.Price * count;
  96. m_nFruitCount += count;
  97. }
  98.  
  99. public void Info()
  100. {
  101. Console.WriteLine("=============================");
  102. Console.WriteLine("구매자 정보");
  103. Console.WriteLine("소지금 : " + m_nGold);
  104. Console.WriteLine("소지 갯수 : " + m_nFruitCount);
  105. Console.WriteLine("=============================");
  106. Console.WriteLine();
  107. }
  108. }
  109.  
  110. class Seller
  111. {
  112. public void SetParent(Market a_refParent, int a_nType, int a_nCount)
  113. {
  114. m_refParent = a_refParent;
  115. m_eType = (Fruit)a_nType;
  116. switch (m_eType)
  117. {
  118. case Fruit.Apple:
  119. m_nPrice = 500;
  120. break;
  121. case Fruit.Orange:
  122. m_nPrice = 1000;
  123. break;
  124. case Fruit.Banana:
  125. m_nPrice = 5000;
  126. break;
  127. case Fruit.Lemon:
  128. m_nPrice = 1200;
  129. break;
  130. }
  131. m_nGold = 0;
  132. m_nFruitCount = a_nCount;
  133. }
  134.  
  135. public int FruitCount { get { return m_nFruitCount; } }
  136. public int Price { get { return m_nPrice; } }
  137. public Fruit Type { get { return m_eType; } }
  138.  
  139. public void Sold(Market market, Buyer buyer,int count)
  140. {
  141. if (count <= 0) { Console.WriteLine("몇개 살건데?"); return; }
  142. int M_Gold = (int)((m_nPrice * count) * 0.03f);
  143. market.result(M_Gold);
  144. int Gold = 0;
  145. Gold = m_nPrice * count - M_Gold;
  146. m_nGold += Gold;
  147. m_nFruitCount -= count;
  148. buyer.Buy(this, count);
  149. }
  150.  
  151. public void Info()
  152. {
  153. Console.WriteLine("=============================");
  154. Console.WriteLine("판매자 정보");
  155. Console.WriteLine("소지금 : " + m_nGold);
  156. Console.WriteLine("판매 금액 : " + m_nPrice);
  157. Console.WriteLine("소지 갯수 : " + m_nFruitCount);
  158. Console.WriteLine("=============================");
  159. Console.WriteLine();
  160. }
  161.  
  162. int m_nGold;
  163. int m_nPrice;
  164. int m_nFruitCount;
  165. Market m_refParent = null;
  166. Fruit m_eType = Fruit.None;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement