




已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
郑州轻工业学院实训报告实训名称: 停车位游戏指导教师: 姓名: 学号: 班级: 提交日期: 1. 实训目的 通过开发一款停车场游戏程序,熟练掌握C#编程语言、面向对象程序设计方法和可视化编程技术。2. 实训题目使用C#编程语言,开发一款停车场游戏。 3. 功能描述 游戏基本功能描述如下: 1) 停车场有 5 种颜色的汽车和 6 个车位。 2) 每一辆汽车对应颜色的车位。 3) 车位之间有的有通道,有的没有。 4) 最初 5 种颜色的汽车未停在对应颜色的车位。 5) 玩家点击汽车,实现将该汽车沿通道移动到空闲的车位上;当该汽车与空间的车位之间没有通道时,则不移动汽车。 6) 玩家可以点击按钮“自来一次”,重新开始游戏。 7) 当所有的汽车都听到对应颜色的车位上时,游戏成功。8) 游戏有计分功能,分数点击一次减一。9) 游戏有下一关,地图难度增加。10)游戏有当前时间显示。4. 需求分析根据功能描述可知,停车场游戏的系统结构图如下所示。 5. 设计说明 根据需求分析可知,车位具有位置、大小和颜色等属性,定义Space类用于描述车位的信息。通道具有起点和终点两个属性,定义Road类用于描述通道的信息以及通道与车位之间的关系。车具有位置和颜色等属性,定义Car类用于描述车的信息以及车停留在哪个车位,并实现车的移动功能。 为了使游戏的运行更易于控制,定义Game类用于启动游戏、控制游戏和结束游戏。 综上所述,在停车场游戏中,有Space(车位)、Road(通道)、Car(车)、Game(游戏)和Form1(用户接口)五个类。停车场游戏的逻辑模型如下图所示。6. 源代码 Form1.cs源码:using System;using System.Collections.Generic;using System.ComponentModel;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() InitializeComponent(); score.Text = Convert.ToString(Convert.ToInt32(score.Text); game = new Game(); for (int i = 0; i 0) game.df-; score.Text = game.df.ToString(); else pictureBox0.Enabled = false; if (game.MoveCar(0, game.cars0.spaceNum, game.freeSpaceNum) pBox.Location = new Point(game.cars0.center.X - pBox.Width / 2, game.cars0.center.Y - pBox.Height / 2); if (game.Success() MessageBox.Show(您的得分为: + game.df.ToString(), 恭喜!成功了, MessageBoxButtons.OK, MessageBoxIcon.Information ); else MessageBox.Show(不能移动); if (game.df 0) game.df-; score.Text = game.df.ToString(); else pictureBox1.Enabled = false; if (game.MoveCar(1, game.cars1.spaceNum, game.freeSpaceNum) pBox.Location = new Point(game.cars1.center.X - pBox.Width / 2, game.cars1.center.Y - pBox.Height / 2); if (game.Success() MessageBox.Show(您的得分为: + game.df.ToString(), 恭喜!成功了, MessageBoxButtons.OK, MessageBoxIcon.Information ); else MessageBox.Show(不能移动); if (game.df 0) game.df-; score.Text = game.df.ToString(); else pictureBox2.Enabled = false; if (game.MoveCar(2, game.cars2.spaceNum, game.freeSpaceNum) pBox.Location = new Point(game.cars2.center.X - pBox.Width / 2, game.cars2.center.Y - pBox.Height / 2); if (game.Success() MessageBox.Show(您的得分为: + game.df.ToString(), 恭喜!成功了, MessageBoxButtons.OK, MessageBoxIcon.Information ); else MessageBox.Show(不能移动); if (game.df 0) game.df-; score.Text = game.df.ToString(); else pictureBox3.Enabled = false; if (game.MoveCar(3, game.cars3.spaceNum, game.freeSpaceNum) pBox.Location = new Point(game.cars3.center.X - pBox.Width / 2, game.cars3.center.Y - pBox.Height / 2); if (game.Success() MessageBox.Show(您的得分为: + game.df.ToString(), 恭喜!成功了, MessageBoxButtons.OK, MessageBoxIcon.Information ); else MessageBox.Show(不能移动); if (game.df 0) game.df-; score.Text = game.df.ToString(); else pictureBox4.Enabled = false; if (game.MoveCar(4, game.cars4.spaceNum, game.freeSpaceNum) pBox.Location = new Point(game.cars4.center.X - pBox.Width / 2, game.cars4.center.Y - pBox.Height / 2); if (game.Success() MessageBox.Show(您的得分为: + game.df.ToString(), 恭喜!成功了, MessageBoxButtons.OK, MessageBoxIcon.Information ); else MessageBox.Show(不能移动); if (game.df = 0) MessageBox.Show(剩余步数为0,你没法再走了); pictureBox4.Enabled = false; private void buttonStart_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 + i.ToString(); PictureBox pBox = (PictureBox)this.Controls.Find(name,false)0; pBox.Location = new Point(game.carsi.center.X - pictureBox0.Width / 2, game.carsi.center.Y - pictureBox0.Height / 2); pBox.Visible = true; pBox.Enabled = true; private void buttonStart_Paint(object sender, PaintEventArgs e) game.PaintParkingLot(this.CreateGraphics(); private void score_Click(object sender, EventArgs e) private void label1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) MessageBox.Show(1.单击小车可以移动到其所在圆圈连线对应的圆圈内n2.将小车移动到对应颜色圆圈内即为获胜n3.得分高玩得好, 帮助, MessageBoxButtons.OK, MessageBoxIcon.Information); 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(); PictureBox pBox = (PictureBox)this.Controls.Find(name, false)0; pBox.Location = new Point(game.carsi.center.X - pictureBox0.Width / 2, game.carsi.center.Y - pictureBox0.Height / 2); pBox.Visible = true; pBox.Enabled = true; 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, 您的剩余步数); this.toolTip1.SetToolTip(this.score , 您的剩余步数); this.toolTip1.SetToolTip(this.buttonStart, 开始新的游戏); this.toolTip1.SetToolTip(this.buttonNext, 直接下一关); this.toolTip1.SetToolTip(this.help, 获取帮助); this.toolTip1.SetToolTip(this.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) 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 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.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; public Car cars; public int freeSpaceNum; public int df = 10; public Game() spaces = new Space6; roads = new Road9; cars = new Car5; spaces0 = new Space(new Point(200, 400), Color.Blue); spaces1 = new Space(new Point(200, 200), Color.Red); spaces2 = new Space(new Point(500, 100), Color.Yellow); spaces3 = new Space(new Point(800, 200), Color.Green); spaces4 = new Space(new Point(800, 400), Color.Pink); spaces5 = new Space(new Point(500, 500), Color.Black); roads0 = new Road(0, 1, spaces0.center, spaces1.center); roads1 = new Road(1, 2, spaces1.center, spaces2.center); roads2 = new Road(2, 3, spaces2.center, spaces3.center); roads3 = new Road(3, 4, spaces3.center, spaces4.center); roads4 = new Road(4, 5, spaces4.center, spaces5.center); roads5 = new Road(5, 0, spaces5.center, spaces0.center); roads6 = new Road(0, 3, spaces0.center, spaces3.center); roads7 = new Road(1, 4, spaces1.center, spaces4.center); roads8 = new Road(2, 5, spaces2.center, spaces5.center); cars0 = new Car(spaces1.center, 1); cars1 = new Car(spaces2.center, 2); cars2 = new Car(spaces3.center, 3); cars3 = new Car(spaces4.center, 4); cars4 = new Car(spaces0.center, 0); freeSpaceNum = 5; public void PaintParkingLot(Graphics g) foreach (Road r in roads) r.Paint(g); 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 spaces) s.Clear(g); public bool Success() for (int i = 0; i 5; i+) if (i != carsi.spaceNum) return false; return true; public bool MoveCar(int carNum, int start, int end) foreach (Road r in roads) if (r.spaceStartNum = start & r.spaceEndNum = end) carscarNum.Move(spacesend.center, end); freeSpaceNum = start; return true; if (r.spaceStartNum = end & r.spaceEndNum = start) carscarNum.Move(spacesend.center, end); freeSpaceNum = start; return true; return false; public void Next() spaces = new Space6; roads = new Road9; cars = new Car5; spaces0 = new Space(new Point(200, 350), Color.Blue); spaces1 = new Space(new Point(200, 100), Color.Red); spaces2 = new Space(new Point(500, 100), Color.Yellow); spaces3 = new Space(new Point(800, 100), Color.Green); spaces4 = new Space(new Point(800, 350), Color.Pink); spaces5 = new Space(new Point(500, 500), Color.Black); roads0 = new Road(0, 1, spaces0.center, spaces1.center); roads1 = new Road(1, 2, spaces1.center, spaces2.center); roads2 = new Road(2, 3, spaces2.center, spaces3.center); roads3 = new Road(3, 4, spaces3.center, spaces4.center); roads4 = new Road(4, 5, spaces4.center, spaces5.center); roads5 = new Road(5, 0, spaces5.center, spaces0.center); roads6 = new Road(0, 3, spaces0.center, spaces3.center); roads7 = new Road(1, 4, spaces1.center, spaces4.center); roads8 = new Road(2, 5, spaces2.center, spaces5.center); cars0 = new Car(spaces1.center, 1); cars1 = new Car(spaces2.center, 2); cars2 = new Car(spaces3.center, 3); cars3 = new Car(spaces4.center, 4); cars4 = new Car(spaces0.center, 0); freeSpaceNum = 5; Road.cs源码:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;namespace WindowsFormsApplication2 class Road public int spaceStartNum; public int spaceEndNum; Point start; Point end; static Color color = Color.DarkOrchid; public Road(int startNum, int endNum, Point p1, Point p2) spaceStartNum = startNum; spaceEndNum = endNum; start = p1; end = p2; public void Paint(Graphics g) g.DrawLine(new Pen(color, 15), start, end); public void Clear(Graphics g) g.DrawLine(new Pen(Color.PeachPuff, 15), start, end); Space.cs源码:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;namespace WindowsFormsApplication2 cl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 金属绿色高效回收项目施工方案
- 机床辅助装备生产线项目施工方案
- 电缆生产线项目施工方案
- 校园安全教育宣讲方案
- 给水工程系统集成方案
- 郑州国企考试题目及答案
- 燃气工程建设组织管理方案
- 煤炭场地租赁合同范本(含合同解除费用)正规范本
- 工业园区绿色供电需求侧响应管理方案
- 给水工程水质保护方案
- 2025年第一届安康杯安全生产知识竞赛试题题库及答案(完整版)
- 电力工程冬季施工安全技术措施
- 贵州省贵阳市2026届高三上学期摸底考试数学试卷含答案
- 公司年度员工安全教育培训计划
- 供电所安全教育培训课件
- 2025年杭州市上城区望江街道办事处 编外人员招聘8人考试参考试题及答案解析
- 百果园水果知识培训资料课件
- 商业地产策划流程
- 2025年灌注桩考试题及答案
- 公司安全生产责任书范本
- 养老护理员培训班课件
评论
0/150
提交评论