�因克路德 2019-11-11 15:04 采纳率: 33.3%
浏览 437
已采纳

C#如何通过星星类扩展出流星类,流星通过重写星星的show方法显示出一颗移动的星星

图片说明图片说明
star类可以显示出一颗星星,现在要新建一个流星类重写star的show方法,显示出一个移动的星星。。求助

`主函数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Collections;

namespace 满天星星
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入星星数量:");
int num = Convert.ToInt32(Console.ReadLine());
Random r = new Random();
char[] shapes = { '!', '@', '#', '$', '%', '^', '&', '*' };
for (int i = 0; i < num; i++)
{
Star star = new Star(shapes[r.Next(8)], r.Next(52), r.Next(52), r.Next(15));
star.PrintStar();
}
}
}
}

star类
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 满天星星
{
class Star
{
public int x;
public int y;
public int yanse;
public char shape;
public Star()
{
shape = '*';
}
public Star(char Z, int x, int y,int k)
{
this.x = x;
this.y = y;
this.yanse = k;
this.shape = Z;
}
public virtual void PrintStar()
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = (ConsoleColor)(int)yanse;
Console.Write("{0}", shape);
}
}
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-11 18:10
    关注

    class 流星 : Star
    {
    public override void PrintStar()
    {
    你的实现的代码
    }
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥100 正常上网,内部网页无法打开
    • ¥15 组件库引入并使用在若依框架未展示
    • ¥149 关于#使用python 的Flash Echarts+ajax+mysql动态数据实现饼图#的问题,请各位专家解答!
    • ¥15 RichTextBox中追加文本时报错
    • ¥15 关于c语言的学习问题
    • ¥15 activity升级到flowable工作流act_ge_bytearray的草稿json数据复制到act_de_model 的model_editor_json的脚本
    • ¥15 cvi使用CreateThread创建线程时,出现存储空间不足无法处理此命令的错误
    • ¥15 求苹果推信imessage批量推信技术
    • ¥15 ubuntu 22.04 系统盘空间不足。隐藏的docker空间占用?(相关搜索:移动硬盘|管理系统)
    • ¥15 c++ word自动化,为什么可用接口是空的?