《嵌入式系統(tǒng)導論》課程設計_第1頁
《嵌入式系統(tǒng)導論》課程設計_第2頁
《嵌入式系統(tǒng)導論》課程設計_第3頁
《嵌入式系統(tǒng)導論》課程設計_第4頁
《嵌入式系統(tǒng)導論》課程設計_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、嵌入式系統(tǒng)導論嵌入式系統(tǒng)導論課程設課程設計計名稱 小游戲之小雞快跑姓名院系電氣工程系班級電子二班學號時間2014 年 12 月 19 日1目錄目錄設計目的-3設計器件-3設計步驟-3仿真步驟與結(jié)果-3 1.小雞行走-62.小雞停止下墜-6設計程序(部分)-71. 計時器程序-72. 操作程序-8 3. 行走路徑程序-94.主程序-12總結(jié)-152設計目的:設計目的:通過過此次實驗,讓大家更熟 visual studio 軟件的使用。同時通過小組討論的方式,增強大家的溝通、合作能力。學會在遇到問題時與他人協(xié)作的能力。設計設計器件:器件:計算機一臺 visual studio 軟件設計設計步驟:步

2、驟:1. 確立題目,選擇方向2. 進行編寫程序3. 打開 visual studio 軟件,加載程序4. 點擊運行按鈕,進行軟件的仿真5. 根據(jù)仿真結(jié)果進行調(diào)試仿真步驟與結(jié)果:仿真步驟與結(jié)果:步驟一3步驟二步驟三4步驟四步驟五 5小雞行走:6小雞停止下墜:7實驗程序(部分)計時器程序namespace ChickRun partial class Form1 / / private System.ComponentModel.IContainer components = null; / / / protected override void Dispose(bool disposing) i

3、f (disposing & (components != null) components.Dispose(); base.Dispose(disposing); #region Windows private void InitializeComponent() ponents = new System.ComponentModel.Container(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.timer1 = new System.Windows.Forms.Timer(ponents);

4、(System.ComponentModel.ISupportInitialize)(this.pictureBox1).BeginInit(); this.SuspendLayout(); / / pictureBox1 / this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = pictureBox1; this.pictureBox1.Size = new

5、System.Drawing.Size(530, 346); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);8 this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); / / t

6、imer1 / this.timer1.Tick += new System.EventHandler(this.timer1_Tick); / / Form1 / this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(530, 346); this.Controls.Add(this.pictureBox1); thi

7、s.Name = Form1; this.Text = Form1; this.Load += new System.EventHandler(this.Form1_Load); this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown); (System.ComponentModel.ISupportInitialize)(this.pictureBox

8、1).EndInit(); this.ResumeLayout(false); #endregion private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Timer timer1; 操作程序:using System;using System.Collections.Generic;using System.Text;using System.Drawing;namespace ChickRun public class Chick 9 public float g = 150.0f

9、; public float speedX; public float speedY = 100.0f; public float dt = 0.1f; public bool IsRuning = false; public bool IsJumping = false; public bool IsSpeeding = false; public bool IsFalling = false; public Bitmap bmp; public Chick() using (Bitmap bmpt = (Bitmap)Bitmap.FromFile(chick.png) bmp = bmp

10、t.Clone() as Bitmap; public void Update() if (!IsRuning) return; if (IsSpeeding) this.point.X += (int)(speedX *2) * dt+0.9); else this.point.X += (int)(speedX * dt+0.9); if (IsJumping | IsFalling) this.point.Y += (int)(-speedY * dt+0.9); speedY -= (int)(g * dt); public Point point; 行走路徑程序:using Syst

11、em;using System.Collections.Generic;using System.Text;using System.Drawing;namespace ChickRun10 public class Road static Random rand = new Random(); public int ItemLen; public List landbmp = new List(); public Road(int itemnum, int itemlen) if (itemlen 2) throw new Exception(); this.ItemLen = itemle

