Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Fruit
- {
- None = -1,
- Apple,
- Orange,
- Banana,
- Lemon,
- Max,
- }
- class Market
- {
- public Market(int nCount)
- {
- if (nCount <= 0) { Console.WriteLine("error"); return; }
- m_seller = new Seller[nCount];
- Random rt = new Random();
- for (int i = 0; i < nCount; ++i)
- {
- Seller m = new Seller();
- int nRand = rt.Next((int)Fruit.Max);
- int FruitCount = rt.Next(9) + 1;
- m.SetParent(this, nRand, FruitCount);
- m_seller[i] = m;
- }
- }
- public bool Sold(Buyer buyer,int count)
- {
- for(int i = 0; i < m_seller.Length; i++)
- {
- for(int j = 0; j < m_seller.Length; j++)
- {
- if ((int)buyer.Type == (int)m_seller[j].Type)
- {
- if (m_seller[j].FruitCount == count + i)
- {
- m_seller[j].Info();
- m_seller[j].Sold(this, buyer, count);
- m_seller[j].Info();
- return true;
- }
- if (m_seller[j].FruitCount == count - i)
- {
- m_seller[j].Info();
- m_seller[j].Sold(this, buyer, count - i);
- m_seller[j].Info();
- return true;
- }
- }
- }
- }
- return false;
- }
- public void Info()
- {
- Console.WriteLine("판매 대금 : " + m_nGold);
- }
- public void result(int Gold)
- {
- m_nGold += Gold;
- }
- Seller[] m_seller;
- int m_nGold;
- }
- class Buyer
- {
- int m_nGold;
- int m_nFruitCount;
- Fruit m_fType;
- public Buyer()
- {
- m_nGold = 100000;
- m_nFruitCount = 0;
- m_fType = Fruit.None;
- }
- public Buyer(int Gold, Fruit Type)
- {
- m_nGold = Gold;
- m_nFruitCount = 0;
- m_fType = Type;
- }
- public int FruitCount { get { return m_nFruitCount; } }
- public int Gold { get { return m_nGold; } }
- public Fruit Type { get { return m_fType; } }
- public void Buy(Seller s, int count)
- {
- m_nGold -= s.Price * count;
- m_nFruitCount += count;
- }
- public void Info()
- {
- Console.WriteLine("=============================");
- Console.WriteLine("구매자 정보");
- Console.WriteLine("소지금 : " + m_nGold);
- Console.WriteLine("소지 갯수 : " + m_nFruitCount);
- Console.WriteLine("=============================");
- Console.WriteLine();
- }
- }
- class Seller
- {
- public void SetParent(Market a_refParent, int a_nType, int a_nCount)
- {
- m_refParent = a_refParent;
- m_eType = (Fruit)a_nType;
- switch (m_eType)
- {
- case Fruit.Apple:
- m_nPrice = 500;
- break;
- case Fruit.Orange:
- m_nPrice = 1000;
- break;
- case Fruit.Banana:
- m_nPrice = 5000;
- break;
- case Fruit.Lemon:
- m_nPrice = 1200;
- break;
- }
- m_nGold = 0;
- m_nFruitCount = a_nCount;
- }
- public int FruitCount { get { return m_nFruitCount; } }
- public int Price { get { return m_nPrice; } }
- public Fruit Type { get { return m_eType; } }
- public void Sold(Market market, Buyer buyer,int count)
- {
- if (count <= 0) { Console.WriteLine("몇개 살건데?"); return; }
- int M_Gold = (int)((m_nPrice * count) * 0.03f);
- market.result(M_Gold);
- int Gold = 0;
- Gold = m_nPrice * count - M_Gold;
- m_nGold += Gold;
- m_nFruitCount -= count;
- buyer.Buy(this, count);
- }
- public void Info()
- {
- Console.WriteLine("=============================");
- Console.WriteLine("판매자 정보");
- Console.WriteLine("소지금 : " + m_nGold);
- Console.WriteLine("판매 금액 : " + m_nPrice);
- Console.WriteLine("소지 갯수 : " + m_nFruitCount);
- Console.WriteLine("=============================");
- Console.WriteLine();
- }
- int m_nGold;
- int m_nPrice;
- int m_nFruitCount;
- Market m_refParent = null;
- Fruit m_eType = Fruit.None;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement