今天是实训第二天,桂老师开始讲解C#的基础知识,相较于昨天的各种理论,今天的知识点明显好掌握一些,所以听的也比较有动力.
    上午的时候主要讲了控制台的一些属性方法,还有命名法,下午才是重头戏,一直没有理解的值类型和引用类型在桂老师生动的课件下终于掌握了.真是收获太大了!
    今天主要的代码写了两个,基本都跟控制台有关,第一个是用控制台的BEEP方法来做一个发音的小程序,
没什么难度.不过音准一直找不到..第二个是用控制台做一个登陆程序,关键点在于密码用readkey来隐藏,还有在用户操作的类里加一个递归.其他没什么难度了,都做完之后时间还早,考虑到我数组的理解一直比较差,所以在书上找了一练习题--龟图.代码都记下来,望大家给出意见,各种方面都太繁琐了..
    龟图的定义就是输入1的时候画笔向上,即为不画图模式,输入2时画笔向下,进入画图模式,输入3向右转,4向左转,输入5,*,即为向前走*步,输入6,画出这个20*20的数组,默认为乌龟在0,0位置向右方向.
class Program
        {
                 int painter = 0;
                 int upDown = 0;
                 int leftRight = 0;
                 int paintLength = 0;
                 int whereToGo = 1;
                 int whereToTurn = 0;

                 private void GetWhere()
                {
                         if (whereToTurn == 0 && whereToGo > 1)
                        {
                                whereToGo--;
                        }
                         else if (whereToTurn == 0 && whereToGo == 1)
                        {
                                whereToGo = 4;
                        }
                         if (whereToTurn == 1 && whereToGo == 3)
                        {
                                whereToGo = 4;
                        }
                         else if (whereToTurn == 1 && whereToGo != 3)
                        {
                                whereToGo = (whereToGo + 1) % 4;
                        }


                }
                 private void paint( int where, int length, int[,] myPaint)
                {


                         if (where == 1)
                        {
                                 for ( int i = 0; i < length; i++)
                                {
                                        myPaint.SetValue(1, i + leftRight, upDown);

                                }
                                leftRight = leftRight + length;
                        }
                         if (where == 2)
                        {
                                 for ( int i = 0; i < length; i++)
                                {
                                        myPaint.SetValue(1, leftRight, i + upDown);

                                }
                                upDown = upDown + length;
                        }
                         if (where == 3)
                        {
                                 for ( int i = 0; i < length; i++)
                                {
                                        myPaint.SetValue(1, leftRight - i, upDown);

                                }
                                leftRight = leftRight - length;
                        }
                         if (where == 4)
                        {
                                 for ( int i = 0; i < length; i++)
                                {
                                        myPaint.SetValue(1, leftRight, upDown - i);

                                }
                                upDown = upDown - length;
                        }
                }
                 static void Main( string[] args)
                {
                        Program d = new Program();
                         int[,] myPaint = new int[20, 20];

                         for ( int i = 0; i < 20; i++)
                        {
                                 for ( int j = 0; j < 20; j++)
                                {
                                        myPaint.SetValue(0, i, j);
                                }
                        }
                         while ( true)
                        {
                                Console.WriteLine( "请输入指令");
                                 string zhiling = Console.ReadLine();
                                 if (zhiling == "1")
                                {
                                        d.painter = 0;
                                }
                                 if (zhiling == "2")
                                {
                                        d.painter = 1;
                                }
                                 if (zhiling == "3")
                                {
                                        d.whereToTurn = 1;
                                        d.GetWhere();
                                }
                                 if (zhiling == "4")
                                {
                                        d.whereToTurn = 0;
                                        d.GetWhere();
                                }
                                 if (zhiling.IndexOf(',') >= 1)
                                {
                                         string temp = "";
                                        CharEnumerator charZhiling = zhiling.GetEnumerator();
                                        charZhiling.MoveNext();
                                        charZhiling.MoveNext();

                                         for ( int i = 0; i < zhiling.Length - 2; i++)
                                        {

                                                charZhiling.MoveNext();
                                                temp = temp + charZhiling.Current.ToString();
                                        }
                                        d.paintLength = Int32.Parse(temp);
                                        d.paint(d.whereToGo, d.paintLength, myPaint);

                                }
                                 if (zhiling == "6")
                                {
                                         for ( int i = 0; i < 20; i++)
                                        {
                                                 for ( int j = 0; j < 20; j++)
                                                {
                                                         if (j < 19)
                                                        {
                                                                Console.Write(myPaint.GetValue(j, i));
                                                        }
                                                         if (j == 19)
                                                        {
                                                                Console.WriteLine(myPaint.GetValue(j, i));
                                                        }
                                                }
                                        }
                                }

                        }

                }

        }