停車場實訓(xùn)報告_第1頁
停車場實訓(xùn)報告_第2頁
停車場實訓(xùn)報告_第3頁
停車場實訓(xùn)報告_第4頁
停車場實訓(xùn)報告_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

實訓(xùn)報告實訓(xùn)名稱:停車場指導(dǎo)教師:姓名:學(xué)號:班級:提交日期:2014/5/23實訓(xùn)目的:通過開發(fā)一款停車場游戲程序,熟練掌握C#編程語言、面向?qū)ο蟪绦蛟O(shè)計方法和可視化編程技術(shù)。實訓(xùn)題目:使用C#編程語言,開發(fā)一款停車場游戲如下圖所示。3.功能描述:1)停車場有5種顏色的汽車和6個車位。2)每一輛汽車對應(yīng)顏色的車位。3)車位之間有的有通道,有的沒有。4)最初5種顏色的汽車未停在對應(yīng)顏色的車位。5)玩家點擊汽車,實現(xiàn)將該汽車沿通道移動到空閑的車位上;當(dāng)該汽車與空間的車位之間沒有通道時,則不移動汽車。6)玩家可以點擊按鈕“自來一次”,重新開始游戲。7)當(dāng)所有的汽車都聽到對應(yīng)顏色的車位上時,游戲成功。4.需求分析:1)車(Car):在停車場游戲中,車是玩家操縱的對象。車具有位置和顏色等屬性。在游戲中,玩家可以將汽車沿通道移動到空閑的車位上。2)車位(Space):在停車場游戲中,車位是汽車停留的空間。車位具有位置、大小和顏色等屬性。3)通道(Road):在停車場游戲中,通道是汽車移動的路徑。通道具有起始點等屬性。當(dāng)某兩個車位間有通道時,汽車可以直接再這兩個車位間移動。當(dāng)某兩個車位間沒有通道時,汽車不可以直接在這兩個車位間移動。5.設(shè)計說明:根據(jù)需求分析可知,車位具有位置、大小和顏色等屬性,定義Space類用于描述車位的信息。通道具有起點和終點兩個屬性,定義Road類用于描述通道的信息以及通道與車位之間的關(guān)系。車具有位置和顏色等屬性,定義Car類用于描述車的信息以及車停留在哪個車位,并實現(xiàn)車的移動功能。為了使游戲的運行更易于控制,定義Game類用于啟動游戲、控制游戲和結(jié)束游戲。綜上所述,在停車場游戲中,有Space(車位)、Road(通道)、Car(車)、Game(游戲)和MainForm(用戶接口)六個類。6.源代碼:Form1:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceParkingLot{publicpartialclassForm1:Form{privateGamegame;privateSpacespace;privateRoadroad;privateCarcars;publicForm1(){InitializeComponent();game=newGame();for(inti=0;i<5;i++){stringname="pictureBox"+i.ToString();PictureBoxpBox=(PictureBox)this.Controls.Find(name,false)[0];pBox.Location=newPoint(game.cars[i].center.X-pictureBox0.Width/2,game.cars[i].center.Y-pictureBox0.Height/2);pBox.Visible=true;}}privatevoidpictureBox0_Click(objectsender,EventArgse){if(game.MoveCar(0,game.cars[0].spaceNum,game.freeSpaceNum)){pictureBox0.Location=newPoint(game.cars[0].center.X-pictureBox0.Width/2,game.cars[0].center.Y-pictureBox0.Height/2);score.Text=Convert.ToString(Convert.ToInt32(score.Text)+1);if(game.Success()){MessageBox.Show("恭喜!成功了");}}else{MessageBox.Show("不能移動");}}privatevoidpictureBox1_Click(objectsender,EventArgse){if(game.MoveCar(1,game.cars[1].spaceNum,game.freeSpaceNum)){pictureBox1.Location=newPoint(game.cars[1].center.X-pictureBox1.Width/2,game.cars[1].center.Y-pictureBox1.Height/2);score.Text=Convert.ToString(Convert.ToInt32(score.Text)+1);if(game.Success()){MessageBox.Show("恭喜!成功了");}}else{MessageBox.Show("不能移動");}}privatevoidpictureBox2_Click(objectsender,EventArgse){if(game.MoveCar(2,game.cars[2].spaceNum,game.freeSpaceNum)){pictureBox2.Location=newPoint(game.cars[2].center.X-pictureBox2.Width/2,game.cars[2].center.Y-pictureBox2.Height/2);score.Text=Convert.ToString(Convert.ToInt32(score.Text)+1);if(game.Success()){MessageBox.Show("恭喜!成功了");}}else{MessageBox.Show("不能移動");}}privatevoidpictureBox3_Click(objectsender,EventArgse){if(game.MoveCar(3,game.cars[3].spaceNum,game.freeSpaceNum)){pictureBox3.Location=newPoint(game.cars[3].center.X-pictureBox3.Width/2,game.cars[3].center.Y-pictureBox3.Height/2);score.Text=Convert.ToString(Convert.ToInt32(score.Text)+1);if(game.Success()){MessageBox.Show("恭喜!成功了");}}else{MessageBox.Show("不能移動");}}privatevoidpictureBox4_Click(objectsender,EventArgse){if(game.MoveCar(4,game.cars[4].spaceNum,game.freeSpaceNum)){pictureBox4.Location=newPoint(game.cars[4].center.X-pictureBox4.Width/2,game.cars[4].center.Y-pictureBox4.Height/2);score.Text=Convert.ToString(Convert.ToInt32(score.Text)+1);if(game.Success()){MessageBox.Show("恭喜!成功了");}}else{MessageBox.Show("不能移動");}}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidbutton1_Click(objectsender,EventArgse){game=newGame();score.Text=Convert.ToString(Convert.ToInt32(score.Text)-Convert.ToInt32(score.Text));for(inti=0;i<5;i++){stringname="pictureBox"+i.ToString();PictureBoxpBox=(PictureBox)this.Controls.Find(name,false)[0];pBox.Location=newPoint(game.cars[i].center.X-pictureBox0.Width/2,game.cars[i].center.Y-pictureBox0.Height/2);pBox.Visible=true;}}privatevoidbuttonStart_Paint(objectsender,PaintEventArgse){game.PaintParkingLot(this.CreateGraphics());}privatevoidtextBox1_TextChanged(objectsender,EventArgse){}privatevoidbutton1_Click_1(objectsender,EventArgse){MessageBox.Show("對不起,沒有下一關(guān)了");}privatevoidlabel1_Click(objectsender,EventArgse){}privatevoidscore_Click(objectsender,EventArgse){}}}Program:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Windows.Forms;namespaceParkingLot{staticclassProgram{///<summary>///應(yīng)用程序的主入口點。///</summary>[STAThread]staticvoidMain(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(newForm1());}}}Car:usingSystem;usingSystem.Drawing;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceParkingLot{classCar{publicPointcenter;publicintspaceNum;publicCar(Pointcenter,intspaceNum){this.center=center;this.spaceNum=spaceNum;}publicvoidMove(Pointcenter,intspaceNum){this.center=center;this.spaceNum=spaceNum;}}Game:usingSystem;usingSystem.Drawing;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceParkingLot{classGame{publicSpace[]spaces;publicRoad[]roads;publicCar[]cars;publicintfreeSpaceNum;publicGame(){spaces=newSpace[6];roads=newRoad[9];cars=newCar[5];spaces[0]=newSpace(newPoint(200,400),Color.Blue);spaces[1]=newSpace(newPoint(200,200),Color.Red);spaces[2]=newSpace(newPoint(500,100),Color.Yellow);spaces[3]=newSpace(newPoint(800,200),Color.Green);spaces[4]=newSpace(newPoint(800,400),Color.Pink);spaces[5]=newSpace(newPoint(500,500),Color.Black);roads[0]=newRoad(0,1,spaces[0].center,spaces[1].center);roads[1]=newRoad(1,2,spaces[1].center,spaces[2].center);roads[2]=newRoad(2,3,spaces[2].center,spaces[3].center);roads[3]=newRoad(3,4,spaces[3].center,spaces[4].center);roads[4]=newRoad(4,5,spaces[4].center,spaces[5].center);roads[5]=newRoad(5,0,spaces[5].center,spaces[0].center);roads[6]=newRoad(0,3,spaces[0].center,spaces[3].center);roads[7]=newRoad(1,4,spaces[1].center,spaces[4].center);roads[8]=newRoad(2,5,spaces[2].center,spaces[5].center);cars[0]=newCar(spaces[1].center,1);cars[1]=newCar(spaces[2].center,2);cars[2]=newCar(spaces[3].center,3);cars[3]=newCar(spaces[4].center,4);cars[4]=newCar(spaces[0].center,0);freeSpaceNum=5;}publicvoidPaintParkingLot(Graphicsg){foreach(Roadrinroads){r.Paint(g);}foreach(Spacesinspaces){s.Paint(g);}}publicboolSuccess(){for(inti=0;i<5;i++){if(i!=cars[i].spaceNum)returnfalse;}returntrue;}publicboolMoveCar(intcarNum,intstart,intend){foreach(Roadrinroads){if(r.spaceStartNum==start&&r.spaceEndNum==end){cars[carNum].Move(spaces[end].center,end);freeSpaceNum=start;returntrue;}if(r.spaceStartNum==end&&r.spaceEndNum==start){cars[carNum].Move(spaces[end].center,end);freeSpaceNum=start;returntrue;}}returnfalse;}}}Road:usingSystem;usingSystem.Drawing;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceParkingLot{classRoad{publicintspaceStartNum;publicintspaceEndNum;Pointstart;Pointend;staticColorcolor=Color.DarkOrchid;publicRoad(intstartNum,intendNum,Pointp1,Pointp2){spaceStartNum=startNum;spaceEndNum=endNum;start=p1;end=p2;}publicvoidPaint(Graphicsg){g.DrawLine(newPen(color,15)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論