ImageVerifierCode 换一换
格式:DOCX , 页数:27 ,大小:134.17KB ,
资源ID:6543146      下载积分:10 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/6543146.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(C#停车位游戏.docx)为本站上传会员【xrp****65】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

C#停车位游戏.docx

1、 郑州轻工业学院 实训报告 实训名称: 停车位游戏 指导教师: 姓名: 学号: 班级: 提交日期: 1. 实训目的 通过开发一款停车场游戏程序,熟练掌握C#编程语言、面向对象程序设计方法和可视化编程技术。 2. 实训题目 使用C#编程语言,开发一款停车场游戏。 3. 功能描述 游戏基本功能描述如下: 1) 停车场有 5 种颜色的汽车和 6 个车位。 2) 每一辆汽车对应颜色的车位。 3) 车位之间有的有通道,有的没有。 4) 最初 5 种颜色的汽车未停在对

2、应颜色的车位。 5) 玩家点击汽车,实现将该汽车沿通道移动到空闲的车位上;当该汽车与空间的车位之间没有通道时,则不移动汽车。 6) 玩家可以点击按钮“自来一次”,重新开始游戏。 7) 当所有的汽车都听到对应颜色的车位上时,游戏成功。 8) 游戏有计分功能,分数点击一次减一。 9) 游戏有下一关,地图难度增加。 10)游戏有当前时间显示。 4. 需求分析 根据功能描述可知,停车场游戏的系统结构图如下所示。 5. 设计说明 根据需求分析可知,车位具有位置、大小和颜色等属性,定义Space类用于描述车位的信息。通道具有起点和终点两个属性,定义 Road类用于

3、描述通道的信息以及通道与车位之间的关系。车具有位置 和颜色等属性,定义Car类用于描述车的信息以及车停留在哪个车位, 并实现车的移动功能。 为了使游戏的运行更易于控制,定义Game类用于启动游戏、控 制游戏和结束游戏。 综上所述,在停车场游戏中,有Space(车位)、Road(通道)、 Car(车)、Game(游戏)和Form1(用户接口)五个类。停车场 游戏的逻辑模型如下图所示。 6. 源代码 Form1.cs源码: using System; using System.Collections.Generic; using System.Compone

