wutiejun / workspace

My workspace.
7 stars 3 forks source link

Red or Blue? #79

Open wutiejun opened 6 years ago

wutiejun commented 6 years ago
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Data;

namespace RedBlue
{

    class RedBlue
    {
        public int Red;
        public int Blue;

        System.Random Ramdom;
        Hashtable HashTable;

        public RedBlue()
        {
            this.Red = 50;
            this.Blue = 50;
            this.HashTable = new Hashtable();
            for (int i = 0; i <= 100; i ++)
            {
                this.HashTable.Add(i, i);
            }
            this.Ramdom = new Random();
        }

        public int GetColor()
        {  
            int random = this.Ramdom.Next(this.HashTable.Count);
            return (int)this.HashTable[random];
        }

        public void PushColor(int color)
        {
            if (color%2 == 0)
            {
                this.Red ++;
            }
            else
            {
                this.Blue ++;
            }
            this.HashTable.Add(this.HashTable.Count, color);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            RedBlue rb = new RedBlue();
            while (true)
            {
                rb.PushColor(rb.GetColor());
                System.Console.WriteLine("Red:{0} Blue:{1}", rb.Red, rb.Blue);
            }
        }
    }
}
wutiejun commented 6 years ago

image

wutiejun commented 6 years ago

image