• 20150313


    练习:

    一、石头、剪刀、布,编辑程序

    //int a=r.Next(0,3); //int b=r.Next(0,3);

    //switch (a) //{ // case 0://剪刀 // x = "剪刀"; // break; // case 1://石头 // x = "石头"; // break; // case 2://布 // x = "布"; // break; // default: // x = "耍赖"; // break; //} //switch (b) //{ // case 0://剪刀 // y = "剪刀"; // break; // case 1://石头 // y = "石头"; // break; // case 2://布 // y = "布"; // break; // default: // y = "耍赖"; // break; //}
    //Console.WriteLine("x出的是"+x); //Console.WriteLine("y出的是" + y); //string jg = ""; //if (a==b) //{ // jg = "平局"; //} //else if (a>b) //{ // if (a==2&&b==0) // { // jg = "Y胜利"; // } // else // { // jg = "X胜利!"; // }
    //} //else if (b>a) //{ // if ((b==2&&a==0)) // { // jg = "X胜利!"; // } // else // { // jg = "Y胜利!"; // }
    //} //if (a==b) //{ // jg = "平局"; //} //else if (a>b||(b==2&&a==0)) //{ // jg = "a胜利"; //} //else if (b>a||(a==2&&b==0)) //{ // jg = "b胜利"; //}

     二、俩人对战游戏编程

    //        static void Main(string[] args) //        { //            wanjia wj1 = new wanjia(); //            wanjia wj2 = new wanjia(); //            Random r=new Random(); //            //载入姓名 //            Console.WriteLine("请输入第一个玩家昵称:"); //            wj1.nc = Console.ReadLine(); //            Console.WriteLine("请输入第二个玩家昵称:"); //            wj2.nc = Console.ReadLine(); //            while (true) //            { //            //载入血量 //            wj1.mp = 1000 + r.Next(0,1000); //            wj2.mp = 1000 + r.Next(0,1000); //            //载入法力 //            wj1.hp = 1000 + r.Next(0,1000); //            wj2.hp = 1000 + r.Next(0,1000); //            //载入攻击力 //            wj1.gongji = 50+ r.Next(0,100); //            wj2.gongji = 50 + r.Next(0,100); //            //载入防御力 //            wj1.fangyu = 50 + r.Next(0,100); //            wj2.fangyu = 50 + r.Next(0,100); //            //载入技能             //            wj1.jineng =new string [6]{"普通攻击","辟邪剑","寒光剑","清风剑","雷霆剑诀","无名剑诀"}; //            wj2.jineng =new string [6]{"普通攻击","葵花宝典","吸星大法","无法无天","大海无量","损人不利己"};            //            Console.WriteLine("昵称:" + wj1.nc + " 生命:" + wj1.mp + " 法力:" + wj1.hp + " 攻击:" + wj1.gongji + " 防御:" + wj1.fangyu); //            Console.WriteLine("VS"); //            Console.WriteLine("昵称:" + wj2.nc + " 生命:" + wj2.mp + " 法力:" + wj2.hp + " 攻击:" + wj2.gongji + " 防御:" + wj2.fangyu);

    //            Console.WriteLine("是否开始对阵(Y/N)?"); //            string s = Console.ReadLine();           //            if (s.ToUpper()=="N") //            { //                break; //            } //            else //            { //                //对战 //                while (true) //                { //                     int chushou = r.Next(0,3); //                if (chushou==0)//wj1对wj2出手 //                {                     //                    //掉血掉蓝计算函数                     //                    int dx = 0, dl = 0; //                    int ss = r.Next(0,6); //                    switch (ss) //                    { //                        case 0: //                            dx = r.Next(0, 20); //                            dl = r.Next(5, 15); //                            break; //                        case 1: //                            dx = r.Next(20, 40); //                            dl = r.Next(10, 20); //                            break; //                        case 2: //                            dx = r.Next(40, 80); //                            dl = r.Next(20, 40); //                            break; //                        case 3: //                            dx = r.Next(80, 120); //                            dl = r.Next(40, 80); //                            break; //                        case 4: //                            dx = r.Next(120, 200); //                            dl = r.Next(60, 100); //                            break; //                        case 5: //                            dx = r.Next(200, 500); //                            dl = r.Next(100, 200); //                            break;

    //                        default: //                            break; //                    }                     //                    dx = wj1.gongji + dx - wj2.fangyu;                     //                    wj2.mp -= dx; //                    wj1.hp -= dl; //                    if (wj2.mp<=0) //                    { //                        wj2.mp = 0;

    //                    } //                    if (wj1.hp <= 0) //                    { //                        wj1.hp = 0;

    //                    }                     //                    if (dx<0) //                    { //                        dx = 0; //                    } //                    if (dx == 0) //                    { //                        Console.WriteLine(wj2.nc+"成功躲过了"+wj1.nc+"的攻击"); //                    }                     //                    if (wj1.hp <= 0) //                    { //                        Console.WriteLine(wj1.nc + "没蓝了!!"); //                        chushou = 1; //                    } //                   Console.WriteLine(wj1.nc + "消耗" + dl + "点法力使出了" + wj1.jineng[ss] + ", " + wj2.nc + "掉血" + dx + "滴");                    //                    if (wj1.mp <= 0 && wj2.mp <= 0) //                    { //                        Console.WriteLine(wj1.nc + "与" + wj2.nc + "双双赴死了!!"); //                        break; //                    } //                    if (wj2.mp <= 0) //                    { //                        Console.WriteLine(wj1.nc + "把" + wj2.nc + "蹂躏死了!!"); //                        break; //                    } //                    Console.WriteLine(" "); //                    Console.WriteLine("昵称:" + wj1.nc + " 生命:" + wj1.mp + " 法力:" + wj1.hp);

    //                    Console.WriteLine("昵称:" + wj2.nc + " 生命:" + wj2.mp + " 法力:" + wj2.hp); //                    Console.WriteLine(" ");

    //                } //                   System.Threading.Thread.Sleep(1000); //                if (chushou==1)//wj2对wj1出手 //                {                     //                    //掉血掉蓝计算函数 //                    int dx = 0, dl = 0; //                    int ss = r.Next(0,6); //                    switch (ss) //                    { //                        case 0: //                            dx = r.Next(0, 20); //                            dl = r.Next(5, 15); //                            break; //                        case 1: //                            dx = r.Next(20, 40); //                            dl = r.Next(10, 20); //                            break; //                        case 2: //                            dx = r.Next(40, 80); //                            dl = r.Next(20, 40); //                            break; //                        case 3: //                            dx = r.Next(80, 120); //                            dl = r.Next(40, 80); //                            break; //                        case 4: //                            dx = r.Next(120, 200); //                            dl = r.Next(60, 100); //                            break; //                        case 5: //                            dx = r.Next(200, 500); //                            dl = r.Next(100, 200); //                            break;

    //                        default: //                            break; //                    } //                    dx = wj2.gongji + dx - wj1.fangyu; //                    wj1.mp -= dx; //                    wj2.hp -= dl; //                    if (dx < 0) //                    { //                        dx = 0; //                    } //                    if (dx == 0) //                    { //                        Console.WriteLine(wj2.nc + "成功躲过了" + wj1.nc + "的攻击"); //                    } //                    if (wj1.mp <= 0) //                    { //                        wj1.mp = 0;

    //                    } //                    if (wj2.hp <= 0) //                    { //                        wj2.hp = 0;

    //                    } //                    if (wj1.hp <= 0) //                    { //                        Console.WriteLine(wj1.nc + "没蓝了!!"); //                        chushou = 0; //                    } //                     Console.WriteLine(wj2.nc + "消耗" + dl + "点法力使出了" + wj2.jineng[ss] + ", " + wj1.nc + "掉血" + dx + "滴"); //                    if (wj1.mp <= 0 && wj2.mp <= 0) //                    { //                        Console.WriteLine(wj1.nc + "与" + wj2.nc + "双双赴死了!!"); //                        break; //                    } //                    if (wj2.mp <= 0) //                    { //                        Console.WriteLine(wj1.nc + "把" + wj2.nc + "蹂躏死了!!"); //                        break; //                    }

                      //                    Console.WriteLine(" "); //                    Console.WriteLine("昵称:" + wj1.nc + " 生命:" + wj1.mp + " 法力:" + wj1.hp); //                    Console.WriteLine("昵称:" + wj2.nc + " 生命:" + wj2.mp + " 法力:" + wj2.hp); //                    Console.WriteLine(" "); //                } //                else //                { //                    Console.WriteLine("双方都在等待对方露出破绽....."); //                } //                }               

    //            } //            Console.WriteLine("再来一局"); //            Console.ReadKey(); //            } //            Console.WriteLine("退出对战。。。。");

    三、推箱子编程

     static void Main(string[] args) ////        { ////            int x = 1, y = 1;//初始人的坐标 ////            int[,] tu = new int[10, 10]//定义原始地图 ////            { ////            {1,1,1,1,1,1,1,1,1,1}, ////            {1,4,0,0,0,0,0,0,0,1}, ////            {1,0,0,0,1,1,1,1,0,1}, ////            {1,0,0,0,1,5,0,1,0,1}, ////            {1,1,1,1,1,1,0,1,0,1}, ////            {1,1,0,0,0,0,0,1,0,1}, ////            {1,1,0,1,1,1,1,1,0,1}, ////            {1,1,0,0,0,0,0,0,0,1}, ////            {1,1,1,0,0,0,0,0,0,1}, ////            {1,1,1,1,1,1,1,1,1,1} ////            };//一张地图 ////            ditus(tu);//调用地图显示 ////            while (true) ////            { ////                int temp = 0;//临时变量 ////                ConsoleKeyInfo s = Console.ReadKey();//用s接收按键类型 ////                if (s.Key.ToString() == "UpArrow")//如果按键上键 ////                { ////                    if (tu[x - 1, y] == 0 || tu[x - 1, y] == 5)//如果上面是0或者5 ////                    { ////                        //交换位置 ////                        temp = tu[x - 1, y]; ////                        tu[x - 1, y] = tu[x, y]; ////                        tu[x, y] = temp; ////                        x--;//人的坐标上移一位 ////                    } ////                } ////                else if (s.Key.ToString() == "DownArrow")//如果按键下键 ////                { ////                    if (tu[x + 1, y] == 0 || tu[x + 1, y] == 5)//如果下面是0或者5 ////                    { ////                       // 交换位置 ////                        temp = tu[x + 1, y]; ////                        tu[x + 1, y] = tu[x, y]; ////                        tu[x, y] = temp; ////                        x++;//人的坐标下移一位 ////                    } ////                } ////                else if (s.Key.ToString() == "LeftArrow")//如果按键左键 ////                { ////                    if (tu[x, y - 1] == 0 || tu[x, y - 1] == 5)//如果左面是0或者5 ////                    { ////                        //交换位置 ////                        temp = tu[x, y - 1]; ////                        tu[x, y - 1] = tu[x, y]; ////                        tu[x, y] = temp; ////                        y--;//人的坐标左移一位 ////                    } ////                } ////                else if (s.Key.ToString() == "RightArrow")//如果按键右键 ////                { ////                    if (tu[x, y + 1] == 0 || tu[x, y + 1] == 5)//如果右面是0或者5 ////                    { ////                       // 交换位置 ////                        temp = tu[x, y + 1]; ////                        tu[x, y + 1] = tu[x, y]; ////                        tu[x, y] = temp; ////                        y++;//人的坐标右移一位 ////                    } ////                } ////                else ////                {

    ////                } ////                if (temp == 5)//如果移动后位置上是5 ////                { ////                    Console.WriteLine("成功走出迷宫!");//提示走出迷宫 ////                }

    ////                Console.Clear();//清屏 ////                ditus(tu);//显示地图 ////            } ////            Console.ReadLine(); ////        }

    ////        public static void ditus(int[,] tu)//创建ditus函数 ////        { ////            string[,] ditu = new string[10, 11];//定义string类型地图 ////            for (int i = 0; i < 10; i++) ////            { ////                for (int j = 0; j < 10; j++) ////                { ////                    if (tu[i, j] == 0) ////                    { ////                        ditu[i, j] = "  "; ////                    } ////                    if (tu[i, j] == 1) ////                    { ////                        ditu[i, j] = "■"; ////                    } ////                    if (tu[i, j] == 2) ////                    { ////                        ditu[i, j] = "●"; ////                    } ////                    if (tu[i, j] == 3) ////                    { ////                        ditu[i, j] = "◎"; ////                    } ////                    if (tu[i, j] == 4) ////                    { ////                        ditu[i, j] = "人"; ////                    } ////                    if (tu[i, j] == 5) ////                    { ////                        ditu[i, j] = "※"; ////                    } ////                    if (tu[i, j] == 7) ////                    { ////                        ditu[i, j] = "人"; ////                    } ////                } ////                ditu[i, 10] = " ";//换行 ////            } ////            foreach (string s in ditu)//打印地图 ////            { ////                Console.Write(s); ////            } ////        }

    ////    } ////}

    四、计算机

    static public double jaq(double x, double y, string m)         {

                double z;             m = (m == "加" || m == "+") ? "加" : (m == "减" || m == "-") ? "减" : (m == "乘" || m == "*" || m == "×") ? "乘" : (m == "除" || m == "/" || m == "÷") ? "除" : "加";             Console.WriteLine("进行的是" + m + "法运算");             switch (m)             {                 case "加":

                        z = x + y;                     break;                 case "减":

                        z = x - y;                     break;                 case "乘":

                        z = x * y;                     break;                 case "除":

                        z = x / y;                     break;                 default:

                        z = x + y;                     break;             }             return z;         }

            static void Main(string[] args)         {

                Console.Title = "加减乘除";

                double x, y, z = 0;             string m;             while (true)             {                 Console.WriteLine("第一个数:");                 x = Convert.ToDouble(Console.ReadLine());                 Console.WriteLine("运算符(默认为加):");                 m = Console.ReadLine();

                    Console.WriteLine("第二个数:");                 y = Convert.ToDouble(Console.ReadLine());

                    z = jaq(x, y, m);

                    Console.WriteLine("运算结果是" + z);                 ConsoleKeyInfo s;                 Console.TreatControlCAsInput = true;                 Console.WriteLine("按任意键从新开始(Esc退出) ");                 s = Console.ReadKey();

                    if (s.Key == ConsoleKey.Escape)                 {                     break;                 }

                }             Console.WriteLine("结束!!");             Console.ReadKey();

            }

        } }

  • 相关阅读:
    js根据ip地址获取城市地理位置
    vue-cli项目中使用mock结合axios-mock-adapter生成模拟数据
    将图片转canvas
    判断浏览器是否联网
    头尾固定中间高度自适应布局 css
    经典闭包
    多余文字转化为省略号css
    $.grep()
    node 图片转base64
    CentOS 7下安装Mysql 5.7
  • 原文地址:https://www.cnblogs.com/m123/p/4335981.html
Copyright © 2020-2023  润新知