計算機(jī)實(shí)習(xí)報告.docx_第1頁
計算機(jī)實(shí)習(xí)報告.docx_第2頁
計算機(jī)實(shí)習(xí)報告.docx_第3頁
計算機(jī)實(shí)習(xí)報告.docx_第4頁
計算機(jī)實(shí)習(xí)報告.docx_第5頁
已閱讀5頁,還剩38頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

計算機(jī)實(shí)習(xí)報告學(xué)院:班級:學(xué)號:姓名: 1、題目要求:作一個兩輛賽車比賽的游戲,要求可以用A,S,D,W和小鍵盤的上下左右鍵控制小汽車的運(yùn)行方向進(jìn)行比賽。設(shè)計方案 :所用軟件為Adobe Flash CS5設(shè)置控制鍵,通過按鍵對小車進(jìn)行控制,在控制的同時判斷小車的位置使其行駛在跑道上,當(dāng)有一輛賽車跑完三圈時,比賽結(jié)束,并輸出比賽結(jié)果。開始流程圖:方向鍵控制對兩小車是否碰到跑道進(jìn)行判斷小車停止Y N判斷比賽是否完成NY顯示比賽的輸贏結(jié)束設(shè)計過程:1. 首先要讓賽車能夠動起來。讓賽車運(yùn)動不是最難的一部分首先在defs的圖層里打開actions窗口,設(shè)定好賽車的加速度,減速度,最大速度,以及圈數(shù)等基本常量值。 Flash中使用的的是經(jīng)典的直角坐標(biāo)系,所以我們在計算賽車實(shí)際的速度時要把速度分解到X軸和Y軸上,得到X分量和Y分量(如下圖)。計算上述分量就要知道角度,F(xiàn)lash中對角度和弧度要進(jìn)行轉(zhuǎn)化:angle_radians = angle_degrees *(PI/180)。再加上函數(shù),就可以讓我們的車動起來。這里我用了兩個類似的函數(shù)來分別控制兩輛賽車,他們只有控制方向的按鍵不同的。2還需要處理碰撞的問題。碰撞時整個賽車游戲中十分重要的一部分,因?yàn)槲覀儽仨毎奄愜囅拗圃谂艿纼?nèi),并且讓玩家可以在最快的時間內(nèi)完成比賽。在車的四邊分別設(shè)置一個點(diǎn),用來檢測它是否碰到了不可進(jìn)入的區(qū)域。如果碰到了賽道,那么賽車的速度將會降低,并且賽車的方向會得到糾正。3處理圈數(shù)和計時的問題。設(shè)置了兩個函數(shù)來分別計算總的比賽時間setTimes和單圈最好成績setBestLap。當(dāng)賽車連續(xù)經(jīng)過兩次檢查點(diǎn)checkpoint時則完成一圈,當(dāng)完成三圈時游戲結(jié)束,顯示游戲結(jié)果。源代碼:Defs:car1.code = player;car2.code = playertotalLaps = 3;acceleration = 0.4;speedDecay = 0.96;rotationStep = 10;maxSpeed = 10;backSpeed = 1;currentCheckpoint1 = 1;currentCheckpoint2 = 1;currentLap1 = 0;currentLap2 = 0;checkpoints = 2;currentLapTXT = 1/3;Actions:function step(who) if (_rootcar+who.code = player) if (thisspeed+who0.3) thisspeed+who *= _root.speedDecay; else thisspeed+who = 0;/賽車控制按鍵的設(shè)置/加速if (Key.isDown(Key.UP) & thisspeed+who0.3) _rootcar+who._rotation -= _root.rotationStep*(thisspeed+who/_root.maxSpeed);/右轉(zhuǎn) if (Key.isDown(Key.RIGHT) & Math.abs(thisspeed+who)0.3) _rootcar+who._rotation += _root.rotationStep*(thisspeed+who/_root.maxSpeed);thisrotation+who = _rootcar+who._rotation;/計算賽車X方向和Y方向的速度分量thisspeedx+who = Math.sin(thisrotation+who*(Math.PI/180)*thisspeed+who;thisspeedy+who = Math.cos(thisrotation+who*(Math.PI/180)*thisspeed+who*-1;/讓這兩個分量具體的作用到賽車的位置上_rootcar+who._x += thisspeedx+who;_rootcar+who._y += thisspeedy+who;/碰撞/定義四個碰撞點(diǎn)的位置_rootcar+who.pointLeft = x:-20, y:0;_rootcar+who.localToGlobal(_rootcar+who.pointLeft);_rootcar+who.pointRight = x:20, y:0;_rootcar+who.localToGlobal(_rootcar+who.pointRight);_rootcar+who.pointFront = x:0, y:-25;_rootcar+who.localToGlobal(_rootcar+who.pointFront);_rootcar+who.pointBack = x:0, y:25;_rootcar+who.localToGlobal(_rootcar+who.pointBack);/簡寫上述變量thislpx+who = _rootcar+who.pointLeft.x;thislpy+who = _rootcar+who.pointLeft.y;thisrpx+who = _rootcar+who.pointRight.x;thisrpy+who = _rootcar+who.pointRight.y;thisfpx+who = _rootcar+who.pointFront.x;thisfpy+who = _rootcar+who.pointFront.y;thisbpx+who = _rootcar+who.pointBack.x;thisbpy+who = _rootcar+who.pointBack.y;/檢查是否發(fā)生碰撞if (_root.terrain.hitTest(thislpx+who, thislpy+who, true) _rootcar+who._rotation += 5;thisspeed+who *= 0.85;if (_root.terrain.hitTest(thisrpx+who, thisrpy+who, true) _rootcar+who._rotation -= 5;thisspeed+who *= 0.85;if (_root.terrain.hitTest(thisfpx+who, thisfpy+who, true) thisspeed+who = -1;if (_root.terrain.hitTest(thisbpx+who, thisbpy+who, true) thisspeed+who = 1;/陰影的位置 _rootshadow+who._x = _rootcar+who._x-4;_rootshadow+who._y = _rootcar+who._y+2;_rootshadow+who._rotation = _rootcar+who._rotation;/檢查點(diǎn)if (_rootcar+who.hitTest(_rootcheckpoint+_rootcurrentCheckpoint+who) /if the current checkpoint is the start line - increase the lap numberif (_rootcurrentCheckpoint+who = 1) if (_rootcurrentLap+who != 0) _root.setBestLap();if (_rootcurrentLap+who = _root.totalLaps) _root.gotoAndStop(finish); else _rootcurrentLap+who+;_root.currentLapTXT = _rootcurrentLap+who+/3;_rootcurrentCheckpoint+who+;if (_rootcurrentCheckpoint+who_root.checkpoints) _rootcurrentCheckpoint+who = 1;if (_rootcar+who.code = computer) function step2(who) if (_rootcar+who.code = player) if (thisspeed+who0.3) thisspeed+who *= _root.speedDecay; else thisspeed+who = 0;/賽車控制按鍵的設(shè)置/加速if (Key.isDown(87) & thisspeed+who0.3) _rootcar+who._rotation -= _root.rotationStep*(thisspeed+who/_root.maxSpeed);/右轉(zhuǎn) if (Key.isDown(68) & Math.abs(thisspeed+who)0.3) _rootcar+who._rotation += _root.rotationStep*(thisspeed+who/_root.maxSpeed);thisrotation+who = _rootcar+who._rotation;/計算速度的X分量和Y分量thisspeedx+who = Math.sin(thisrotation+who*(Math.PI/180)*thisspeed+who;thisspeedy+who = Math.cos(thisrotation+who*(Math.PI/180)*thisspeed+who*-1;/讓這兩個分量具體的作用到賽車的位置上_rootcar+who._x += thisspeedx+who;_rootcar+who._y += thisspeedy+who;/碰撞/定義四個碰撞點(diǎn)的位置_rootcar+who.pointLeft = x:-20, y:0;_rootcar+who.localToGlobal(_rootcar+who.pointLeft);_rootcar+who.pointRight = x:20, y:0;_rootcar+who.localToGlobal(_rootcar+who.pointRight);_rootcar+who.pointFront = x:0, y:-25;_rootcar+who.localToGlobal(_rootcar+who.pointFront);_rootcar+who.pointBack = x:0, y:25;_rootcar+who.localToGlobal(_rootcar+who.pointBack);/簡寫上述變量thislpx+who = _rootcar+who.pointLeft.x;thislpy+who = _rootcar+who.pointLeft.y;thisrpx+who = _rootcar+who.pointRight.x;thisrpy+who = _rootcar+who.pointRight.y;thisfpx+who = _rootcar+who.pointFront.x;thisfpy+who = _rootcar+who.pointFront.y;thisbpx+who = _rootcar+who.pointBack.x;thisbpy+who = _rootcar+who.pointBack.y;/檢查是否發(fā)生碰撞if (_root.terrain.hitTest(thislpx+who, thislpy+who, true) _rootcar+who._rotation += 5;thisspeed+who *= 0.85;if (_root.terrain.hitTest(thisrpx+who, thisrpy+who, true) _rootcar+who._rotation -= 5;thisspeed+who *= 0.85;if (_root.terrain.hitTest(thisfpx+who, thisfpy+who, true) thisspeed+who = -1;if (_root.terrain.hitTest(thisbpx+who, thisbpy+who, true) thisspeed+who = 1;/陰影的位置 _rootshadow+who._x = _rootcar+who._x-4;_rootshadow+who._y = _rootcar+who._y+2;_rootshadow+who._rotation = _rootcar+who._rotation;/檢查點(diǎn)if (_rootcar+who.hitTest(_rootcheckpoint+_rootcurrentCheckpoint+who) /if the current checkpoint is the start line - increase the lap numberif (_rootcurrentCheckpoint+who = 1) if (_rootcurrentLap+who != 0) _root.setBestLap();if (_rootcurrentLap+who = _root.totalLaps) _root.gotoAndStop(finish); else _rootcurrentLap+who+;_root.currentLapTXT = _rootcurrentLap+who+/3;_rootcurrentCheckpoint+who+;if (_rootcurrentCheckpoint+who_root.checkpoints) _rootcurrentCheckpoint+who = 1;if (_rootcar+who.code = computer) function setTimes() timeElapsed = getTimer()-_root.initialTime;milliseconds = timeElapsed;seconds = Math.floor(milliseconds/1000);minutes = Math.floor(seconds/60);minutesTXT = minutes;secondsTXT = seconds-minutes*60;tensTXT = Math.round(milliseconds-seconds*1000)/10);if (minutesTXT10) minutesTXT = 0+minutesTXT;if (secondsTXT10) secondsTXT = 0+secondsTXT;if (tensTXTmilliseconds | oldMilliseconds = null) oldMilliseconds = milliseconds;seconds = Math.floor(milliseconds/1000);minutes = Math.floor(seconds/60);minutesTXT = minutes;secondsTXT = seconds-minutes*60;tensTXT = Math.round(milliseconds-seconds*1000)/10);if (minutesTXT10) minutesTXT = 0+minutesTXT;if (secondsTXT10) secondsTXT = 0+secondsTXT;if (tensTXTLoadIcon(IDR_MAINFRAME);void CCalculatorDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CCalculatorDlg)DDX_Text(pDX, IDC_EDIT1, m_EDIT);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CCalculatorDlg, CDialog)/AFX_MSG_MAP(CCalculatorDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON0, OnButton0)ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON3, OnButton3)ON_BN_CLICKED(IDC_BUTTON4, OnButton4)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)ON_BN_CLICKED(IDC_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTONA, OnButtona)ON_BN_CLICKED(IDC_BUTTONB, OnButtonb)ON_BN_CLICKED(IDC_BUTTONC, OnButtonc)ON_BN_CLICKED(IDC_BUTTOND, OnButtond)ON_BN_CLICKED(IDC_BUTTONE, OnButtone)ON_BN_CLICKED(IDC_BUTTONF, OnButtonf)ON_BN_CLICKED(IDC_BTN_BACK, OnBtnBack)ON_BN_CLICKED(IDC_BTN_DOT, OnBtnDot)ON_BN_CLICKED(IDC_BTN_AC, OnBtnAc)ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)ON_BN_CLICKED(IDC_BTN_DECREASE, OnBtnDecrease)ON_BN_CLICKED(IDC_BTN_MULTI, OnBtnMulti)ON_BN_CLICKED(IDC_BTN_DIV, OnBtnDiv)ON_BN_CLICKED(IDC_BTN_EQUAL, OnBtnEqual)ON_BN_CLICKED(IDC_BTN_SIGN, OnBtnSign)ON_BN_CLICKED(IDC_BTN_HEX, OnBtnHex)ON_BN_CLICKED(IDC_BTN_DEC, OnBtnDec)ON_BN_CLICKED(IDC_BTN_OCT, OnBtnOct)ON_BN_CLICKED(IDC_BTN_BIN, OnBtnBin)/AFX_MSG_MAPON_EN_CHANGE(IDC_EDIT1, &CCalculatorDlg:OnEnChangeEdit1)END_MESSAGE_MAP()/ CCalculatorDlg message handlers/初始化對話框BOOL CCalculatorDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small icon/ TODO: Add extra initialization here form=D;point=false;GetDlgItem(IDC_BUTTONA)-EnableWindow(0);GetDlgItem(IDC_BUTTONB)-EnableWindow(0);GetDlgItem(IDC_BUTTONC)-EnableWindow(0);GetDlgItem(IDC_BUTTOND)-EnableWindow(0);GetDlgItem(IDC_BUTTONE)-EnableWindow(0);GetDlgItem(IDC_BUTTONF)-EnableWindow(0);return TRUE; / return TRUE unless you set the focus to a controlvoid CCalculatorDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw the icon. For MFC applications using the document/view model,/ this is automatically done for you by the framework.void CCalculatorDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CCalculatorDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;/控件觸發(fā)void CCalculatorDlg:OnButton0() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+0;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton1() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+1;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton2() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+2;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton3() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+3;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton4() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+4;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton5() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+5;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton6() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+6;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton7() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+7;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton8() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+8;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton9() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+9;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtona() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+A;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonb() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+B;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonc() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+C;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtond() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+D;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtone() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+E;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonf() / TODO: Add your control notification handler code herem_EDIT=m_EDIT+F;SetDlgItemText(IDC_EDIT1,m_EDIT);/退格void CCalculatorDlg:OnBtnBack() / TODO: Add your control notification handler code here

溫馨提示

  • 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

提交評論