C#课程设计实验报告.docx

上传人:b****8 文档编号:30236098 上传时间:2023-08-13 格式:DOCX 页数:41 大小:391.59KB
下载 相关 举报
C#课程设计实验报告.docx_第1页
第1页 / 共41页
C#课程设计实验报告.docx_第2页
第2页 / 共41页
C#课程设计实验报告.docx_第3页
第3页 / 共41页
C#课程设计实验报告.docx_第4页
第4页 / 共41页
C#课程设计实验报告.docx_第5页
第5页 / 共41页
点击查看更多>>
下载资源
资源描述

C#课程设计实验报告.docx

《C#课程设计实验报告.docx》由会员分享,可在线阅读,更多相关《C#课程设计实验报告.docx(41页珍藏版)》请在冰豆网上搜索。

C#课程设计实验报告.docx

C#课程设计实验报告

苏州市职业大学

课程设计说明书

名称计算机语言C#课程设计 

 弹珠游戏     

2010年6月21日至2010年7月4日共2周

院 系 计算机工程系 

班级09软件测试

姓名罗苑(096307335)

系 主 任李金祥

教研室主任叶良

指导教师张苏王德鹏

 

摘要:

这个小程序是关于弹珠的小游戏,游戏比较简单,以小球的速度来区分游戏的难易。

该小程序是用左右键控制游戏的开始和挡板的方向,不让小球落到底端,当然,小球的速度越快,该游戏的难度也就越大。

此程序利用C#程序编写,在visualstudio2005的环境下进行调试运行的。

弹珠原理:

碰撞基本都是参照“反射定理”的,就是出射角=入射角,但是做碰撞时需要角度。

碰撞的运动和球的方向有关,球的方向有好几种。

有8向的,也有4向的。

保证小球横向上在允许范围之内运动,当触发时就反方向运动,和当出了球拍的可击打范围就停止运行了。

对于该程序开发,必须达到以下要求:

1、熟悉.NET开发环境,能够使用C#语言在.NET平台上独立设计、开发WINDOWS应用程序。

2、掌握C#语言的异常处理技术,能够使用.NET各种调试方法调试代码,掌握帮助的使用方法。

3、掌握常用控件以及控件的常用属性的使用方法。

4、界面要做到简洁易懂,具有人性化等特点。

5、程序没有在使用过程中不存在任何的问题。

6、可选功能应全面,可以实施速度的选择,游戏的是否继续,还有记录的保存。

目录

摘要:

2

目录3

一、题目说明4

二、总体设计4

2.1.系统开发平台4

三、详细说明4

3.1系统实施4

四、遇到的问题和解决方法20

五、课程设计总结22

六、参考文献22

附录(源程序代码)22

 

一、题目说明

当今用简单的代码编写的小游戏越来越受人们的欢迎,所以对于小游戏的开发也成为了各大编程人士的最爱。

我选择弹珠游戏这个课题,用代码控制游戏的等级,运用不同的函数来控制球的速度和方向,游戏简单而有趣。

二、总体设计

2.1.系统开发平台

系统采用MicrosoftVisualStudio2005

三、详细说明

在此弹球游戏中,对于球与挡板的位置,借助于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);

}

#endregion

privatevoidSlowRadio_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

{

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);

SpeedDia

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1