写一个star的类(包含随机random的星星的位置、颜色、形状),从star扩充流星类(会移动的星星),show定义为虚拟,在流星类里重写
程序从键盘上输入一个数,输出相应数量的星星,形状随机 @ # % * 。,并且会闪烁(threading)
写了但是编译不了

解决方案 »

  1.   

    show定义为虚拟(virtual),在流星类里重写,有Star类,流星要继承Star类呢?
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication14
    {
        public class Star
        {
            public int X;
            public int Y;
            Random r = new Random();
            public int x;
            public int y;
            public Star(int num)
            {
                for (int i = 0; i < num; i++)
                {
                    int g = r.Next(5);
                    int k = r.Next(5);
                    char[] shapes = { '+', '*', '&', '。', '#' };
                    Console.ForegroundColor = (ConsoleColor)g;
                    Console.SetCursorPosition(r.Next(100), r.Next(20));
                    Console.Write("{0}", shapes[k]);
                }
             }        public Star(int x, int y)
            {
                // TODO: Complete member initialization
                this.x = x;
                this.y = y;
            }
            public virtual void Show(int x, int y)
            {
                X = x;
                Y = y;
                Console.SetCursorPosition(x, y);
            }        internal void Show()
            {
                throw new NotImplementedException();
            }
        }
    }
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication14
    {
        class Meteor:Star
        {
            public Meteor(int x, int y): base(x, y)
             {
                Console.WriteLine() ;
            }
            public override void Show(int x, int y)
            {
                base.Show();
                while (true)
                {
                    X = x;
                    Y = y;
                    Console.SetCursorPosition(x+1, y+1);
                }
            }
        }
    }
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;namespace ConsoleApplication14
    {
        class Program
        {
          List<Star> Stars = new List<Star>();
            static void Main(string[] args)
            {
                Console.WriteLine("输入星星数:");
                int num = Convert.ToInt32(Console.ReadLine());
                Console.Clear();
                Star Star1 = new Star(num);
                Console.ReadLine();
            }
        }
    }