


版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、輕型建材輕型建材頁腳內容頁腳內容 1摘要:該小程序是用左右鍵把握玩耍的開頭和擋板的方向,不讓小球落到底端,固然,小球的速度越快,該玩耍的難度也就越大。此程序利用C#程序編寫,在visualstudio2022的射角,但是做碰撞時需要角度。碰撞的運動和球的方向有關,球的方向有好幾種。有8向的,也有4向的。保證小球橫向上在允許范圍之內運動,當觸發時就反方向運動,和當出了球拍的可擊打范圍就停頓運行了。對于該程序開發,必需到達以下要求:程序。C#語言的特別處理技術,能夠使用.NET各種調試方法調試代碼,把握幫助的使用方法。3、把握常用控件以及控件的常用屬性的使用方法。、界面要做到簡潔易懂,具有人性化等
2、特點。、程序沒有在使用過程中不存在任何的問題。6、可選功能應全面,可以實施速度的選擇,玩耍的是否連續,還有記錄的保存。目錄 HYPERLINK l “_TOC_250010“ 摘要:1 HYPERLINK l “_TOC_250009“ 目錄2 HYPERLINK l “_TOC_250008“ 一、題目說明2 HYPERLINK l “_TOC_250007“ 二、總體設計3 HYPERLINK l “_TOC_250006“ 2.1系統開發平臺3 HYPERLINK l “_TOC_250005“ 三、具體說明3 HYPERLINK l “_TOC_250004“ .1系統實施3 HYPE
3、RLINK l “_TOC_250003“ 四、遇到的問題和解決方法19 HYPERLINK l “_TOC_250002“ 五、課程設計總結20 HYPERLINK l “_TOC_250001“ 六、參考文獻21 HYPERLINK l “_TOC_250000“ 附錄源程序代碼21一、題目說明頁腳內容頁腳內容 3輕型建材同的函數來把握球的速度和方向,玩耍簡潔而好玩。二、總體設計系統開發平臺系統承受Microsoft Visual Studio 2022三、具體說明在此彈球玩耍中,對于球與擋板的位置,借助于xyVisualStudio球的速度。打中一個磚塊即可得到一分,看你最多能打多少磚塊
4、。.111. 主界面功能菜單輕型建材輕型建材頁腳內容頁腳內容 4此界面的代碼為:using System;using System.Drawing; usingSystem.Collections;using System ponentModel;using System.Windows.Forms;namespace BrickOutpublic class SpeedDialog : System.Windows.Forms.Formprivate System.Windows.Forms.GroupBox groupBox1;privateSystem.Windows.Forms.But
5、ton button1;private System ponentModel.Container components = null;private Button button2;private PictureBox pictureBox1;private Button button3;private Button button4;publicintSpeed=250;public SpeedDialogInitializeComponent;protected overridevoid Dispose( bool disposing )if( disposing )if(components
6、 != null)components.Dispose;base.Dispose( disposing );#region Windows Form Designer generated codeprivate void InitializeComponentSystem ponentModel ponentResourceManager resources = newSystem ponentModel ponentResourceManager(typeof(SpeedDialog);this.groupBox1 = new System.Windows.Forms.GroupBox;th
7、is.button4 =new System.Windows.Forms.Button;this.button3 =new System.Windows.Forms.Button; this.button1 =new System.Windows.Forms.Button; this.button2 =new System.Windows.Forms.Button; this.pictureBox1 = new System.Windows.Forms.PictureBox;this.groupBox1.SuspendLayout;(System ponentModel.ISupportIni
8、tialize)(this.pictureBox1).BeginInit;this.SuspendLayout;this.groupBox1.BackColor = System.Drawing.Color.FromArgb(int)(byte)(224),(int)(byte)(224), (int)(byte)(224);this.groupBox1.Controls.Add(this.button4); this.groupBox1.Controls.Add(this.button3); this.groupBox1.Controls.Add(this.button1); this.gr
9、oupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.pictureBox1); this.groupBox1.Location = new System.Drawing.Point(-2, 1);this.groupBox1.Name = “groupBox1“;this.groupBox1.Size = new System.Drawing.Size(320, 344);this.groupBox1.TabIndex = 0;this.groupBox1.TabStop = false; this.grou
10、pBox1.Text“選擇難度“;this.button4.BackColor = System.Drawing.Color.FromArgb(int)(byte)(192),(int)(byte)(192), (int)(byte)(255);this.button4.ForeColor = System.Drawing.Color.Red; this.button4.Location = new System.Drawing.Point(108, 106);this.button4.Name = “button4“;this.button4.Size = new System.Drawin
11、g.Size(99, 29);this.button4.TabIndex = 5;this.button4.Text“幫助“; this.button4.UseVisualStyleBackColorfalse;this.button4.Click += new System.EventHandler(this.button4_Click);this.button3.BackColor = System.Drawing.Color.Cyan; this.button3.Location = new System.Drawing.Point(108, 58); this.button3.Name
12、 = “button3“;this.button3.Size = new System.Drawing.Size(99, 29);this.button3.TabIndex = 4;this.button3.Text“等級選擇“; this.button3.UseVisualStyleBackColorfalse;this.button3.Click += new System.EventHandler(this.button3_Click); this.button1.BackColor=System.Drawing.Color.FromArgb(int)(byte)(255),(int)(
13、byte)(128), (int)(byte)(128);this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;this.button1.Location = new System.Drawing.Point(107, 11); this.button1.Name = “button1“;this.button1.Size = new System.Drawing.Size(98, 29);this.button1.TabIndex = 10; this.button1.Text“進入玩?!?this.button1.
14、UseVisualStyleBackColor = true;this.button1.Click += new System.EventHandler(this.button1_Click); this.button2.BackColor=System.Drawing.Color.FromArgb(int)(byte)(192),(int)(byte)(192), (int)(byte)(0);this.button2.DialogResult = System.Windows.Forms.DialogResult.OK;this.button2.ForeColor = System.Dra
15、wing.Color.Blue; this.button2.Location = new System.Drawing.Point(110, 157); this.button2.Name = “button2“;this.button2.Size = new System.Drawing.Size(98, 29);this.button2.TabIndex = 2;this.button2.Text“退出玩?!? this.button2.UseVisualStyleBackColorfalse;this.button2.Click += new System.EventHandler(th
16、is.button2_Click);this.pictureBox1.BackgroundImage =(System.Drawing.Image)(resources.GetObject(“pictureBox1.BackgroundImage“); this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;this.pictureBox1.Location = new System.Drawing.Point(0, 0);this.pictureBox1.Name = “picture
17、Box1“; this.pictureBox1.Size = new System.Drawing.Size(318, 344);this.pictureBox1.TabIndex = 3;this.pictureBox1.TabStop= false;this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);this.AutoScaleBaseSize = newSystem.Drawing.Size(6, 14);this.BackColor = System.Drawing.Color.White;
18、 this.ClientSize = new System.Drawing.Size(316, 349);this.Controls.Add(this.groupBox1);this.Icon = (System.Drawing.Icon)(resources.GetObject(“$this.Icon“);this.Name = “SpeedDialog“;this.Text“歡送進入我的彈珠玩?!?this.TransparencyKey = System.Drawing.Color.Transparent; this.Load += new System.EventHandler(thi
19、s.SpeedDialog_Load);this.groupBox1.ResumeLayout(false);(System ponentModel.ISupportInitialize)(this.pictureBox1).EndInit;this.ResumeLayout(false);#endregionprivate void SlowRadio_CheckedChanged(object sender, System.EventArgse)private void button1_Click(object sender, System.EventArgs e)private void
20、 MediumRadio_CheckedChanged(object sender, EventArgs e)private void FastRadio_CheckedChanged(object sender, EventArgs e)private void button2_Click(object sender,EventArgs e)Application.Exit;private void button3_Click(object sender,EventArgs e)Form2 SpeedDialog =new Form2;SpeedDialog.ShowDialog;this.
21、Speed = SpeedDialog.Speed;private void button4_Click(object sender,EventArgs e)Form3 SpeedDialog = new Form3;SpeedDialog.ShowDialog;private void SlowRadio_CheckedChanged_1(object sender, EventArgs e)private void MediumRadio_CheckedChanged_1(object sender,EventArgs e)輕型建材輕型建材頁腳內容頁腳內容 8private void Fa
22、stRadio_CheckedChanged_1(object sender, EventArgs e)private void SpeedDialog_Load(object sender, EventArgs e)private void pictureBox1_Click(object sender,EventArgs e)玩耍幫助:在玩耍幫助后,就會跳出一個幫助的界面。閱讀幫助后關閉幫助,然后選擇難度進展玩耍。2 玩耍幫助此界面的代碼為:using System;using System.Collections.Generic;using System ponentModel; usi
23、ng System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace BrickOutpublicpartial class Form3 : Formpublic Form3InitializeComponent;private void Form3_Load(object sender, EventArgs e)選擇玩耍難度:在玩家將玩耍幫助了解以后,接下來就會進展玩耍難度的選擇,玩家依據對玩耍的操作嫻熟程度的不同選擇相應的玩耍難度。3此界面的代碼為:using System;us
24、ing System.Collections.Generic;using System ponentModel; using System.Data;using System.Drawing;頁腳內容頁腳內容 10輕型建材using System.Text;using System.Windows.Forms;namespace BrickOutpublicpartial class Form2 : Formpublic Form2InitializeComponent;private void button1_Click(object sender,EventArgs e)this.Clos
25、e;private void SlowRadio_CheckedChanged_1(object sender, EventArgs e)private void MediumRadio_CheckedChanged(object sender, EventArgs e)private void panel1_Paint(object sender, PaintEventArgs e)入玩耍。頁腳內容頁腳內容 11輕型建材4掉。以上三個界面的代碼為:using System;using System.Drawing; usingSystem.Collections;using System p
26、onentModel;using System.Windows.Forms; using System.Data;using System.Runtime.InteropServices;using System.Threading;輕型建材輕型建材頁腳內容頁腳內容 12namespace BrickOutpublic class Form1 : System.Windows.Forms.FormprivateSystem ponentModel.IContainer components;private const int kNumberOfRows = 8; privateconstint
27、kNumberOfTries=3;privateintNumTotalBricks=0;private intNumBalls =0;private Ball TheBall = new Ball; private Paddle ThePaddle = new Paddle; privateSystem.Windows.Forms.Timertimer1;private Row Rows = new RowkNumberOfRows;private ScoreTheScore = null;private Thread oThread = null;DllImport(“winmm.dll“)
28、publicstatic extern long PlaySound(String lpszName, long hModule, long dwFlags);public Form1InitializeComponent;for(int i = 0; i 0)m_strCurrentSoundFile = “;oThread.Abort;publicvoid PlaySoundInThread(string wavefile)m_strCurrentSoundFile = wavefile;oThread = new Thread(new ThreadStart(PlayASound);oT
29、hread.Start;#region Windows Form Designer generated codeprivate void InitializeComponentthis ponents = new System ponentModel.Container; System ponentModel ponentResourceManagerresources=newSystem ponentModel ponentResourceManager(typeof(Form1);this.timer1 = new System.Windows.Forms.Timer(this ponen
30、ts);this.SuspendLayout;this.timer1.Tick += new System.EventHandler(this.timer1_Tick);this.AutoScaleBaseSize = newSystem.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(552, 389);this.Icon = (System.Drawing.Icon)(resources.GetObject(“$this.Icon“);this.KeyPreview = true;this.Name = “For
31、m1“; this.Text“打磚塊“;this.Paint+= new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);this.Load +=new System.EventHandler(this.Form1_Load);this.ResumeLayout(false);#endregion STAThread staticvoidMainApplication.Run
32、(new Form1);private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)Graphics g = e.Graphics;g.FillRectangle(Brushes.White, 0, 0, this.ClientRectangle.Width,this.ClientRectangle.Height);TheScore.Draw(g);ThePaddle.Draw(g);DrawRows(g);TheBall.Draw(g);private void DrawRows(Graphics
33、 g)for(int i = 0; i kNumberOfRows; i+)Rowsi.Draw(g);private void CheckForCollisionif (TheBall.Position.X 0) TheBall.XStep *= -1; TheBall.Position.X+=TheBall.XStep;PlaySoundInThread(“WallHit.wav“);if (TheBall.Position.Y this.ClientRectangle.Right - TheBall.Width )TheBall.XStep *= -1; TheBall.Position
34、.X += TheBall.XStep;PlaySoundInThread(“WallHit.wav“);if (TheBall.Position.Y this.ClientRectangle.Bottom - TheBall.YStep)IncrementGameBalls;Reset;PlaySoundInThread(“BallOut.wav“);if (RowsCollide(TheBall.Position)TheBall.YStep *= -1; PlaySoundInThread(“BrickHit.wav“);inthp=HitsPaddle(TheBall.Position)
35、;if (hp -1)PlaySoundInThread(“PaddleHit.wav“);switch (hp)case 1:TheBall.XStep = -7;TheBall.YStep = -3;break;case 2:TheBall.XStep = -5;TheBall.YStep = -5;break;case 3:TheBall.XStep = 5;TheBall.YStep = -5;break;default:TheBall.XStep =7;TheBall.YStep = -3;break;private intHitsPaddle(Pointp)RectanglePad
36、dleRect = ThePaddle.GetBounds;if (p.Y =this.ClientRectangle.Bottom - (PaddleRect.Height + TheBall.Height) )if (p.X PaddleRect.Left) & (p.X PaddleRect.Left) & (p.X PaddleRect.Left+ PaddleRect.Width/4)&(p.X PaddleRect.Left+PaddleRect.Width/2)&(p.X= kNumberOfTries)timer1.Stop;stringmsg“玩耍完畢,您一共打了“ + Nu
37、mTotalBricks;if (NumTotalBricks = 1)msg += “ brick.“;elsemsgbricks.“ “連續努力哦!“;MessageBox.Show(msg); Application.Exit;private void ResetTheBall.XStep = 5;TheBall.YStep = 5;TheBall.Position.Y = this.ClientRectangle.Bottom - 190;TheBall.Position.X = 5;timer1.Stop; TheBall.UpdateBounds; Invalidate(TheBa
38、ll.GetBounds);private intSumBricks intsum = 0;for(int i = 0; i kNumberOfRows; i+)sum += Rowsi.BrickOut;return sum;private bool RowsCollide (Point p)for(int i = 0; i kNumberOfRows; i+)if (Rowsi.Collides(TheBall.GetBounds)Rectangle rRow = Rowsi.GetBounds;Invalidate(rRow);return true;returnfalse;privat
39、e void timer1_Tick(object sender, System.EventArgs e)TheBall.UpdateBounds; Invalidate(TheBall.GetBounds);TheBall.Move; TheBall.UpdateBounds; Invalidate(TheBall.GetBounds);CheckForCollision; NumTotalBricks = SumBricks; TheScore.Count = NumTotalBricks;Invalidate(TheScore.GetFrame);if (NumTotalBricks =
40、 kNumberOfRows*Row.kNumberOfBricks)timer1.Stop;Form4 Form1 = new Form4;Form1.ShowDialog; Application.Exit;private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)string result = e.KeyData.ToString;Invalidate(ThePaddle.GetBounds); switch (result)case“Left“:ThePaddle.MoveLeft; In
41、validate(ThePaddle.GetBounds);if (timer1.Enabled = false)timer1.Start;break; case“Right“:ThePaddle.MoveRight(ClientRectangle.Right);Invalidate(ThePaddle.GetBounds);if (timer1.Enabled = false)timer1.Start;break;default:輕型建材輕型建材頁腳內容頁腳內容 19break;private void Form1_Load(object sender, EventArgs e)四、遇到的問
42、題和解決方法誤。圖一:路徑錯誤在此拷貝的時候就不會造成圖片的損壞和喪失。造成窗口無限堆疊,使程序變成死循環。解決方案:在窗口 form1 中參加代碼 timer1.Stop;用來完畢前一個窗口。五、課程設計總結C#學問。程設計使我們懂得了理論與實際相結合是很重要的。的時候給我的指導,也感謝在這段時間給過我們幫助的同學。提出,分析和解決實際問題,熬煉實踐力量的重要環節,是對學生實際工作力量的具體訓練和考察過程.隨著科學技術進展的日月異,編程已經成為當今計算機應用中空前活潑題,都一一通過網絡解決了,同時還問過很多學得比較扎實的同學,是他們讓我們有了更多的了解,更好的讓我們在這個問題上著手設計. 這
43、次課程設計最終順當完成了,在設輕型建材輕型建材頁腳內容頁腳內容 21教師再次表示忠心的感謝!六、參考文獻,c#有用教程,電子工業出版社,20222022年。3王進強. Visual Basic.Net根底教程M, 北京:清華大學出版社,2022年。附錄源程序代碼using System;using System.Drawing; using System.Collections; using System ponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;u
44、sing System.Threading;namespace BrickOutpublic class Form1 : System.Windows.Forms.Formprivate System ponentModel.IContainer components;private const int kNumberOfRows = 8; private const int kNumberOfTries = 3;private int NumTotalBricks = 0;private int NumBalls = 0;private Ball TheBall = new Ball; pr
45、ivate Paddle ThePaddle = new Paddle;private System.Windows.Forms.Timer timer1; private Row Rows = new RowkNumberOfRows;private Score TheScore = null;private Thread oThread = null;dwFlags);DllImport(“winmm.dll“)public static extern long PlaySound(String lpszName, long hModule, longpublic Form1Initial
46、izeComponent;for (int i = 0; i kNumberOfRows; i+)Rowsi = new Row(i);ThePaddle.Position.X = 5;ThePaddle.Position.Y = this.ClientRectangle.Bottom - ThePaddle.Height;TheBall.Position.Y = this.ClientRectangle.Bottom - 200;this.SetBounds(this.Left,this.Top,Rows0.GetBounds.Width,this.Height);TheScore = ne
47、w Score(ClientRectangle.Right - 50, ClientRectangle.Bottom- 180);/ choose LevelSpeedDialog dlg = new SpeedDialog;if (dlg.ShowDialog = DialogResult.OK)timer1.Interval = dlg.Speed;/ TODO: Add any constructor code after InitializeComponent call/ / Clean up any resources being used./ protected override
48、void Dispose( bool disposing )if( disposing )if (components != null)components.Dispose;base.Dispose( disposing );private string m_strCurrentSoundFile = “BallOut.wav“;public void PlayASoundif (m_strCurrentSoundFile.Length 0)0);PlaySound(Application.StartupPath+ “ + m_strCurrentSoundFile,0,m_strCurren
49、tSoundFile = “;oThread.Abort;public void PlaySoundInThread(string wavefile)m_strCurrentSoundFile = wavefile;oThread = new Thread(new ThreadStart(PlayASound);oThread.Start;#region Windows Form Designer generated code/ / Required method for Designer support - do not modify/ the contents of this method
50、 with the code editor./ private void InitializeComponentthis ponents = new System ponentModel.Container; this.timer1 = new System.Windows.Forms.Timer(this ponents);this.SuspendLayout;/ timer1/this.timer1.Tick += new System.EventHandler(this.timer1_Tick);/ Form1/this.AutoScaleBaseSize = new System.Dr
51、awing.Size(6, 14);this.ClientSize = new System.Drawing.Size(552, 389); this.KeyPreview = true;this.Name = “Form1“; this.Text = “Brick Out“;this.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.Form1_Paint);this.KeyDown+=newSystem.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);this.Load += ne
52、w System.EventHandler(this.Form1_Load);this.ResumeLayout(false);#endregion/ / The main entry point for the application./ STAThreadstatic void MainApplication.Run(new Form1);private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgse)Graphics g = e.Graphics;g.FillRectangle(Brushes.Wh
53、ite,0,0,this.ClientRectangle.Width,this.ClientRectangle.Height);TheScore.Draw(g);ThePaddle.Draw(g);DrawRows(g);TheBall.Draw(g);private void DrawRows(Graphics g)for (int i = 0; i kNumberOfRows; i+)Rowsi.Draw(g);private void CheckForCollisionif (TheBall.Position.X 0) / hit the left side, switch polari
54、tyTheBall.XStep *= -1; TheBall.Position.X += TheBall.XStep;PlaySoundInThread(“WallHit.wav“);if (TheBall.Position.Y this.ClientRectangle.Right-TheBall.Width) /hit the left side, switch polarityTheBall.XStep *= -1; TheBall.Position.X += TheBall.XStep;PlaySoundInThread(“WallHit.wav“);lost the ball!if (
55、TheBall.Position.Ythis.ClientRectangle.Bottom - TheBall.YStep) /IncrementGameBalls;Reset;PlaySoundInThread(“BallOut.wav“);if (RowsCollide(TheBall.Position)TheBall.YStep *= -1; PlaySoundInThread(“BrickHit.wav“);int hp = HitsPaddle(TheBall.Position);if (hp -1)/ lost the ball!PlaySoundInThread(“PaddleHit.wav“);switch (hp)case 1:TheBall.XStep = -7;TheBall.YStep = -3;break;case 2:TheBall.XStep = -5;TheBall.YStep = -5;break;case 3:TheBall.XStep = 5;TheBall.YStep = -5;break;default:TheBall.XStep = 7;TheBall.YStep = -3;break;pr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司祭掃烈士墓活動方案
- 2025年中學教師資格考試試卷及答案
- 2025年衛生檢驗與檢疫專業知識考試試題及答案
- 2025年項目管理專業資格考試試題及答案
- 2025年認證會計師考試試卷及答案
- 2025年生態系統管理與保護專業考試題及答案
- 2025年人力資源管理與實務課程考試卷及答案
- 2025年社區心理服務與危機干預專業知識測試試題及答案
- 2025年工程管理與項目管理考試試題及答案
- 2025年工業機器人與自動化技術考試題及答案
- 3停止間轉法教案
- 2022-2023學年重慶市合川市三下數學期末學業質量監測模擬試題含解析
- 文創園物業管理方案
- 全過程造價咨詢服務實施方案
- 初二生地會考復習資料全
- 里氏硬度法檢測鋼材強度范圍記錄表、鋼材里氏硬度與抗拉強度范圍換算表
- 《屹立在世界的東方》示范課教學課件【人教部編版小學道德與法治五年級下冊】
- 四川省宜賓市翠屏區中學2022-2023學年數學八年級第二學期期末檢測試題含解析
- 2020-2021成都石室聯合中學蜀華分校小學數學小升初模擬試卷附答案
- 某冶金機械廠供配電系統設計
- 《在中亞細亞草原上》賞析 課件
評論
0/150
提交評論