4、ntModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { private Game game; public Form1() { InitializeComponen

5、t(); score.Text = Convert.ToString(Convert.ToInt32(score.Text)); game = new Game(); for (int i = 0; i < 5; i++) { string name = "pictureBox" + i.ToString(); PictureBox pBox = (PictureBox)this.Controls.Find(name,fal

6、se)[0]; pBox.Location = new Point(game.cars[i].center.X - pictureBox0.Width / 2, game.cars[i].center.Y - pictureBox0.Height / 2); pBox.Visible = true; } } private void pictureBox0_Click(object sender, EventArgs e) {

7、 PictureBox pBox = (PictureBox)sender; if (game.df > 0) { game.df--; score.Text = game.df.ToString(); } else pictureBox0.Enabled = false; if (game.MoveCar(0, game.cars[0].spaceNum,

8、game.freeSpaceNum)) { pBox.Location = new Point(game.cars[0].center.X - pBox.Width / 2, game.cars[0].center.Y - pBox.Height / 2); if (game.Success()) { MessageBox.Show("您的得分为:" + game.df.ToString(), "恭喜!成功了", Messag

9、eBoxButtons.OK, MessageBoxIcon.Information ); } }

10、 else { MessageBox.Show("不能移动"); } if (game.df <1) { MessageBox.Show("剩余步数为0,你没法再走了"); }

11、 } private void pictureBox1_Click(object sender, EventArgs e) { PictureBox pBox = (PictureBox)sender; if (game.df > 0) { game.df--; score.Text = game.df.ToString(); }

12、 else pictureBox1.Enabled = false; if (game.MoveCar(1, game.cars[1].spaceNum, game.freeSpaceNum)) { pBox.Location = new Point(game.cars[1].center.X - pBox.Width / 2, game.cars[1].center.Y - pBox.Height / 2);

13、 if (game.Success()) { MessageBox.Show("您的得分为:" + game.df.ToString(), "恭喜!成功了", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } else { MessageBox.Show("不能移动"); }

14、 if (game.df <= 0) { MessageBox.Show("剩余步数为0,你没法再走了"); } } private void pictureBox2_Click(object sender, EventArgs e) { PictureBox pBox = (PictureBox)sender; if (game.df >

15、 0) { game.df--; score.Text = game.df.ToString(); } else pictureBox2.Enabled = false; if (game.MoveCar(2, game.cars[2].spaceNum, game.freeSpaceNum)) { pBox.Location =

16、new Point(game.cars[2].center.X - pBox.Width / 2, game.cars[2].center.Y - pBox.Height / 2); if (game.Success()) { MessageBox.Show("您的得分为:" + game.df.ToString(), "恭喜!成功了", MessageBoxButtons.OK, MessageBoxIcon.Information );

17、 } } else { MessageBox.Show("不能移动"); } if (game.df <= 0) { MessageBox.Show("剩余步数为0,你没法再走了"); } } private void pictureBox3_Clic

18、k(object sender, EventArgs e) { PictureBox pBox = (PictureBox)sender; if (game.df > 0) { game.df--; score.Text = game.df.ToString(); } else pictureBox3.Enabled = false;

19、 if (game.MoveCar(3, game.cars[3].spaceNum, game.freeSpaceNum)) { pBox.Location = new Point(game.cars[3].center.X - pBox.Width / 2, game.cars[3].center.Y - pBox.Height / 2); if (game.Success()) {

20、 MessageBox.Show("您的得分为:" + game.df.ToString(), "恭喜!成功了", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } else { MessageBox.Show("不能移动"); } if (game.df <= 0) { M

21、essageBox.Show("剩余步数为0,你没法再走了"); pictureBox3.Enabled = false; } } private void pictureBox4_Click(object sender, EventArgs e) { PictureBox pBox = (PictureBox)sender; if (game.df > 0) {

22、 game.df--; score.Text = game.df.ToString(); } else pictureBox4.Enabled = false; if (game.MoveCar(4, game.cars[4].spaceNum, game.freeSpaceNum)) { pBox.Location = new Point(game.cars[4

23、].center.X - pBox.Width / 2, game.cars[4].center.Y - pBox.Height / 2); if (game.Success()) { MessageBox.Show("您的得分为:" + game.df.ToString(), "恭喜!成功了", MessageBoxButtons.OK, MessageBoxIcon.Information ); }

24、 } else { MessageBox.Show("不能移动"); } if (game.df <= 0) { MessageBox.Show("剩余步数为0,你没法再走了"); pictureBox4.Enabled = false; } } private void buttonSt

25、art_Click(object sender, EventArgs e) { game.PaintClear(this.CreateGraphics()); score.Text = Convert.ToString(Convert.ToInt32(100)); game = new Game(); for (int i = 0; i < 5; i++) { string name = "pictureBox"

26、 i.ToString(); PictureBox pBox = (PictureBox)this.Controls.Find(name,false)[0]; pBox.Location = new Point(game.cars[i].center.X - pictureBox0.Width / 2, game.cars[i].center.Y - pictureBox0.Height / 2); pBox.Visible = true; pBox.Ena

27、bled = true; } } private void buttonStart_Paint(object sender, PaintEventArgs e) { game.PaintParkingLot(this.CreateGraphics()); } private void score_Click(object sender, EventArgs e) { } private

28、 void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("1.单击小车可以移动到其所在圆圈连线对应的圆圈内\n2.将小车移动到对应颜色圆圈内即为获胜\n3.得分高玩得好", "帮助", MessageBoxButtons.OK, MessageBoxIcon.Information);

29、 } private void buttonNext_Click(object sender, EventArgs e) { game.PaintClear(this.CreateGraphics()); game.Next(); for (int i = 0; i < 5; i++) { string name = "pictureBox" + i.ToString(); Pict

30、ureBox pBox = (PictureBox)this.Controls.Find(name, false)[0]; pBox.Location = new Point(game.cars[i].center.X - pictureBox0.Width / 2, game.cars[i].center.Y - pictureBox0.Height / 2); pBox.Visible = true; pBox.Enabled = true; }

31、 game.PaintParkingLot(this.CreateGraphics()); } private void toolTip1_Popup(object sender, PopupEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { this.toolTip1.SetToolTip(this.label1, "您的剩余步

32、数"); this.toolTip1.SetToolTip(this.score , "您的剩余步数"); this.toolTip1.SetToolTip(this.buttonStart, "开始新的游戏"); this.toolTip1.SetToolTip(this.buttonNext, "直接下一关"); this.toolTip1.SetToolTip(this.help, "获取帮助"); this.toolTip1.SetToolTip(this.

33、time, "时间"); } private void timer1_Tick(object sender, EventArgs e) { DateTime dt = DateTime.Now; time.Text = dt.ToString(); } private void buttonNext_Paint(object sender, PaintEventArgs e) { }

34、private void time_TextChanged(object sender, EventArgs e) { } } } Car.cs源码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace WindowsFormsApplication2 { class Car { public Point

35、 center; public int spaceNum; public Car(Point center, int spaceNum) { this.center = center; this.spaceNum = spaceNum; } public void Move(Point center, int spaceNum) { this.center = center; this

36、spaceNum = spaceNum; } } } Game.cs源码: using System; using System.Collections.Generic; using System.Linq; using System.Drawing; using System.Text; namespace WindowsFormsApplication2 { class Game { public Space[] spaces; public Road[] roads;

37、 public Car[] cars; public int freeSpaceNum; public int df = 10; public Game() { spaces = new Space[6]; roads = new Road[9]; cars = new Car[5]; spaces[0] = new Space(new Point(200, 400), Color.Blue);

38、 spaces[1] = new Space(new Point(200, 200), Color.Red); spaces[2] = new Space(new Point(500, 100), Color.Yellow); spaces[3] = new Space(new Point(800, 200), Color.Green); spaces[4] = new Space(new Point(800, 400), Color.Pink); spaces[5]

39、 = new Space(new Point(500, 500), Color.Black); roads[0] = new Road(0, 1, spaces[0].center, spaces[1].center); roads[1] = new Road(1, 2, spaces[1].center, spaces[2].center); roads[2] = new Road(2, 3, spaces[2].center, spaces[3].center); roads[3] =

40、new Road(3, 4, spaces[3].center, spaces[4].center); roads[4] = new Road(4, 5, spaces[4].center, spaces[5].center); roads[5] = new Road(5, 0, spaces[5].center, spaces[0].center); roads[6] = new Road(0, 3, spaces[0].center, spaces[3].center); roads[7

41、] = new Road(1, 4, spaces[1].center, spaces[4].center); roads[8] = new Road(2, 5, spaces[2].center, spaces[5].center); cars[0] = new Car(spaces[1].center, 1); cars[1] = new Car(spaces[2].center, 2); cars[2] = new Car(spaces[3].center, 3);

42、 cars[3] = new Car(spaces[4].center, 4); cars[4] = new Car(spaces[0].center, 0); freeSpaceNum = 5; } public void PaintParkingLot(Graphics g) { foreach (Road r in roads) { r.Paint(g); }

43、 foreach (Space s in spaces) { s.Paint(g); } } public void PaintClear(Graphics g) { foreach (Road r in roads) { r.Clear(g); } foreach (Space s in sp

44、aces) { s.Clear(g); } } public bool Success() { for (int i = 0; i < 5; i++) { if (i != cars[i].spaceNum) return false; } return true;

45、 } public bool MoveCar(int carNum, int start, int end) { foreach (Road r in roads) { if (r.spaceStartNum == start && r.spaceEndNum == end) { cars[carNum].Move(spaces[end].center, end);

46、 freeSpaceNum = start; return true; } if (r.spaceStartNum == end && r.spaceEndNum == start) { cars[carNum].Move(spaces[end].center, end); freeSpaceNum = start;

47、 return true; } } return false; } public void Next() { spaces = new Space[6]; roads = new Road[9]; cars = new Car[5]; spaces[0] = new Space(new Point(200, 350), Color.Blue);

48、 spaces[1] = new Space(new Point(200, 100), Color.Red); spaces[2] = new Space(new Point(500, 100), Color.Yellow); spaces[3] = new Space(new Point(800, 100), Color.Green); spaces[4] = new Space(new Point(800, 350), Color.Pink); spaces[5]

49、 = new Space(new Point(500, 500), Color.Black); roads[0] = new Road(0, 1, spaces[0].center, spaces[1].center); roads[1] = new Road(1, 2, spaces[1].center, spaces[2].center); roads[2] = new Road(2, 3, spaces[2].center, spaces[3].center); roads[3] =

50、new Road(3, 4, spaces[3].center, spaces[4].center); roads[4] = new Road(4, 5, spaces[4].center, spaces[5].center); roads[5] = new Road(5, 0, spaces[5].center, spaces[0].center); roads[6] = new Road(0, 3, spaces[0].center, spaces[3].center); roads[7

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服