弹珠小游戏课程设计实验报告_第1页
弹珠小游戏课程设计实验报告_第2页
弹珠小游戏课程设计实验报告_第3页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

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

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论