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

下载本文档

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

文档简介

计算机实习报告计算机实习报告 学院 学院 班级 班级 学号 学号 姓名 姓名 1 题目要求 作一个两辆赛车比赛的游戏 要求可以用 A S D W 和小键盘的上下左右 键控制小汽车的运行方向进行比赛 设计方案 所用软件为 Adobe Flash CS5 设置控制键 通过按键对小车进行控制 在控制的同时判断小车的位置使其行驶在跑道上 当有一辆赛车跑完三圈时 比赛结束 并输出比赛结果 流程图流程图 设计过程 设计过程 1 首先要让赛车能够动起来 让赛车运动不是最难的一部分首先在 defs 的图层里打开 actions 窗口 设定好赛车 的加速度 减速度 最大速度 以及圈数等基本常量值 Flash 中使用的的是经典的直角坐标系 所以我们在计算赛车实际的速度时要把速 开始 方向键控制 对两小车是否碰到 跑道进行判断 判断比赛是否完 成 N Y 显示比赛的输赢 结束 小车停止 Y N 度分解到 X 轴和 Y 轴上 得到 X 分量和 Y 分量 如下图 计算上述分量就要知道角度 Flash 中对角度和弧度要进行转化 angle radians angle degrees PI 180 再加上函 数 就可以让我们的车动起来 这里我用了两个类似的函数来分别控制两辆赛车 他 们只有控制方向的按键不同的 2 还需要处理碰撞的问题 碰撞时整个赛车游戏中十分重要的一部分 因为我们必须把赛车限制在跑道内 并且 让玩家可以在最快的时间内完成比赛 在车的四边分别设置一个点 用来检测它是否碰到了不可进入的区域 如果碰到了赛 道 那么赛车的速度将会降低 并且赛车的方向会得到纠正 3 处理圈数和计时的问题 设置了两个函数来分别计算总的比赛时间 setTimes 和单圈最好成绩 setBestLap 当赛 车连续经过两次检查点 checkpoint 时则完成一圈 当完成三圈时游戏结束 显示游戏结果 源代码 源代码 Defs car1 code player car2 code player totalLaps 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 root car who code player if this speed who 0 3 this speed who root speedDecay else this speed who 0 赛车控制按键的设置 加速 if Key isDown Key UP 右转 if Key isDown Key RIGHT this rotation who root car who rotation 计算赛车 X 方向和 Y 方向的速度分量 this speedx who Math sin this rotation who Math PI 180 this speed who this speedy who Math cos this rotation who Math PI 180 this speed who 1 让这两个分量具体的作用到赛车的位置上 root car who x this speedx who root car who y this speedy who 碰撞 定义四个碰撞点的位置 root car who pointLeft x 20 y 0 root car who localToGlobal root car who pointLeft root car who pointRight x 20 y 0 root car who localToGlobal root car who pointRight root car who pointFront x 0 y 25 root car who localToGlobal root car who pointFront root car who pointBack x 0 y 25 root car who localToGlobal root car who pointBack 简写上述变量 this lpx who root car who pointLeft x this lpy who root car who pointLeft y this rpx who root car who pointRight x this rpy who root car who pointRight y this fpx who root car who pointFront x this fpy who root car who pointFront y this bpx who root car who pointBack x this bpy who root car who pointBack y 检查是否发生碰撞 if root terrain hitTest this lpx who this lpy who true root car who rotation 5 this speed who 0 85 if root terrain hitTest this rpx who this rpy who true root car who rotation 5 this speed who 0 85 if root terrain hitTest this fpx who this fpy who true this speed who 1 if root terrain hitTest this bpx who this bpy who true this speed who 1 阴影的位置 root shadow who x root car who x 4 root shadow who y root car who y 2 root shadow who rotation root car who rotation 检查点 if root car who hitTest root checkpoint root currentCheckpoint who if the current checkpoint is the start line increase the lap number if root currentCheckpoint who 1 if root currentLap who 0 root setBestLap if root currentLap who root totalLaps root gotoAndStop finish else root currentLap who root currentLapTXT root currentLap who 3 root currentCheckpoint who if root currentCheckpoint who root checkpoints root currentCheckpoint who 1 if root car who code computer function step2 who if root car who code player if this speed who 0 3 this speed who root speedDecay else this speed who 0 赛车控制按键的设置 加速 if Key isDown 87 右转 if Key isDown 68 this rotation who root car who rotation 计算速度的 X 分量和 Y 分量 this speedx who Math sin this rotation who Math PI 180 this speed who this speedy who Math cos this rotation who Math PI 180 this speed who 1 让这两个分量具体的作用到赛车的位置上 root car who x this speedx who root car who y this speedy who 碰撞 定义四个碰撞点的位置 root car who pointLeft x 20 y 0 root car who localToGlobal root car who pointLeft root car who pointRight x 20 y 0 root car who localToGlobal root car who pointRight root car who pointFront x 0 y 25 root car who localToGlobal root car who pointFront root car who pointBack x 0 y 25 root car who localToGlobal root car who pointBack 简写上述变量 this lpx who root car who pointLeft x this lpy who root car who pointLeft y this rpx who root car who pointRight x this rpy who root car who pointRight y this fpx who root car who pointFront x this fpy who root car who pointFront y this bpx who root car who pointBack x this bpy who root car who pointBack y 检查是否发生碰撞 if root terrain hitTest this lpx who this lpy who true root car who rotation 5 this speed who 0 85 if root terrain hitTest this rpx who this rpy who true root car who rotation 5 this speed who 0 85 if root terrain hitTest this fpx who this fpy who true this speed who 1 if root terrain hitTest this bpx who this bpy who true this speed who 1 阴影的位置 root shadow who x root car who x 4 root shadow who y root car who y 2 root shadow who rotation root car who rotation 检查点 if root car who hitTest root checkpoint root currentCheckpoint who if the current checkpoint is the start line increase the lap number if root currentCheckpoint who 1 if root currentLap who 0 root setBestLap if root currentLap who root totalLaps root gotoAndStop finish else root currentLap who root currentLapTXT root currentLap who 3 root currentCheckpoint who if root currentCheckpoint who root checkpoints root currentCheckpoint who 1 if root car 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 minutesTXT 10 minutesTXT 0 minutesTXT if secondsTXT 10 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 minutesTXT 10 minutesTXT 0 minutesTXT if secondsTXT 10 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 MAP BEGIN 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 MAP ON EN CHANGE IDC EDIT1 Add About menu item to system menu IDM ABOUTBOX must be in the system command range ASSERT 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 application s main window is not a dialog SetIcon m hIcon TRUE Set big icon SetIcon 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 control void CCalculatorDlg OnSysCommand UINT nID LPARAM lParam if nID dlgAbout DoModal else CDialog 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 painting SendMessage WM ICONERASEBKGND WPARAM dc GetSafeHdc 0 Center icon in client rectangle int cxIcon GetSystemMetrics SM CXICON int cyIcon GetSystemMetrics SM CYICON CRect rect GetClientRect int x rect Width cxIcon 1 2 int y rect Height cyIcon 1 2 Draw the icon dc DrawIcon x y m hIcon else CDialog 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 控件触发 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 SetDlgItemText 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 EDIT 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 OnButton6 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 control 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 code 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 SetDlgItemText 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 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 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 void CCalculatorDlg OnBtnMulti TODO Add your control notification handler code here temp m EDIT op m EDIT T point false void CCalculatorDlg OnBtnDiv TODO Add your control notification handler code here temp m EDIT op m EDIT T point false void CCalculatorDlg OnBtnEqual TODO Add your control notification handler code here 先进行进制判断 在进行运算 char c 50 switch form case H first tcstoul temp 0 16 second tcstoul m EDIT 0 16 switch op case if second 0 MessageBox 第二个操作数不能为 0 ERROR m EDIT T point false else result first second m EDIT Format d result break case result first second m EDIT Format X result break case result first second m EDIT Format X result break case result first second m EDIT Format X result break case if second 0 MessageBox 除数不能为 0 ERROR m EDIT T point false else result first second m EDIT Format X result break default return op SetDlgItemText IDC EDIT1 m EDIT break case D first tcstoul temp 0 10 second tcstoul m EDIT 0 10 a atof LPCTSTR temp b atof LPCTSTR m EDIT switch op case if second 0 MessageBox 第二个操作数不能为 0 ERROR m EDIT T point false else result first second m EDIT Format d result break case r a b m EDIT Format f r break case r a b m EDIT Format f r break case r a b m EDIT Format f r break case if b 0 MessageBox 除数不能为 0 ERROR m EDIT T point false else r a b m EDIT Format f r break default return op point true SetDlgItemText IDC EDIT1 m EDIT break case O first tcstoul temp 0 8 second tcstoul m EDIT 0 8 switch op case if second 0 MessageBox 第二个操作数不能为 0 ERROR m EDIT T point false else result first second m EDIT Format d result break case result first second m EDIT Format o result break case result first second m EDIT Format o result break case result first second m EDIT Format o result break case if second 0 MessageBox 除数不能为 0 ERROR m EDIT T point false else result first second m EDIT Format o result break default return op SetDlgItemText IDC EDIT1 m EDIT break case B first tcstoul temp 0 2 second tcstoul m EDIT 0 2 switch op case if second 0 MessageBox 第二个操作数不能为 0 ERROR m EDIT T point false else result first second itoa result c 2 m EDIT Format s c break case result first second itoa result c 2 m EDIT Format s c break case result first second itoa result c 2 m EDIT Format s c break case result first second itoa result c 2 m EDIT Format s c break case if second 0 MessageBox 除数不能为 0 ERROR m EDIT T point false else result first second itoa result c 2 m EDIT Format s c break default return op SetDlgItemText IDC EDIT1 m EDIT break default return void CCalculatorDlg OnBtnSign TODO Add your control notification handler code here double tmp tmp double atof m EDIT tmp 1 m EDIT Format g tmp SetDlgItemText IDC EDIT1 m EDIT void CCalculatorDlg OnBtnHex TODO Add your control notification handler code here GetDlgItem IDC BUTTON0 EnableWindow 1 GetDlgItem IDC BUTTON1 EnableWindow 1 GetDlgItem IDC BUTTON2 EnableWindow 1 GetDlgItem IDC BUTTON3 EnableWindow 1 GetDlgItem IDC BUTTON4 EnableWindow 1 GetDlgItem IDC BUTTON5 EnableWindow 1 GetDlgItem IDC BUTTON6 EnableWindow 1 GetDlgItem IDC BUTTON7 EnableWindow 1 GetDlgItem IDC BUTTON8 EnableWindow 1 GetDlgItem IDC BUTTON9 EnableWindow 1 GetDlgItem IDC BUTTONA EnableWindow 1 GetDlgItem IDC BUTTONB EnableWindow 1 GetDlgItem IDC BUTTONC EnableWindow 1 GetDlgItem IDC BUTTOND EnableWindow 1 GetDlgItem IDC BUTTONE EnableWindow 1 GetDlgItem IDC BUTTONF EnableWindow 1 GetDlgItem IDC BTN DOT EnableWindow 0 if atof LPCTSTR m EDIT 0 switch form case D m EDIT Format X tcstoul m EDIT 0 10 break case O m EDIT Format X tcstoul m EDIT 0 8 break case B m EDIT Format X tcstoul m EDIT 0 2 break default return SetDlgItemText IDC EDIT1 m EDIT else m EDIT T SetDlgItemText IDC EDIT1 m EDIT form H void CCalculatorDlg OnBtnDec TODO Add your control notification handler code here 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 GetDlgItem IDC BUTTON0 EnableWindow 1 GetDlgItem IDC BUTTON1 EnableWindow 1 GetDlgItem IDC BUTTON2 EnableWindow 1 GetDlgItem IDC BUTTON3 EnableWindow 1 GetDlgItem IDC BUTTON4 EnableWindow 1 GetDlgItem IDC BUTTON5 EnableWindow 1 GetDlgItem IDC BUTTON6 EnableWindow 1 GetDlgItem IDC BUTTON7 EnableWindow 1 GetDlgItem IDC BUTTON8 EnableWindow 1 GetDlgItem IDC BUTTON9 EnableWindow 1 GetDlgItem IDC BTN DOT EnableWindow 1 if tcstoul m EDIT 0 16 0 switch form case H m EDIT Format d tcstoul m EDIT 0 16 break case O m EDIT Format d tcstoul m EDIT 0 8 break case B m EDIT Format d tcstoul m EDIT 0 2 break default return SetDlgItemText IDC EDIT1 m EDIT else m EDIT T SetDlgItemText IDC EDIT1 m EDIT point false form D void CCalculatorDlg OnBtnOct TODO Add your control notification handler code here GetDlgItem IDC BUTTON0 EnableWindow 1 GetDlgItem IDC BUTTON1 EnableWindow 1 GetDlgItem IDC BUTTON2 EnableWindow 1 GetDlgItem IDC BUTTON3 EnableWindow 1 GetDlgItem IDC BUTTON4 EnableWindow 1 GetDlgItem IDC BUTTON5 EnableWindow 1 GetDlgItem IDC BUTTON6 EnableWindow 1 GetDlgItem IDC BUTTON7 EnableWindow 1 GetDlgItem IDC BUTTON8 EnableWindow 0 GetDlgItem IDC BUTTON9 EnableWindow 0 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 GetDlgItem IDC BTN DOT EnableWindow 0 if tcstoul m EDIT 0 16 0 switch form case H m EDIT Format o tcstoul m EDIT 0 16 break case D m EDIT Format o tcstoul m EDIT 0 10 break case B m EDIT Format o tcstoul m EDIT 0 2 break default return SetDlgItemText IDC EDIT1 m EDIT else m EDIT T SetDlgItemText IDC EDIT1 m EDIT form O void CCalculatorDlg OnBtnBin TODO Add your control notification handler code here int bintemp char binch 50 GetDlgItem IDC BUTTON2 EnableWindow 0 GetDlgItem IDC BUTTON3 EnableWindow 0 GetDlgItem IDC BUTTON4 EnableWindow 0 GetDlgItem IDC BUTTON5 EnableWindow 0 GetDlgItem IDC BUTTON6 EnableWindow 0 GetDlgItem IDC BUTTON7 EnableWindow 0 GetDlgItem IDC BUTTON8 EnableWindow 0 GetDlgItem IDC BUTTON9 EnableWindow 0 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 GetDlgItem IDC BTN DOT EnableWindow 0 if tcstoul m EDIT 0 16 0 switch f

温馨提示

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

评论

0/150

提交评论