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

下载本文档

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

文档简介

摘要:这个小程序是关于弹珠小游戏,游戏比较简朴,以小球速度来区别游戏难易。该小程序是用左右键控制游戏开始和挡板方向,不让小球落究竟端,固然,小球速度越快,该游戏难度也就越大。此程序运用C#程序编写,在visualstudio环境下进行调试运营。弹珠原理:碰撞基本都是参照“反射定理”,就是出射角=入射角,但是做碰撞时需要角度。碰撞运动和球方向关于,球方向有好几种。有8向,也有4向。保证小球横向上在容许范畴之内运动,当触发时就反方向运动,和当出了球拍可击打范畴就停止运营了。对于该程序开发,必要达到如下规定:1、熟悉.NET开发环境,可以使用C#语言在.NET平台上独立设计、开发WINDOWS应用程序。2、掌握C#语言异常解决技术,可以使用.NET各种调试办法调试代码,掌握协助用法。3、掌握惯用控件以及控件惯用属性用法。4、界面要做到简洁易懂,具备人性化等特点。5、程序没有在使用过程中不存在任何问题。6、可选功能应全面,可以实行速度选取,游戏与否继续,尚有记录保存。目录摘要: 2目录 3一、 题目阐明 4二、总体设计 42.1.系统开发平台 4三、详细阐明 43.1系统实行 4四、遇到问题和解决办法 20五、课程设计总结 22六、参照文献 22附录(源程序代码) 22题目阐明当今用简朴代码编写小游戏越来越受人们欢迎,因此对于小游戏开发也成为了各大编程人士最爱。我选取弹珠游戏这个课题,用代码控制游戏级别,运用不同函数来控制球速度和方向,游戏简朴而有趣。二、总体设计2.1.系统开发平台系统采用MicrosoftVisualStudio三、详细阐明在此弹球游戏中,对于球与挡板位置,借助于x与y坐标调节来实现记录,从而拟定球落在板上后球下一次方向。同步借助于VisualStudio中控件来控制小球速度。此项游戏计分运用函数count++,打中一种砖块即可得到一分,看你最多能打多少砖块。3.1系统实行1.主界面:打开弹珠游戏,开始运营程序,跳出一种Forms界面,顾客在此时必要先选取符合自己能力游戏级别,然后才可以进行游戏。如图1所示。图1.主界面功能菜单此界面代码为:usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Windows.Forms;namespaceBrickOut{ publicclassSpeedDialog:System.Windows.Forms.Form {privateSystem.Windows.Forms.GroupBoxgroupBox1;privateSystem.Windows.Forms.Buttonbutton1; privateSystem.ComponentModel.Containercomponents=null;privateButtonbutton2;privatePictureBoxpictureBox1;privateButtonbutton3;privateButtonbutton4;publicintSpeed=250; publicSpeedDialog() { InitializeComponent(); } protectedoverridevoidDispose(booldisposing) { if(disposing) { if(components!=null) { components.Dispose(); } } base.Dispose(disposing); } #regionWindowsFormDesignergeneratedcode privatevoidInitializeComponent() {System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(SpeedDialog));this.groupBox1=newSystem.Windows.Forms.GroupBox();this.button4=newSystem.Windows.Forms.Button();this.button3=newSystem.Windows.Forms.Button();this.button1=newSystem.Windows.Forms.Button();this.button2=newSystem.Windows.Forms.Button();this.pictureBox1=newSystem.Windows.Forms.PictureBox();this.groupBox1.SuspendLayout();((System.ComponentModel.ISupportInitialize)(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.groupBox1.Controls.Add(this.button2);this.groupBox1.Controls.Add(this.pictureBox1);this.groupBox1.Location=newSystem.Drawing.Point(-2,1);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(320,344);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.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=newSystem.Drawing.Point(108,106);this.button4.Name="button4";this.button4.Size=newSystem.Drawing.Size(99,29);this.button4.TabIndex=5;this.button4.Text="协助";this.button4.UseVisualStyleBackColor=false;this.button4.Click+=newSystem.EventHandler(this.button4_Click);this.button3.BackColor=System.Drawing.Color.Cyan;this.button3.Location=newSystem.Drawing.Point(108,58);this.button3.Name="button3";this.button3.Size=newSystem.Drawing.Size(99,29);this.button3.TabIndex=4;this.button3.Text="级别选取";this.button3.UseVisualStyleBackColor=false;this.button3.Click+=newSystem.EventHandler(this.button3_Click);this.button1.BackColor=System.Drawing.Color.FromArgb(((int)(((byte)(255)))),((int)(((byte)(128)))),((int)(((byte)(128)))));this.button1.DialogResult=System.Windows.Forms.DialogResult.OK;this.button1.Location=newSystem.Drawing.Point(107,11);this.button1.Name="button1";this.button1.Size=newSystem.Drawing.Size(98,29);this.button1.TabIndex=10;this.button1.Text="进入游戏";this.button1.UseVisualStyleBackColor=true;this.button1.Click+=newSystem.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.Drawing.Color.Blue;this.button2.Location=newSystem.Drawing.Point(110,157);this.button2.Name="button2";this.button2.Size=newSystem.Drawing.Size(98,29);this.button2.TabIndex=2;this.button2.Text="退出游戏";this.button2.UseVisualStyleBackColor=false;this.button2.Click+=newSystem.EventHandler(this.button2_Click);this.pictureBox1.BackgroundImage=((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));this.pictureBox1.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Stretch;this.pictureBox1.Location=newSystem.Drawing.Point(0,0);this.pictureBox1.Name="pictureBox1";this.pictureBox1.Size=newSystem.Drawing.Size(318,344);this.pictureBox1.TabIndex=3;this.pictureBox1.TabStop=false;this.pictureBox1.Click+=newSystem.EventHandler(this.pictureBox1_Click);this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);this.BackColor=System.Drawing.Color.White;this.ClientSize=newSystem.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+=newSystem.EventHandler(this.SpeedDialog_Load);this.groupBox1.ResumeLayout(false);((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();this.ResumeLayout(false);} #endregionprivatevoidSlowRadio_CheckedChanged(objectsender,System.EventArgse){}privatevoidbutton1_Click(objectsender,System.EventArgse){}privatevoidMediumRadio_CheckedChanged(objectsender,EventArgse){}privatevoidFastRadio_CheckedChanged(objectsender,EventArgse){}privatevoidbutton2_Click(objectsender,EventArgse){Application.Exit();}privatevoidbutton3_Click(objectsender,EventArgse){Form2SpeedDialog=newForm2();SpeedDialog.ShowDialog();this.Speed=SpeedDialog.Speed;}privatevoidbutton4_Click(objectsender,EventArgse){Form3SpeedDialog=newForm3();SpeedDialog.ShowDialog();}privatevoidSlowRadio_CheckedChanged_1(objectsender,EventArgse){}privatevoidMediumRadio_CheckedChanged_1(objectsender,EventArgse){}privatevoidFastRadio_CheckedChanged_1(objectsender,EventArgse){}privatevoidSpeedDialog_Load(objectsender,EventArgse){}privatevoidpictureBox1_Click(objectsender,EventArgse){} }}2.游戏协助:在游戏协助后,就会跳出一种协助界面。阅读协助后关闭协助,然后选取难度进行游戏。图2游戏协助此界面代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceBrickOut{publicpartialclassForm3:Form{publicForm3(){InitializeComponent();}privatevoidForm3_Load(objectsender,EventArgse){}}}3.选取游戏难度:在玩家将游戏协助理解后来,接下来就会进行游戏难度选取,玩家依照对游戏操作纯熟限度不同选取相应游戏难度。图3游戏难度选取界面此界面代码为:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceBrickOut{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){this.Close();}privatevoidSlowRadio_CheckedChanged_1(objectsender,EventArgse){}privatevoidMediumRadio_CheckedChanged(objectsender,EventArgse){}privatevoidpanel1_Paint(objectsender,PaintEventArgse){}}}4.开始游戏:在玩家选取游戏难度后,单击拟定,然后单击“开始游戏”按钮,进入游戏。图4游戏开始界面5.游戏结束:游戏结束有两种成果,玩家将所有砖块都打完和玩家将三次机会都挥霍掉。以上三个界面代码为:usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Windows.Forms;usingSystem.Data;usingSystem.Runtime.InteropServices;usingSystem.Threading;namespaceBrickOut{ publicclassForm1:System.Windows.Forms.Form {privateSystem.ComponentModel.IContainercomponents;privateconstintkNumberOfRows=8;privateconstintkNumberOfTries=3;privateintNumTotalBricks=0;privateintNumBalls=0;privateBallTheBall=newBall();privatePaddleThePaddle=newPaddle();privateSystem.Windows.Forms.Timertimer1;privateRow[]Rows=newRow[kNumberOfRows];privateScoreTheScore=null;privateThreadoThread=null;[DllImport("winmm.dll")]publicstaticexternlongPlaySound(StringlpszName,longhModule,longdwFlags); publicForm1() { InitializeComponent();for(inti=0;i<kNumberOfRows;i++){Rows[i]=newRow(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,Rows[0].GetBounds().Width,this.Height);TheScore=newScore(ClientRectangle.Right-50,ClientRectangle.Bottom-180);SpeedDialogdlg=newSpeedDialog();if(dlg.ShowDialog()==DialogResult.OK){timer1.Interval=dlg.Speed;} } protectedoverridevoidDispose(booldisposing) { if(disposing) { if(components!=null) { components.Dispose(); } } base.Dispose(disposing); }privatestringm_strCurrentSoundFile="BallOut.wav";publicvoidPlayASound(){if(m_strCurrentSoundFile.Length>0){}m_strCurrentSoundFile="";oThread.Abort();}publicvoidPlaySoundInThread(stringwavefile){m_strCurrentSoundFile=wavefile;oThread=newThread(newThreadStart(PlayASound));oThread.Start();} #regionWindowsFormDesignergeneratedcode privatevoidInitializeComponent() {ponents=newSystem.ComponentModel.Container();System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(Form1));this.timer1=newSystem.Windows.Forms.Timer(ponents);this.SuspendLayout();this.timer1.Tick+=newSystem.EventHandler(this.timer1_Tick);this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);this.ClientSize=newSystem.Drawing.Size(552,389);this.Icon=((System.Drawing.Icon)(resources.GetObject("$this.Icon")));this.KeyPreview=true;this.Name="Form1";this.Text="打砖块";this.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.Form1_Paint);this.KeyDown+=newSystem.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);this.Load+=newSystem.EventHandler(this.Form1_Load);this.ResumeLayout(false);} #endregion [STAThread] staticvoidMain() { Application.Run(newForm1()); }privatevoidForm1_Paint(objectsender,System.Windows.Forms.PaintEventArgse){Graphicsg=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);}privatevoidDrawRows(Graphicsg){for(inti=0;i<kNumberOfRows;i++){Rows[i].Draw(g);}}privatevoidCheckForCollision(){if(TheBall.Position.X<0){TheBall.XStep*=-1;TheBall.Position.X+=TheBall.XStep;PlaySoundInThread("WallHit.wav");}if(TheBall.Position.Y<0){TheBall.YStep*=-1;TheBall.Position.Y+=TheBall.YStep;PlaySoundInThread("WallHit.wav");}if(TheBall.Position.X>this.ClientRectangle.Right-TheBall.Width){TheBall.XStep*=-1;TheBall.Position.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);if(hp>-1){PlaySoundInThread("PaddleHit.wav");switch(hp){case1:TheBall.XStep=-7;TheBall.YStep=-3;break;case2:TheBall.XStep=-5;TheBall.YStep=-5;break;case3:TheBall.XStep=5;TheBall.YStep=-5;break;default:TheBall.XStep=7;TheBall.YStep=-3;break;}}}privateintHitsPaddle(Pointp){RectanglePaddleRect=ThePaddle.GetBounds();if(p.Y>=this.ClientRectangle.Bottom-(PaddleRect.Height+TheBall.Height)){if((p.X>PaddleRect.Left)&&(p.X<PaddleRect.Right)){if((p.X>PaddleRect.Left)&&(p.X<=PaddleRect.Left+PaddleRect.Width/4))return1;elseif((p.X>PaddleRect.Left+PaddleRect.Width/4)&&(p.X<=PaddleRect.Left+PaddleRect.Width/2))return2;elseif((p.X>PaddleRect.Left+PaddleRect.Width/2)&&(p.X<=PaddleRect.Right-PaddleRect.Width/2))return3;elsereturn4;}}return-1;}privatevoidIncrementGameBalls(){NumBalls++;if(NumBalls>=kNumberOfTries){timer1.Stop();stringmsg="游戏结束,您一共打了"+NumTotalBricks;if(NumTotalBricks==1)msg+="brick.";elsemsg+="bricks."+"继续努力哦!";MessageBox.Show(msg);Application.Exit();}}privatevoidReset(){TheBall.XStep=5;TheBall.YStep=5;TheBall.Position.Y=this.ClientRectangle.Bottom-190;TheBall.Position.X=5;timer1.Stop();TheBall.UpdateBounds();Invalidate(TheBall.GetBounds());}privateintSumBricks(){intsum=0;for(inti=0;i<kNumberOfRows;i++){sum+=Rows[i].BrickOut;}returnsum;}privateboolRowsCollide(Pointp){for(inti=0;i<kNumberOfRows;i++){if(Rows[i].Collides(TheBall.GetBounds())){RectanglerRow=Rows[i].GetBounds();Invalidate(rRow);returntrue;}}returnfalse;}privatevoidtimer1_Tick(objectsender,System.EventArgse){TheBall.UpdateBounds();Invalidate(TheBall.GetBounds());TheBall.Move();TheBall.UpdateBounds();Invalidate(TheBall.GetBounds());CheckForCollision();NumTotalBricks=SumBricks();TheScore.Count=NumTotalBricks;Invalidate(TheScore.GetFrame());if(NumTotalBricks==kNumberOfRows*Row.kNumberOfBricks){timer1.Stop();Form4Form1=newForm4();Form1.ShowDialog();Application.Exit();}}privatevoidForm1_KeyDown(objectsender,System.Windows.Forms.KeyEventArgse){stringresult=e.KeyData.ToString();Invalidate(ThePaddle.GetBounds());switch(result){case"Left":ThePaddle.MoveLeft();Invalidate(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:break;}}privatevoidForm1_Load(objectsender,EventArgse){} }}四、遇到问题和解决办法1.错误:图片途径错误,在做此程序时候对游戏中浮现挡板进行选取时候,选取了在桌面上图片,日后将此程序拷到自己电脑上时候运营代码浮现了途径错误。图一:途径错误解决方案:将图片重新拷到游戏文献夹中,并且将途径改到相应游戏文献夹中,在此拷贝时候就不会导致图片损坏和丢失。2.错误:游戏结束时由于缺少结束代码,使得游戏虽然结束,但是窗口无法结束,导致窗口无限堆叠,使程序变成死循环。解决方案:在窗口form1中加入代码timer1.Stop();用来结束前一种窗口。五、课程设计总结通过两周课程设计,使我对C#编程有了更深一层理解。在这两周课程设计中我不断地改错,不断调试,我努力终于有了成果。最让我受益匪浅是整个设计过程,这个过程也是我不断学习一种过程,咱们在运用旧知识同步也学到了不少新知识。本次课程设计我发现自己对知识掌握还存在着诸多局限性之处,同步我也明白了自己尚有哪些地方需要改进,自己要在哪些地方进行自我提高。尤为重要是,这次课程设计使咱们懂得了理论与实际相结合是很重要。在这次课程设计中,我虽然遇到某些困难,但我仍能坚持克服。通过这个小小课题,我也学到了某些课外东西,多谢学校给了我一次体验机会,谢谢教师在我困难时候给我指引,也谢谢在这段时间给过咱们协助同窗。在此期间我也失落过,也曾一度热情高涨。从开始时满腹盛激情到最后汗水背后复杂心情,点点滴滴无不令我回味无穷。课程设计是培养学生综合运用所学知识,发现,提出,分析和解决实际问题,锻炼实践能力重要环节,是对学生实际工作能力详细训练和考察过程.随着科学技术发展日新月异,编程已经成为当今计算机应用中空前活跃领域,在生活中可以说得是无处不在。在设计过程中,咱们遇到许多无法解决问题,都一一通过网络解决了,同步还问过许多学得比较夯实同窗,是她们让咱们有了更多理解,更好让咱们在这个问题上着手设计.这次课程设计终于顺利完毕了,在设计中遇到了诸多编程问题,最后在教师细心指引下,终于得到解决。同步,在教师身上我学得到诸多实用知识,在次我表达感谢!对给过我协助所有同窗和各位指引教师再次表达忠心感谢!六、参照文献[1]郑阿奇、梁敬东、钱晓军等,c#实用教程,电子工业出版社,。[2]钱雪忠、黄学光等,数据库原理及应用,北京邮电大学出版社,。[3]王进强.VisualBasic.Net基本教程[M],北京:清华大学出版社,。附录(源程序代码)usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Windows.Forms;usingSystem.Data;usingSystem.Runtime.InteropServices;usingSystem.Threading;namespaceBrickOut{ publicclassForm1:System.Windows.Forms.Form {privateSystem.ComponentModel.IContainercomponents;privateconstintkNumberOfRows=8;privateconstintkNumberOfTries=3;privateintNumTotalBricks=0;privateintNumBalls=0;privateBallTheBall=newBall();privatePaddleThePaddle=newPaddle();privateSystem.Windows.Forms.Timertimer1;privateRow[]Rows=newRow[kNumberOfRows];privateScoreTheScore=null;privateThreadoThread=null;[DllImport("winmm.dll")]publicstaticexternlongPlaySound(StringlpszName,longhModule,longdwFlags); publicForm1() { InitializeComponent();for(inti=0;i<kNumberOfRows;i++){Rows[i]=newRow(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,Rows[0].GetBounds().Width,this.Height);TheScore=newScore(ClientRectangle.Right-50,ClientRectangle.Bottom-180);//chooseLevelSpeedDialogdlg=newSpeedDialog();if(dlg.ShowDialog()==DialogResult.OK){timer1.Interval=dlg.Speed;} // //TODO:AddanyconstructorcodeafterInitializeComponentcall // } ///<summary> ///Cleanupanyresourcesbeingused. ///</summary> protectedoverridevoidDispose(booldisposing) { if(disposing) { if(components!=null) { components.Dispose(); } } base.Dispose(disposing); }privatestringm_strCurrentSoundFile="BallOut.wav";publicvoidPlayASound(){if(m_strCurrentSoundFile.Length>0){PlaySound(Application.StartupPath+"\\"+m_strCurrentSoundFile,0,0);}m_strCurrentSoundFile="";oThread.Abort();}publicvoidPlaySoundInThread(stringwavefile){m_strCurrentSoundFile=wavefile;oThread=newThread(newThreadStart(PlayASound));oThread.Start();} #regionWindowsFormDesignergeneratedcode ///<summary> ///RequiredmethodforDesignersupport-donotmodify ///thecontentsofthismethodwiththecodeeditor. ///</summary> privatevoidInitializeComponent() {ponents=newSystem.ComponentModel.Container();this.timer1=newSystem.Windows.Forms.Timer(ponents);this.SuspendLayout();////timer1//this.timer1.Tick+=newSystem.EventHandler(this.timer1_Tick);////Form1//this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);this.ClientSize=newSystem.Drawing.Size(552,389);this.KeyPreview=true;this.Name="Form1";this.Text="BrickOut";this.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.Form1_Paint);this.KeyDown+=newSystem.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);this.Load+=newSystem.EventHandler(this.Form1_Load);this.ResumeLayout(false);} #endregion ///<summary> ///Themainentrypointfortheapplication. ///</summary> [STAThread] staticvoidMain() { Application.Run(newForm1()); }privatevoidForm1_Paint(objectsender,System.Windows.Forms.PaintEventArgse){Graphicsg=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);}privatevoidDrawRows(Graphicsg){for(inti=0;i<kNumberOfRows;i++){Rows[i].Draw(g);}}privatevoidCheckForCollision(){if(TheBall.Position.X<0)//hittheleftside,switchpolarity{TheBall.XStep*=-1;TheBall.Position.X+=TheBall.XStep;PlaySoundInThread("WallHit.wav");}if(TheBall.Position.Y<0)//hitthetopoftheform,switchpolarity{TheBall.YStep*=-1;TheBall.Position.Y+=TheBall.YStep;PlaySoundInThread("WallHit.wav");}if(TheBall.Position.X>this.ClientRectangle.Right-TheBall.Width)//hittheleftside,switchpolarity{TheBall.XStep*=-1;TheBall.Position.X+=TheBall.XStep;PlaySoundInThread("WallHit.wav");}if(TheBall.Position.Y>this.ClientRectangle.Bottom-TheBall.YStep)//losttheball!{IncrementGameBalls();Reset();PlaySoundInThread("BallOut.wav");}if(RowsCollide(TheBall.Position)){TheBall.YStep*=-1;PlaySoundInThread("BrickHit.wav");}inthp=HitsPaddle(TheBall.Position);if(hp>-1)//losttheball!{PlaySoundInThread("PaddleHit.wav");switch(hp){case1:TheBall.XStep=-7;TheBall.YStep=-3;break;case2:TheBall.XStep=-5;TheBall.YStep=-5;break;case3:TheBall.XStep=5;TheBall.YStep=-5;break;default:TheBall.XStep=7;TheBall.YStep=-3;break;}}}privateintHitsPaddle(Pointp){RectanglePaddleRect=ThePaddle.GetBounds();if(p.Y>=this.ClientRectangle.Bottom-(PaddleRect.Height+TheBall.Height)){if((p.X>PaddleRect.Left)&&(p.X<PaddleRect.Right)){if((p.X>PaddleRect.Left)&&(p.X<=PaddleRect.Left+PaddleRect.Width/4))return1;elseif((p.X>PaddleRect.Left+PaddleRect.Width/4)&&(p.X<=PaddleRect.Left+PaddleRect.Width/2))return2;elseif((p.X>PaddleRect.Left+PaddleRect.Width/2)&&(p.X<=PaddleRect.Right-PaddleRect.Width/2))return3;

温馨提示

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

评论

0/150

提交评论