AI智能
改变未来

C#第七课文字游戏2.0版本

using System;using System.Threading;namespace @new{class Program{/*常量初始化*/#region//昵称static string name = \"\";//生命static int hp;//当前生命static int c_hp;//成长生命static int g_hp;//攻击力static int atk;//成长攻击力static int g_atk;//防御static int def;//成长防御static int g_def;//速度static int speed;//成长速度static int g_speed;//等级static int level = 1;//当前经验static int exp = 0;//升级所需经验static int g_exp = 1000;//金钱static int money = 100;//查看面板#endregion//武器 衣服 鞋子static Equip wuqi;static int wuqi_atk;static Equip yifu;static int yifu_hp;static Equip xiezi;static int xiezi_speed;//装备中转站static string q1 = null;static string q2 = null;static string q3 = null;//装备道具enum EquipType{wuqi,yifu,xiezi}struct Equip{public EquipType type;public string name;public string des;public int hp;public int atk;public int speed;public Equip(EquipType type, string name, string des, int hp, int atk, int speed){this.type = type;this.name = name;this.des = des;this.hp = hp;this.atk = atk;this.speed = speed;}}static void EquipItem(Equip a){switch (a.type){case EquipType.wuqi:Log(\"你装备了武器:\" + a.name + \" 它\" + a.des + \" 攻击力+\" + a.atk);//装备穿戴wuqi_atk = a.atk;//装备中转站内装备放入背包数组BeiBao(q1);//新的装备再次放入装备中转站q1 = a.name;wuqi = a;break;case EquipType.yifu:Log(\"你装备了衣服:\" + a.name + \" 它\" + a.des + \" 生命+\" + a.hp);yifu_hp = a.hp;BeiBao(q2);q2 = a.name;yifu = a;break;case EquipType.xiezi:Log(\"你装备了鞋子:\" + a.name + \" 它\" + a.des + \" 速度+\" + a.speed);xiezi_speed = a.speed;BeiBao(q3);q3 = a.name;xiezi = a;break;}}//背包static string[] a = new string[20];static void BeiBao(string str){for (int n = 0; n < 10; n++){if (a[n] == null){a[n] = str;break;}}Console.WriteLine(\"当前你的背包里有:\");for (int m = 0; m <= 9; m++){if (a[m] == null){break;}Console.Write(a[m] + \" \");}Console.WriteLine();}//面板提示static void ShowInfo(){Console.WriteLine(\"你现在状态:生命为:{0}/{1}+{2},攻击力为:{3}+{4},防御为:{5},速度为:{6}+{7},金钱为:{8},等级为:{9},经验为:{10}/{11}\", c_hp, hp, yifu.hp, atk, wuqi.atk, def, speed, xiezi_speed, money, level, exp, g_exp);Log(\"武器:\" + wuqi.name + \" 衣服:\" + yifu.name + \" 鞋子:\" + xiezi.name);Thread.Sleep(1000);BeiBao(null);}//延迟输出函数static void Log(string text){Console.WriteLine(text);Thread.Sleep(1000);}//战前准备以及战斗过程static void Battle(string e_name, int e_hp, int e_atk, int e_speed, int e_satk, int e_miss, int e_money, int e_exp){Log(\"你遇到了\" + e_name + \"!是否在战斗前消耗10银两回满生命?\");ShowInfo();Console.WriteLine(e_name + \"现在的状态:生命为:{0},攻击力为:{1},速度为:{2},暴击为:{3},闪避为:{4},金钱为:{5},经验为:{6}\", e_hp, e_atk, e_speed, e_satk, e_miss, e_money, e_exp);Thread.Sleep(1000);Log(\"1,回满 2,跳过\");string str = Console.ReadLine();if (str == \"1\" && money >= 10){c_hp = hp+yifu_hp ;money -= 10;Log(\"血量已回满!\");ShowInfo();}//判断先手bool playerAtk = speed + xiezi_speed > e_speed;while (true){//如果是玩家攻击if (playerAtk){//下一次攻击轮到敌人playerAtk = false;//判定闪避if (new Random().Next(0, 100) < e_miss){Log(\"你向\" + e_name + \"砍出一刀,却被\" + e_name + \"轻松地躲了过去!\");continue;}//敌人掉血int num = new Random().Next(atk + wuqi_atk - 5, atk + wuqi_atk + 5);e_hp -= num;Log(\"你向\" + e_name + \"砍出一刀,\" + e_name + \"受到了\" + num + \"点伤害。\");//判定敌人死亡if (e_hp <= 0){Log(\"你击败了\" + e_name + \",你获得了\" + e_money + \"金钱与\" + e_exp + \"经验!\");money += e_money;exp += e_exp;LevelUp();ShowInfo();break;}}else{//当前敌人攻击,下次玩家攻击playerAtk = true;if (new Random().Next(0, 100) < e_satk){if(e_atk * 2 > def){c_hp -= e_atk * 2 - def;Log(e_name + \"使出了斩无极,触发了暴击效果,对你造成了\" + (e_atk * 2 - def) + \"点伤害\");}else{Log(e_name + \"使出了斩无极,触发了暴击效果,对你造成了0点伤害\");}}else{if (e_atk > def){c_hp -= e_atk - def;Log(e_name + \"使出了横扫,对你造成了\" + (e_atk - def) + \"点伤害\");}else{Log(e_name + \"使出了横扫,对你造成了0点伤害\");}}//如果玩家死亡if (c_hp <= 0){Log(\"你被残忍地杀害了。\");Log(\"胜败乃兵家常事,请重新来过\");//退出Environment.Exit(0);}}}}//判定升级static void LevelUp(){while (exp >= g_exp){level++;hp += g_hp;c_hp = hp + yifu_hp;atk += g_atk;def += g_def;speed += g_speed;exp -= g_exp;g_exp = level * 1000;}}//角色创建static void CreateCharacter(){//提示Console.WriteLine(\"请输入你的角色名称:\");//输入角色名称name = Console.ReadLine();//判断是否输入了名称if (string.IsNullOrEmpty(name)){//给与默认名称name = \"李逍遥\";}//血量随机100到120之间的数hp = new Random().Next(100, 120);//当前血量c_hp = hp;//成长血量g_hp = new Random().Next(100, 120);//攻击力atk = new Random().Next(10, 20);//成长攻击g_atk = new Random().Next(10, 20);//防御def = new Random().Next(5, 10);//成长防御g_def = new Random().Next(5, 10);//速度speed = new Random().Next(5, 10);//成长速度g_speed = new Random().Next(5, 10);Log(\"恭喜你,角色创建成功!\");ShowInfo();}//角色评分static void PingFen(){int a = hp + atk + def + speed;int b = g_hp + g_atk + g_def + g_speed;int c = a + b;//120-160之间:120-130;130-150;150-160。if (a <= 130){Log(\"你的角色初始属性很差。\");}else if (a <= 150){Log(\"你的角色初始属性一般。\");}else{Log(\"你的角色初始属性很好。\");}if (b <= 130){Log(\"你的角色天赋很差。\");}else if (b <= 150){Log(\"你的角色天赋一般。\");}else{Log(\"你的角色天赋很好。\");}if (c <= 260){Log(\"综合来看,系统这边建议你转生重开呢!\");}else if (b <= 300){Log(\"综合来看,系统这边建议你可以开始正常游玩了。\");}else{Log(\"综合来看,系统这边对你佩服的五体投地!\");}}//怪物随机enum EnemyType{小木马,大木马,键盘侠,圣母,鲤鱼精,猫妖,大魔法师,魔神}struct Enemy{public EnemyType type;public Enemy(EnemyType type){this.type = type;}}static void EnemyFight(Enemy a){for (int i = 0; i < 3; i++){Console.WriteLine(\"按一下回车键开始移动\");Console.ReadKey();if (new Random().Next(0, 5) > 3){switch (a.type){case EnemyType.小木马:Battle(\"小木马\", 20, 20, 1, 5, 5, 20, 500);break;case EnemyType.大木马:Battle(\"大木马\", 40, 30, 1, 10, 10, 20, 1000);break;case EnemyType.键盘侠:Battle(\"键盘侠\", 80, 40, 5, 10, 10, 20, 1000);break;case EnemyType.圣母:Battle(\"圣母\", 100, 50, 10, 15, 15, 20, 1500);break;case EnemyType.鲤鱼精:Battle(\"鲤鱼精\", 200, 60, 15, 15, 15, 20, 2000);break;case EnemyType.猫妖:Battle(\"猫妖\", 300, 70, 5, 20, 15, 20, 2500);break;case EnemyType.大魔法师:Battle(\"大魔法师\", 1000, 80, 25, 20, 25, 100, 5000);break;case EnemyType.魔神:Battle(\"魔神\", 1500, 90, 30, 30, 30, 200, 10000);break;}}}}/*开始冒险历程*///NPC1对话选择static void NPC1(string text1,string text2){Log(\"你的左边有一名\" + text1 + \",右边有一名\" + text2 + \",你要选择和谁对话?\");Log(\"1.\" + text1 + \" 2.\" + text2 + \" 3.跳过\");string str = Console.ReadLine();if (str == \"1\"){Log(\"初级任务:给予\" + text1 + \" 20两银子,换取100点生命上限提升。\");Log(\"1,换 2,跳过\");str = Console.ReadLine();if (str == \"1\" && money >= 20){hp += 100;c_hp += 100;money -= 20;Log(\"兑换成功!\");ShowInfo();}}else if (str == \"2\"){Log(\"初级任务:给予\" + text2 + \" 50两银子,换取武器青龙偃月刀\");Log(\"1,换 2,跳过\");str = Console.ReadLine();if (str == \"1\" && money >= 50){money -= 50;EquipItem(new Equip(EquipType.wuqi, \"青龙偃月刀\", \"锋利无比\", 0, 20, 0));Log(\"兑换成功!\");ShowInfo();}}Log(\"你离开了NPC。\");}//NPC2对话选择static void NPC2(string text1, string text2){Log(\"你的左边有一名\" + text1 + \",右边有一名\" + text2 + \",你要选择和谁对话?\");Log(\"1.\" + text1 + \" 2.\" + text2 + \" 3.跳过\");string str = Console.ReadLine();if (str == \"1\"){Log(\"初级任务:给予\" + text1 + \" 20两银子,换取衣服黄金圣衣。\");Log(\"1,换 2,跳过\");str = Console.ReadLine();if (str == \"1\" && money >= 20){money -= 20;EquipItem(new Equip(EquipType.yifu, \"黄金圣衣\", \"坚固无比\", 300, 0, 0));Log(\"兑换成功!\");ShowInfo();}}else if (str == \"2\"){Log(\"初级任务:给予\" + text2 + \" 20两银子,换取鞋子清欢鞋。\");Log(\"1,换 2,跳过\");str = Console.ReadLine();if (str == \"1\" && money >= 20){money -= 20;EquipItem(new Equip(EquipType.xiezi, \"清欢鞋\", \"快如闪电\", 0, 0, 5));Log(\"兑换成功!\");ShowInfo();}}Log(\"你离开了NPC。\");}//NPC3对话选择static void NPC3(){Log(\"你遇到了一个神秘人,50两银子可以换取100生命上限的提升。\");while(true){Log(\"1,兑换一次 2,放弃\");string str = Console.ReadLine();if (str == \"1\" && money >= 50){money -= 50;hp += 100;c_hp += 100;Log(\"兑换成功!\");ShowInfo();Log(\"是否继续\");}else{break;}}}//NPC4对话选择static void NPC4(){Log(\"啊啦啊啦!这位小弟弟,要不要和大姐姐去迷雾森林里玩呀。\");Log(\"伴随着一阵眩晕感,你昏了过去,刚醒来的你遇到了这位大姐姐,对于她的盛情邀请你打算怎么办?\");Log(\"1,逃跑 2,接受她的邀请\");string str = Console.ReadLine();if (str == \"1\"){Map();}else{Log(\"陌生女子觉得你是一个很轻浮的人,于是你被残忍地杀害了。\");Environment.Exit(0);}}static void Map(){int x = 3, y = 1;//记录小人初始位置int[,] map = new int[10, 10]{{1,1,1,1,1,1,1,1,1,1},{1,0,0,0,0,1,0,0,0,1},{1,0,0,0,0,1,0,0,0,1},{1,4,2,0,0,1,0,0,0,1},{1,0,0,0,0,1,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,0,0,0,0,1},{1,0,0,0,0,0,0,0,3,1},{1,1,1,1,1,1,1,1,1,1}};//打印初始图for (int i = 0; i < 10; i++){for (int j = 0; j < 10; j++){if (map[i, j] == 0){Console.Write(\"  \");}else if (map[i, j] == 1){Console.Write(\"■\");}else if (map[i, j] == 2){Console.Write(\"□\");}else if (map[i, j] == 3){Console.Write(\"★\");}else if (map[i, j] == 4){Console.Write(\"♀\");}}Console.WriteLine();}while (true){ConsoleKeyInfo s = Console.ReadKey();int t = map[x, y];if (s.Key.ToString() == \"RightArrow\"){if (map[x, y + 1] == 0){map[x, y] = map[x, y + 1];map[x, y + 1] = t;y++;}else if (map[x, y + 1] == 2 && map[x, y + 2] != 1){int m = map[x, y + 1];map[x, y + 1] = t;map[x, y] = 0;map[x, y + 2] = m;y++;}}else if (s.Key.ToString() == \"LeftArrow\"){if (map[x, y - 1] == 0){map[x, y] = map[x, y - 1];map[x, y - 1] = t;y--;}else if (map[x, y - 1] == 2 && map[x, y - 2] != 1){int m = map[x, y - 1];map[x, y - 1] = t;map[x, y] = 0;map[x, y - 2] = m;y--;}}else if (s.Key.ToString() == \"UpArrow\"){if (map[x - 1, y] == 0){map[x, y] = map[x - 1, y];map[x - 1, y] = t;x--;}else if (map[x - 1, y] == 2 && map[x - 2, y] != 1){int m = map[x - 1, y];map[x - 1, y] = t;map[x, y] = 0;map[x - 2, y] = m;x--;}}else if (s.Key.ToString() == \"DownArrow\"){if (map[x + 1, y] == 0){map[x, y] = map[x + 1, y];map[x + 1, y] = t;x++;}else if (map[x + 1, y] == 2 && map[x + 2, y] != 1){int m = map[x + 1, y];map[x + 1, y] = t;map[x, y] = 0;map[x + 2, y] = m;x++;}}Console.Clear();for (int i = 0; i < 10; i++){for (int j = 0; j < 10; j++){if (map[i, j] == 0){Console.Write(\"  \");}else if (map[i, j] == 1){Console.Write(\"■\");}else if (map[i, j] == 2){Console.Write(\"□\");}else if (map[i, j] == 3){Console.Write(\"★\");}else if (map[i, j] == 4){Console.Write(\"♀\");}}Console.WriteLine();}if (map[8, 8] == 2){Console.WriteLine(\"逃脱成功!\");break;}}}//新手村static void XinShouCun(){Log(\"***********************************\");Log(\"年轻人,欢迎来到计算机大陆。\");Log(\"传说,上古时期,众神混战,微软公司陨落于此,故得此名。\");NPC1(\"360安全卫士\", \"电脑管家\");Log(\"你需要找个地方熟悉win10系统。\");EnemyFight(new Enemy(EnemyType.小木马));EnemyFight(new Enemy(EnemyType.大木马));NPC1(\"QQ\", \"微信\");EnemyFight(new Enemy(EnemyType.键盘侠));EnemyFight(new Enemy(EnemyType.圣母));NPC2(\"商人1\", \"商人2\");EnemyFight(new Enemy(EnemyType.键盘侠));EnemyFight(new Enemy(EnemyType.圣母));Log(\"你感觉自己有点虚,又回去找商人买东西。\");NPC2(\"商人1\", \"商人2\");EnemyFight(new Enemy(EnemyType.键盘侠));EnemyFight(new Enemy(EnemyType.圣母));NPC3();}//喂鱼抽猫王国static void WeiYuChouMao(){Log(\"随着和野怪的搏杀,你渐渐地学会了如何一个人活下去。现在,你来到了位于计算机大陆北方的一个名为喂鱼抽猫的王国。\");Log(\"在这个国家,只有两个种族,鱼族和猫族。\");Log(\"你初来乍到,不知道伪装自己,被路边的士兵看到了,他们向你冲了过来。\");Log(\"你选择:1,战斗 2,逃跑\");string str = Console.ReadLine();if (str == \"1\"){EnemyFight(new Enemy(EnemyType.鲤鱼精));EnemyFight(new Enemy(EnemyType.猫妖));}else{Log(\"因为你逃跑了,喂鱼抽猫王国甚至派出了大魔法师来抓你。\");Log(\"你开始了逃命之旅。\");EnemyFight(new Enemy(EnemyType.鲤鱼精));EnemyFight(new Enemy(EnemyType.猫妖));EnemyFight(new Enemy(EnemyType.大魔法师));}Log(\"喂鱼抽猫王国已经把你定为一个非常危险的人,发动全国之力要来剿灭你。\");Log(\"其中有不少强大的魔神要亲自来杀了你,系统建议你快跑。\");EnemyFight(new Enemy(EnemyType.魔神));EnemyFight(new Enemy(EnemyType.魔神));EnemyFight(new Enemy(EnemyType.魔神));Log(\"你成功的活了下来。\");Log(\"你搜刮了魔神的财产\");EquipItem(new Equip(EquipType.wuqi, \"倚天剑\", \"所向披靡\", 0, 50, 0));EquipItem(new Equip(EquipType.yifu, \"绝对领域\", \"无人能破\", 500, 0, 0));EquipItem(new Equip(EquipType.xiezi, \"踏玉虚鞋\", \"迅疾如风\", 0, 0, 10));ShowInfo();}//火之高兴王国static void HuoZhiGaoXing(){Log(\"按照系统酱的估算,现在的你应该已经有十级了。(来自系统酱的吐槽:没有的话,那你也太黑了!)\");Log(\"系统酱认为你已经可以开启第二重世界了,在第二重世界中,你将会遇到更加强大的敌人,更多的装备,注你好运。\");Log(\"************************************\");NPC4();Log(\"你逃到了一个小村庄,在这里娶妻生子,安稳的度过了余生。\");Log(\"完结撒花!\");}static void Main(string[] args){Console.BackgroundColor = ConsoleColor.DarkBlue;Console.Clear();Console.ForegroundColor = ConsoleColor.Green;CreateCharacter();PingFen();XinShouCun();WeiYuChouMao();HuoZhiGaoXing();}}}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » C#第七课文字游戏2.0版本