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

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()
    {
    你的实现的代码
    }
    }

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题