12、n; RoadItem item00 = new RoadItem(0,this.ItemLen); item00.imageIndex = 0; item00.type = 1; _roads.Add(item00); for (int i = 0; i itemnum-2; i+) int temp = rand.Next(0, 3); int index = 0; int ang = 0; if (temp = 0) ang = -20; index = 2; else if (temp = 1) ang = 0; index = 0; else ang = 20; index = 1;

13、 RoadItem item = new RoadItem(ang, this.ItemLen); if (rand.Next(0, 4) = 1) item.type = 0; else item.type = 1; item.imageIndex = index; _roads.Add(item); RoadItem item11 = new RoadItem(0, this.ItemLen); item11.imageIndex = 0;11 item11.type = 1; _roads.Add(item11); for (int i = 0; i _roads.Count; i+)

14、RoadItem item = _roadsi; if (i = 0) item.start = new Point(0, 100); else item.start = _roadsi - 1.end; item.end = new Point(item.start.X + item.length, item.start.Y + (int)(Math.Tan(item.angle * Math.PI / 180) * item.length+0.9); using (Image bmp1 = Image.FromFile(land0.png) landbmp.Add(bmp1.Clone()

15、 as Image); using (Image bmp2 = Image.FromFile(land20.png) landbmp.Add(bmp2.Clone() as Image); using (Image bmp3 = Image.FromFile(land-20.png) landbmp.Add(bmp3.Clone() as Image); /public int GetY(int x) / / int i = x / ItemLen; / int y = 0; / if (i + 1 RoadItems.Count) / / RoadItem item = RoadItemsi

16、; / float k = (x - item.start.X) / (float)(item.end.X - item.start.X); / y = item.start.Y + (int)k * (item.end.Y - item.start.Y); / / return y; / RoadItems _roads = new RoadItems(); public RoadItems RoadItems get 12 return _roads; public class RoadItems : List public class RoadItem public int angle;

17、 public int length; public int type;/0為空,1為陸地 public RoadItem(int angle, int length) this.angle = angle; this.length = length; public Point start; public Point end; public int GetY(int x) RoadItem item = this;/ RoadItemsi; float k = (x - item.start.X) / (float)(item.end.X - item.start.X); int y = it

18、em.start.Y + (int)(k * (item.end.Y - item.start.Y)+0.9); return y; public int imageIndex = 0; 主程序using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;13namespace ChickRun public partial class For

19、m1 : Form public Form1() InitializeComponent(); Scene sc; private void Form1_Load(object sender, EventArgs e) sc = new Scene(pictureBox1 .Size); sc.StateChange += new StateChange(sc_StateChange); sc.Refresh(); void sc_StateChange(int v,float p) if (v = 1) this.Text=跳起; else if (v = 2) jumpNum = 0; t

20、his.Text = 落到地面; else if (v = 3) this.Text = 正在下落; else if (v = 4) this.Text = 行走; else if (v = 5) this.Text = 下墜; else if (v = 6) this.Text = 停止下墜game over; else if (v = 7) this.Text = 停止,到達終點; this.Text+=+(int)(p*100)+%; private void pictureBox1_Paint(object sender, PaintEventArgs e) if (sc = null

21、) return; e.Graphics.DrawImage(sc.bitmap, new Point(0, 0);14 private void pictureBox1_MouseClick(object sender, MouseEventArgs e) timer1.Enabled = !timer1.Enabled; if (timer1.Enabled) sc.chick.IsRuning = true; private void timer1_Tick(object sender, EventArgs e) sc.Refresh(); pictureBox1.Refresh();

22、int jumpNum = 0; private void Form1_KeyDown(object sender, KeyEventArgs e) if (e.KeyData = Keys.Space) if (sc.currentRoadsIndex + 1 = sc.road.RoadItems.Count) return; jumpNum+; if (jumpNum 2) return; sc.chick.speedY = 150; sc.chick.IsJumping = true; else if (e.KeyData = Keys.S) if (sc.chick.IsRuning) sc.chick.IsSpeeding = true; /+5+1+a+s+

溫馨提示

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

最新文檔

評論

0/150

提交評論