站内搜索

搜索

手游源码-游戏源码-棋牌源码资源网-亲测源码-游戏搭建-破解游戏-网站源码-qq技术

100金币/天 购买
100金币/天 购买
100金币/天 购买

基于视频讲解《通过编程制作一款猜数字的小游戏》的完整源代码

16

主题

37

帖子

1

金币

绿钻会员

Rank: 3Rank: 3

积分
261
发表于 2022-2-26 15:58:34 | 显示全部楼层 |阅读模式
基于视频讲解《通过奇怪诡异恐怖猜数字的小游戏》的完整源代码:
设计界面 需要了解更多教程分享简单编程游戏代码大全(简单射击小游戏代码),都可以关注教程分享栏目—猴子技术宅()

    using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.threading; using system.windows.forms;  namespace windowsformsapplication1 {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }         thread th;         random rand = new random();         int randnum;         private void button1_click(object sender, eventargs e)         {             int x = 10;             int y = 60;             for (int i = 1; i <= 50; i++)             {                 button bt = new button();                 bt.text = i.tostring();                 bt.name = i.tostring();                 bt.width = 40;                 bt.height = 40;                 bt.location = new point(x, y);                 bt.click += new eventhandler(bt_click);                 x += 41;                 if (i % 10 == 0)                 {                     x = 10;                     y += 41;                 }                 controls.add(bt);             }             //新建一个线程             th = new thread(delegate ()             {                 int i = 0;                 while (true)                 {                     i = ++i > 1000000 ? 0 : i;                     this.invoke(                         (methodinvoker)delegate                         {                             label1.text = i.tostring();                         });                     thread.sleep(1000);                 }             });             th.isbackground = true;             th.start();             randnum = rand.next(1, 50);             button1.enabled = false;         }         private void bt_click(object sender, eventargs e)         {             control bc = sender as control;             if (int.parse(bc.name) > randnum)             {                 bc.backcolor = color.pink;                 bc.enabled = false;                 bc.text = "大";             }             if (int.parse(bc.name) < randnum)             {                 bc.backcolor = color.green;                 bc.enabled = false;                 bc.text = "小";             }             if (int.parse(bc.name) == randnum)             {                 bc.backcolor = color.red;                 bc.enabled = false;                 bc.text = "中";                 th.abort();  // 线程终止                  messagebox.show(string.format("终于猜中了,用时{1}秒,猜了{0}次!", getcount(), label1.text), "恭喜");             }         }         string getcount()         {             int pcount = -1;             foreach (control c in controls)             {                 if (!c.enabled)                 {                     pcount++;                 }             }             return pcount.tostring();         }     } } 

【天外神坛】免责声明及帮助
1.重要:如果遇到隐藏内容回复后显示为代码状态,直接刷新一下页面即可解决此问题。
2.本文部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责。
3.若您需要商业运营或用于其他商业活动,请您购买正版授权并合法使用。
4.如果本站有侵犯、不妥之处的资源,请在网站右边客服联系我们。将会第一时间解决!
5.本站所有内容均由互联网收集整理、网友上传,仅供大家参考、学习,不存在任何商业目的与商业用途。
6.本站提供的所有资源仅供参考学习使用,版权归原著所有,禁止下载本站资源参与商业和非法行为,请在24小时之内自行删除!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

老群被封加此新群不迷路。
上个主题 下个主题 快速回复 返回列表 客服中心 搜索 QQ加群
上个主题 下个主题 快速回复 返回列表 客服中心 搜索 QQ加群

QQ|Archiver|小黑屋|天外神坛

湘ICP备2021015333号

Powered by 天外神坛 X3.4 © 2020-2022 天外神坛