计算机实习报告0001_第1页
计算机实习报告0001_第2页
计算机实习报告0001_第3页
计算机实习报告0001_第4页
计算机实习报告0001_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、计算机实习报告学院:班级:学号:姓名:1、题目要求:作一个两辆赛车比赛的游戏,要求可以用A, S, D, W和小键盘的上下左右键控制小汽车的运行方向进行比赛。设计方案:所用软件为 Adobe Flash CS5设置控制键,通过按键对小车进行控制,在控制的同时判断小车的位置使其行驶在跑道上, 当有一辆赛车跑完三圈时,比赛结束,并输出比赛结果。流程图:设计过程:1.首先要让赛车能够动起来。让赛车运动不是最难的一部分首先在defs的图层里打开actions窗口,设定好赛车的加速度,减速度,最大速度,以及圈数等基本常量值。Flash中使用的的是经典的直角坐标系,所以我们在计算赛车实际的速度时要把速度分

2、解到X轴和Y轴上,得到X分量和Y分量(如下图)。计算上述分量就要知道角度, Flash中对角度和弧度要进行转化:angle_radians = angle_degrees * ( PI/180)。再加上函数,就可以让我们的车动起来。这里我用了两个类似的函数来分别控制两辆赛车,他们 只有控制方向的按键不同的。2 还需要处理碰撞的问题。碰撞时整个赛车游戏中十分重要的一部分,因为我们必须把赛车限制在跑道内,并且让玩家可以在最快的时间内完成比赛。在车的四边分别设置一个点, 用来检测它是否碰到了不可进入的区域。如果碰到了赛道,那么赛车的速度将会降低,并且赛车的方向会得到纠正。IhlFD! 、-+aX A

3、xisLeft Side Pointk tFrcint Side PointReaEide Point *Side Paintv hen car.rot-ation = Q the LSP will bs(匚- 20, 匚丑?.)1 Mjll7 Axi s*3 处理圈数和计时的问题。设置了两个函数来分别计算总的比赛时间setTimes和单圈最好成绩setBestLap。当赛车连续经过两次检查点checkpoint时则完成一圈,当完成三圈时游戏结束,显示游戏结果。源代码:Defs:car1.code = player;car2.code = player totalLaps = 3; accel

4、eration = 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 *=

5、_root.speedDecay; else thisspeed+who = 0;/ 赛车控制按键的设置/ 加速if (Key.isDown(Key.UP) & thisspeed+who0.3) _rootcar+who._rotation_root.rotationStep*(thisspeed+who/_root.maxSpeed);/ 右转if (Key.isDown(Key.RIGHT) & Math.abs(thisspeed+who)0.3) _rootcar+who._rotation += _root.rotationStep*(thisspeed+who/_root.max

6、Speed);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

7、;/ 碰撞/ 定义四个碰撞点的位置_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.poi

8、ntBack = 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+

9、who.pointFront.y;thisbpx+who = _rootcar+who.pointBack.x;thisbpy+who = _rootcar+who.pointBack.y;/ 检查是否发生碰撞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;

10、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+wh

