还剩9页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
实训报告实训名称停车场指导教师学号班级提交日期2014/5/
231.实训目的通过开发一款停车场游戏程序,熟练掌握C#编程语言、面向对象程序设计方法和可视化编程技术public intspaceStartNum;public intspaceEndNum;Point start;Point end;static Color color=Color.DarkOrchid;public Roadint startNum,int endNum,Point pl,Point p2spaceStartNum=startNum;spaceEndNum=endNum;start=pl;end=p2;}public voidPaintGraphics gg.DrawLine newPen color,15,start,end;}}6Space using System;using System.Drawing;using System.Collections.Generic;using System.Linq;using System.Text;namespace ParkingLotclassSpacepublic Point center;public constint radius=50;public Colorcolor;public SpacePointcenter,Colorcolorthis.center=center;this.color=color;}public voidPaintGraphics gRectangler=new Rectanglecenter.X-radius,center.Y-radius,2*radius,2*radius;g.DrawEl1ipsenew Pencolor,10,r;
7.测试报告:)测试用例:1•Space的生成与显示1)测试程序是否能在游戏开始时,生成6个车位2)测试程序是否能在游戏运行中,正常显示6个车位•Road的生成与显示1)测试程序是否能在游戏开始时,生成9个通道,且通道的首尾分别连接两个车位2)测试程序是否能在游戏运行中,正常显示9个通道•Car的生成、显示与移动1)测试程序是否能在游戏开始时,生成5辆车,且每个车都位于一个车位2)测试程序是否能在游戏运行中,将车沿通道移动到空闲的车位3)测试程序是否会在游戏运行中,出现车移动到车位以外的情况4)测试程序是否能在所有车都位于相同颜色的车位时,结束游戏)测试结果2游戏开始时可以生成6个车位9个通道和5辆车,通道首尾分别连接两个车位,每个车都位于一个车位,并且游戏运行中能正常显示6个车位9个通道,可以将车沿通道移动到空闲的车位,没有出现车移动到车位以外的情况在所有车都位于相同颜色的车位时,结束游戏
8.心得体会在本次的实训学习中,我不仅学习到了很多关于编程的知识,也从中学会了关于编程的一些方法、技巧在这个过程中,通过请教老师、同学,上网查询等方式,不断虚学习、反思、总结、提高,我的编程水平相对于开始阶段有了一个质的变化
2.实训题目使用C#编程语言,开发一款停车场游戏如下图所示
3.功能描述1)停车场有5种颜色的汽车和6个车位2)每一辆汽车对应颜色的车位3)车位之间有的有通道,有的没有4)最初5种颜色的汽车未停在对应颜色的车位5)玩家点击汽车,实现将该汽车沿通道移动到空闲的车位上;当该汽车与空间的车位之间没有通道时,则不移动汽车6)玩家可以点击按钮“自来一次”,重新开始游戏7)当所有的汽车都听到对应颜色的车位上时,游戏成功
4.需求分析:1)车(Car)在停车场游戏中,车是玩家操纵的对象车具有位置和颜色等属性在游戏中,玩家可以将汽车沿通道移动到空闲的车位上2)车位(Space)在停车场游戏中,车位是汽车停留的空间车位具有位置、大小和颜色等属性3)通道(Road)在停车场游戏中,通道是汽车移动的路径通道具有起始点等属性当某两个车位间有通道时,汽车可以直接再这两个车位间移动当某两个车位间没有通道时,汽车不可以直接在这两个车位间移动
5.设计说明:根据需求分析可知,车位具有位置、大小和颜色等属性,定义Space类用于描述车位的信息通道具有起点和终点两个属性,定义Road类用于描述通道的信息以及通道与车位之间的关系车具有位置和颜色等属性,定义Car类用于描述车的信息以及车停留在哪个车位,并实现车的移动功能为了使游戏的运行更易于控制,定义Game类用于启动游戏、控制游戏和结束游戏综上所述,在停车场游戏中,有Space(车位)、Road(通道)、Car(车)、Game(游戏)和Ma和Form(用户接口)六个类
6.源代码1Forml 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 ParkingLotpublic partialclass Forml:Form privateGame game;private Spacespace;private Road road;private Carcars;public FormlInitializeComponent;game二new Game;for inti=0;i5;i++string name=〃pictureBox〃+i.ToStringO;PictureBox pBox=PictureBoxthis.Controls.Findname,false
[0];pBox.Location=new Pointgame,cars[i].center.X-pictureBoxO.Width/2,game,cars[i].center.Y一pictureBoxO.Height/2;pBox.Visible=true;}}private voidpictureBoxO Clickobject sender,EventArgs eif game.MoveCar0,game,cars
[0].spaceNum,game.freeSpaceNumpictureBoxO.Location=new Pointgame,cars
[0].center.X一pictureBoxO.Width/2,game.cars
[0].center.Y-pictureBoxO.Height/2;score.Text=Convert.ToString Convert.Tolnt32score.Text+1;ifgame.SuccessMessageBox.Show〃恭喜!成功了〃;}elseMessageBox.Show〃不能移动〃;}private voidpictureBoxl Clickobject sender,EventArgs eif game.MoveCar1,game,cars
[1].spaceNum,game.freeSpaceNumpictureBoxl.Location二new Pointgame.cars[l].center.X-pictureBoxl.Width/2,game.cars[l].center.Y-pictureBoxl.Height/2;score.Text=Convert.ToStringConvert.Tolnt32score.Text+1;ifgame.Success{MessageBox.Show〃恭喜!成功了〃;}}else MessageBox.Show〃不能移动〃;}}private voidpictureBox2_Clickobject sender,EventArgs eif game.MoveCar2,game,cars
[2].spaceNum,game.freeSpaceNumpictureBox
2.Location=new Pointgame,cars
[2].center.X一pictureBox
2.Width/2,game,cars
[2].center.Y-pictureBox
2.Height/2;score.Text=Convert.ToStringConvert.Tolnt32score.Text+1;ifgame.Success MessageBox.Show〃恭喜!成功了〃;elseMessageBox.Show〃不能移动〃;}private voidpictureBox3_Clickobject sender,EventArgs eif game.MoveCar3,game,cars
[3].spaceNum,game.freeSpaceNumpictureBox
3.Location=new Pointgame,cars
[3].center.X一pictureBox
3.Width/2,game,cars
[3].center.Y-pictureBox
3.Height/2;score.Text二Convert.ToStringConvert.Tolnt32score.Text+1;ifgame.SuccessMessageBox.Show〃恭喜!成功了〃;}}else MessageBox.Show〃不能移动〃;}private voidpictureBox4_Clickobject sender,EventArgs eifgame.MoveCar4,game.cars
[4].spaceNum,game.freeSpaceNumpictureBox
4.Location=new Pointgame,cars
[4].center.X-pictureBox
4.Width/2,game,cars
[4].center.Y-pictureBox
4.Height/2;score.Text=Convert.ToStringConvert.Tolnt32score.Text+1;ifgame.SuccessMessageBox.Show〃恭喜!成功了〃;}elseMessageBox.Show〃不能移动〃;}}private voidForml Loadobject sender,EventArgs eprivate void buttonl_Clickobject sender,EventArgs egame=new Game;score.Text=Convert.ToStringConvert.Tolnt32score.Text-Convert.Tolnt32score.Text;for inti=0;i5;i++string name=pictureBox+i.ToString;PictureBox pBox=PictureBoxthis.Controls.Findname,false
[0];pBox.Location=new Pointgame,cars[i].center.X一pictureBoxO.Width/2,game.cars[i].center.Y一pictureBoxO.Height/2;pBox.Visible=true;}}private voidbuttonStart Paintobjectsender,PaintEventArgs egame.PaintParkingLotthis.CreateGraphics;private voidtextBoxl_TextChangedobject sender,EventArgs e}private voidbuttonl Clickl objectsender,EventArgs eMessageBox.Show〃对不起,没有下一关了〃;}privatevoidlabelI Clickobjectsender,EventArgs eprivatevoid score_Clickobjectsender,EventArgs e.2Program using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace ParkingLotstaticclass Program///summary///应用程序的主入口点////summary[STAThread]static voidMain Application.EnableVisualStyles;Applicat ion.SetCompatibleTextRenderingDefaultfalse;Application.Runnew Forml;}.3Car using System;using System.Drawing;using System.Collections.Generic;using System.Linq;using System.Text;namespace ParkingLotclass Carpublic Pointcenter;public int spaceNum;public CarPointcenter,int spaceNumthis.center=center;this.spaceNum=spaceNum;public voidMove Pointcenter,intspaceNumthis.center=center;this.spaceNum=spaceNum;}4Game using System;using System.Drawing;using System.Collections.Generic;using System.Linq;usingSystem.Text;namespace ParkingLotclass GamepublicSpace[]spaces;public Road[]roads;public Car[]cars;public intfreeSpaceNum;public Gamespaces=new Space
[6];roads=new Road
[9];cars二new Car
[5];spaces
[0]=new Spacenew Point200,400,Color.Blue;spaces
[1]=new SpacenewPoint200,200,Color.Red;spaces
[2]=new SpacenewPoint500,100,Color.Yellow;spaces
[3]二new SpacenewPoint800,200,Color.Green;spaces
[4]二new SpacenewPoint800,400,Color.Pink;spaces
[5]=new SpacenewPoint500,500,Color.Black;roads
[0]=new Road0,1,spaces
[0].center,spaces[l].centerroads
[1]=new Road1,2,spaces
[1].center,spaces
[2].centerroads
[2]二new Road2,3,spaces
[2].center,spaces
[3].centerroads
[3]二new Road3,4,spaces
[3].center,spaces
[4].centerroads
[4]=new Road4,5,spaces
[4].center,spaces
[5].centerroads
[5]=new Road5,0,spaces
[5].center,spaces
[0].centerroads
[6]=new Road0,3,spaces
[0].center,spaces
[3].centerroads
[7]=new Road1,4,spaces
[1].center,spaces
[4].centerroads
[8]二new Road2,5,spaces
[2].center,spaces
[5].centercars
[0]=new Carspaces
[1].center,1;cars[l]=new Carspaces
[2].center,2;cars
[2]=new Carspaces
[3].center,3;cars
[3]=new Carspaces
[4].center,4;cars
[4]=new Carspaces
[0].center,0;freeSpaceNum=5;}public voidPaintParkingLotGraphics gforeach Roadr in roadsr.Paint g;foreach Spaces inspacess.Paint g;public boolSuccessfor inti=0;i5;i++if i!=cars[i].spaceNum return false;}return true;}public boolMoveCarint carNum,intstart,int endforeachRoadrinroadsif r.spaceStartNum==startr.spaceEndNum==end cars[carNum].Move spaces[end].center,end;freeSpaceNum=start;return true;if r.spaceStartNum二二endr.spaceEndNum二二start{cars[carNum].Movespaces[end].center,end;freeSpaceNum=start;return true;}returnfalse;}}.5Road usingSystem;usingSystem.Drawing;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace ParkingLotclassRoad。
个人认证
优秀文档
获得点赞 0