c#day04从控制台获取一个字符

class EnumStruct
    {
        //定义QQ的状态枚举 Qme QnLine OffLine Leave Busy
        //提示用户现在一个状态 然后接收 ,并将用户输入转换成枚举类
        enum Qstar
        {
            Qme,
            QnLine,
            OffLIne,
            Leave,
            Busy
        }

        public void QqStar()
        {
            Console.WriteLine("请选择您的QQ状态:1.Qme 2.QnLine 3.OffLine 4.Leave 5.Busy");

            int star = int.Parse( Console.ReadLine());

            Qstar myqstar = new Qstar();

            switch(star)
            {
                case 1:
                    myqstar = Qstar.Qme;break;
                case 2:
                    myqstar = Qstar.QnLine; break;
                case 3:
                    myqstar = Qstar.OffLIne;  break;
                case 4:
                    myqstar = Qstar.Leave; break;
                case 5:
                   myqstar = Qstar.Busy; break;
                default:
                    Console.WriteLine("您输入不正确!");
                    break;

            }

            Console.WriteLine("您当前的状态为:"+myqstar);

          
        }
        //用结构体描述一个二维坐标
        struct Vector2
        {
           public  int x;
           public   int y;
        }

        //描述一个矩形的周长和位置
        struct Rectangle
        {
            Vector2 siex;
            int x;
            int y;


        }
        public void CoorDinate()
        {

            Vector2 point = new Vector2();
            point.x = 5;
            point.y = 5;
            Console.SetCursorPosition(point.x*2,point.y);
            Console.WriteLine("");
           

        }

    

//可以自由移动的物体
public void Plain()
{
Rectangle rectangle = new Rectangle();
rectangle.siex.x = 2;
rectangle.siex.y = 3;


Console.Write("■");
while (true)
{
char direction = Console.ReadKey(true).KeyChar;//监听方向键
switch (direction)
{
case 'w':
rectangle.siex.y--; break;
case 's':
rectangle.siex.y++; break;
case 'a':
rectangle.siex.x++; break;
case 'd':
rectangle.siex.x--; break;
default:
break;
}


Console.Clear();//清楚缓存画面


for (int i = 0; i < rectangle.siex.x; i++)//重新定义位置
{
for (int j = 0; j < rectangle.siex.y; j++)
{
if (rectangle.siex.x > 0 && rectangle.siex.y > 0)
{
Console.SetCursorPosition((rectangle.siex.x + i) * 2, rectangle.siex.y + j);

}
}


}
Console.Write("■");//绘制物体


}
}


    }

 

 

posted @ 2019-01-03 13:49  D个人笔记  阅读(300)  评论(0编辑  收藏  举报