寫一個star的類(包含隨機random的星星的位置、顏色、形狀),從star擴充流星類(會移動的星星),show定義為虛擬,在流星類里重寫
程式從鍵盤上輸入一個數,輸出相應數量的星星,形狀隨機 @ # % * 。,并且會閃爍(threading)
寫了但是編譯不了

uj5u.com熱心網友回復:
show定義為虛擬(virtual),在流星類里重寫,有Star類,流星要繼承Star類呢?uj5u.com熱心網友回復:
編譯不了,貼出錯誤資訊,或者文本格式的代碼才好回答你uj5u.com熱心網友回復:
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();
}
}
}
uj5u.com熱心網友回復:
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);
}
}
}
}
uj5u.com熱心網友回復:
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();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/99195.html
標籤:C#
上一篇:求救:WPF拖拽檔案后釋放檔案時怎樣判斷是否為指定的目標軟體
下一篇:致迷茫的軟體開發者