11、o._rotation;/ 检查点if (_rootcar+who.hitTest(_rootcheckpoint+_rootcurrentCheckpoint+who) /if the current checkpoint is the start line - increase the lap number if (_rootcurrentCheckpoint+who = 1) if (_rootcurrentLap+who != 0) _root.setBestLap();if (_rootcurrentLap+who = _root.totalLaps) _root.gotoAndSt

12、op(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) t

13、hisspeed+who *= _root.speedDecay; else thisspeed+who = 0;/ 赛车控制按键的设置/ 加速if (Key.isDown(87) & thisspeed+who0.3) _rootcar+who._rotation -= _root.rotationStep*(thisspeed+who/_root.maxSpeed);/ 右转if (Key.isDown(68) & Math.abs(thisspeed+who)0.3) _rootcar+who._rotation += _root.rotationStep*(thisspeed+who/

14、_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+w

15、ho;/ 碰撞/ 定义四个碰撞点的位置_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

16、.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 = _root

17、car+who.pointFront.y; thisbpx+who = _rootcar+who.pointBack.x; thisbpy+who = _rootcar+who.pointBack.y;/ 检查是否发生碰撞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

18、 -= 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 = _ro

19、otcar+who._rotation;/ 检查点if (_rootcar+who.hitTest(_rootcheckpoint+_rootcurrentCheckpoint+who) /if the current checkpoint is the start line - increase the lap number if (_rootcurrentCheckpoint+who = 1) if (_rootcurrentLap+who != 0) _root.setBestLap(); if (_rootcurrentLap+who = _root.totalLaps) _root.

20、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;

21、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 (te

22、nsTXTmilliseconds | 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;

23、if (secondsTXT10) secondsTXT = 0+secondsTXT;if (tensTXT1N*输入操作符Y输入第二个操作数1运算并输出计一算结果结束设计过程:1 建立一个MFC工程文件,名为 calculator.在对话框红添加适当的编辑框、按钮、静态文件、复选框和单选框.2 设计按钮,并修改其相应的ID与Caption选择和设置个控件的单击鼠标事件.3打开calculatorDIg.cpp文件,在构造函数中,进行成员初始化和完善各控件的响应函数 代码.源代码:#i nclude stdafx.h#include Calculator#i nclude Calculato

24、rDlg.h#in clude math.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILE static char THIS_FILE = _FILE_;#endif#define PI 3.1415926535897932384626433832795/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog public:CAboutDlg();/ Dialog Data /AFX_DATA(CAboutDlg) enum IDD = IDD_ABOUTBO

25、X ;/AFX_DATA/ ClassWizard generated virtual function overrides /AFX_VIRTUAL(CAboutDlg) protected:/ DDX/DDV supportvirtual void DoDataExchange(CDataExchange* pDX); /AFX_VIRTUAL/ Implementation protected: /AFX_MSG(CAboutDlg) /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)

26、/AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog) /AFX_MSG_MAP(CAboutDlg)/ No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP()/ CCalculatorDlg dialogCCalculato

27、rDlg:CCalculatorDlg(CWnd* pParent /*=NULL*/): CDialog(CCalculatorDlg:IDD, pParent)/AFX_DATA_INIT(CCalculatorDlg)m_EDIT = _T();temp=_T();op=#;a=b=r=0;first=second=result=0;/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp() -LoadIcon(IDR_MAINFRA

28、ME);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

29、(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(

30、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_CLIC

31、KED(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, OnBtnEqu

32、al) 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 messag

33、e 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_ABOUTBO

34、X, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialog SetIcon(m_hIcon, TRUE); / Set big icon SetIcon(m_hIcon, FALSE);/ Set small icon/ TODO: Add extra initialization hereform=D; point=false;GetDlgItem(IDC_BUTTONA)-En

35、ableWindow(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:On

36、SysCommand(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 i

37、s 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

38、(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icon dc.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 CCa

39、lculatorDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;/ 控件触发void CCalculatorDlg:OnButton0()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+0;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton1()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+1;S

40、etDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton2()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+2;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton3()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+3;SetDlgItemText(IDC_EDIT1,m_ED

41、IT);void CCalculatorDlg:OnButton4()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+4;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton5()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+5;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnBu

42、tton6()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+6;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton7()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+7;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton8()/ TODO: Add your cont

43、rol notification handler code here m_EDIT=m_EDIT+8;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButton9()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+9;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtona()/ TODO: Add your control notification handler cod

44、e here m_EDIT=m_EDIT+A;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonb()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+B;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtonc()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+C;SetDl

45、gItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtond()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+D;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnButtone()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+E;SetDlgItemText(IDC_EDIT1,m_EDIT);

46、void CCalculatorDlg:OnButtonf()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT+F;SetDlgItemText(IDC_EDIT1,m_EDIT);/ 退格void CCalculatorDlg:OnBtnBack()/ TODO: Add your control notification handler code here m_EDIT=m_EDIT.Left(m_EDIT.GetLength(-)1);SetDlgItemText(IDC_EDIT1,m_EDIT)

47、;void CCalculatorDlg:OnBtnDot()/ TODO: Add your control notification handler code here if(point=false)m_EDIT=m_EDIT+.;SetDlgItemText(IDC_EDIT1,m_EDIT); point=true;void CCalculatorDlg:OnBtnAc()/ TODO: Add your control notification handler code here m_EDIT=_T();point=false;SetDlgItemText(IDC_EDIT1,m_EDIT);void CCalculatorDlg:OnBtnAdd()/ TODO: Add your control notification handler code here temp=m_EDIT;op=+;m_EDIT=_T();point=false;void CCalculatorDlg:OnBtnDecrease()/ TODO: Add your control notification handler code here temp=m_EDIT;op=-;m_EDIT=_T(); point=false;vo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论