




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
摘要:这个小程序是关于弹珠的小游戏,游戏比较简单,以小球的速度来区分游戏的难易。该小程序是用左右键控制游戏的开始和挡板的方向,不让小球落到底端,当然,小球的速度越快,该游戏的难度也就越大。此程序利用C#程序编写,在visual studio 2005的环境下进行调试运行的。弹珠原理:碰撞基本都是参照“反射定理”的,就是出射角=入射角,但是做碰撞时需要角度。碰撞的运动和球的方向有关,球的方向有好几种。有8向的,也有4向的。保证小球横向上在允许范围之内运动,当触发时就反方向运动,和当出了球拍的可击打范围就停止运行了。对于该程序开发,必须达到以下要求:1、熟悉.NET开发环境,能够使用C#语言在.NET平台上独立设计、开发WINDOWS应用程序。2、掌握C#语言的异常处理技术,能够使用.NET各种调试方法调试代码,掌握帮助的使用方法。3、掌握常用控件以及控件的常用属性的使用方法。4、界面要做到简洁易懂,具有人性化等特点。5、程序没有在使用过程中不存在任何的问题。6、可选功能应全面,可以实施速度的选择,游戏的是否继续,还有记录的保存。目 录摘要:2目 录3一、题目说明4二、总体设计42.1系统开发平台4三、详细说明4.1系统实施4四、遇到的问题和解决方法20五、课程设计总结22六、参考文献22附录(源程序代码)22一、 题目说明当今用简单的代码编写的小游戏越来越受人们的欢迎,所以对于小游戏的开发也成为了各大编程人士的最爱。我选择弹珠游戏这个课题,用代码控制游戏的等级,运用不同的函数来控制球的速度和方向,游戏简单而有趣。二、总体设计2.1系统开发平台系统采用Microsoft Visual Studio 2005三、详细说明 在此弹球游戏中,对于球与挡板的位置,借助于x与y坐标的调整来实现统计,从而确定球落在板上后球的下一次方向。同时借助于Visual Studio中的控件来控制小球的速度。此项游戏的计分运用函数count+,打中一个砖块即可得到一分,看你最多能打多少砖块。.1系统实施1主界面:打开弹珠游戏,开始运行程序,跳出一个Forms界面,用户在此时必须先选择符合自己能力的游戏等级,然后才可以进行游戏。如图1所示。 图1. 主界面功能菜单此界面的代码为:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace BrickOutpublic class SpeedDialog : System.Windows.Forms.Form private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null; private Button button2; private PictureBox pictureBox1; private Button button3; private Button button4; public int Speed = 250;public SpeedDialog()InitializeComponent();protected override void Dispose( bool disposing )if( disposing )if(components != null)components.Dispose();base.Dispose( disposing );#region Windows Form Designer generated codeprivate void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SpeedDialog); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.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.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 = 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.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 = new System.Drawing.Point(108, 106); this.button4.Name = button4; this.button4.Size = new System.Drawing.Size(99, 29); this.button4.TabIndex = 5; this.button4.Text = 帮助; this.button4.UseVisualStyleBackColor = false; 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 = button3; this.button3.Size = new System.Drawing.Size(99, 29); this.button3.TabIndex = 4; this.button3.Text = 等级选择; this.button3.UseVisualStyleBackColor = false; this.button3.Click += new System.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 = 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.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.Drawing.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.UseVisualStyleBackColor = false; this.button2.Click += new System.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 = new System.Drawing.Point(0, 0); this.pictureBox1.Name = pictureBox1; 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 = new System.Drawing.Size(6, 14); this.BackColor = System.Drawing.Color.White; 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(this.SpeedDialog_Load); this.groupBox1.ResumeLayout(false); (System.ComponentModel.ISupportInitialize)(this.pictureBox1).EndInit(); this.ResumeLayout(false); #endregion private void SlowRadio_CheckedChanged(object sender, System.EventArgs e) private void button1_Click(object sender, System.EventArgs e) private void 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.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) private void FastRadio_CheckedChanged_1(object sender, EventArgs e) private void SpeedDialog_Load(object sender, EventArgs e) private void pictureBox1_Click(object sender, EventArgs e) 2.游戏帮助:在游戏帮助后,就会跳出一个帮助的界面。阅读帮助后关闭帮助,然后选择难度进行游戏。 图2 游戏帮助此界面的代码为:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace BrickOut public partial class Form3 : Form public Form3() InitializeComponent(); private void Form3_Load(object sender, EventArgs e) 3.选择游戏难度:在玩家将游戏帮助了解以后,接下来就会进行游戏难度的选择,玩家根据对游戏的操作熟练程度的不同选择相应的游戏难度。图3游戏难度选择界面此界面的代码为:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace BrickOut public partial class Form2 : Form public Form2() InitializeComponent(); private void button1_Click(object sender, EventArgs e) this.Close(); 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) 4.开始游戏:在玩家选择游戏难度后,单击确定,然后单击“开始游戏”按钮,进入游戏。 图4游戏开始界面5.游戏结束:游戏结束有两种结果,玩家将所有砖块都打完和玩家将三次机会都浪费掉。 以上三个界面的代码为:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;using System.Threading;namespace BrickOutpublic class Form1 : System.Windows.Forms.Form private System.ComponentModel.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(); private Paddle ThePaddle = new Paddle(); private System.Windows.Forms.Timer timer1; private Row Rows = new RowkNumberOfRows; private Score TheScore = null; private Thread oThread = null; DllImport(winmm.dll) public static extern long PlaySound(String lpszName, long hModule, long dwFlags);public Form1()InitializeComponent(); for (int i = 0; i 0) m_strCurrentSoundFile = ; oThread.Abort(); public void PlaySoundInThread(string wavefile) m_strCurrentSoundFile = wavefile; oThread = new Thread(new ThreadStart(PlayASound); oThread.Start(); #region Windows Form Designer generated codeprivate void InitializeComponent() ponents = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1); this.timer1 = new System.Windows.Forms.Timer(ponents); this.SuspendLayout(); this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.AutoScaleBaseSize = new System.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 = Form1; 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); #endregionSTAThreadstatic void Main() Application.Run(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 g) for (int i = 0; i kNumberOfRows; i+) Rowsi.Draw(g); private void CheckForCollision() if (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.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); int hp = HitsPaddle(TheBall.Position); 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 int HitsPaddle(Point p) Rectangle PaddleRect = 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(); string msg = 游戏结束,您一共打了 + NumTotalBricks; if (NumTotalBricks = 1) msg += brick.; else msg += bricks. + 继续努力哦!; MessageBox.Show(msg); Application.Exit(); private v
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年劳动保障协理员(中级)考试试卷:劳动保障政策执行与社会保障制度完善策略新探讨
- 2025年金融衍生品市场创新模式下的风险防范与监管策略报告
- 医疗器械冷链物流体系标准化建设现状与2025年改进措施研究报告
- 乙肝疫苗联合榄香烯复合肝癌抗原冲激树突状细胞的免疫调控机制与应用前景探究
- 主题式教学法在泰国中学汉语课堂的应用与创新研究
- 不平衡负载下微网逆变器控制策略的多维度探究与优化
- 聚焦2025年:养老地产市场需求与产品智能化养老生活报告
- 中国健身中心行业发展监测及投资战略规划研究报告
- 2025年中国奶油开口松子行业市场发展前景及发展趋势与投资战略研究报告
- 2025年中国机械硬盘行业发展现状与投资战略规划可行性报告
- 广东省风力发电内蒙古分公司广东能源集团招聘笔试题库2025
- 父亲节你了解你的爸爸吗礼赞父亲学会感恩模板
- 2023-2024学年安徽省合肥市六校联盟高一下学期期末联考地理试题(解析版)
- 新设备专项安全风险辨识评估报告示例-副本
- 苏州市昆山市惠民物业管理有限公司招聘笔试真题2024
- 初级银行从业资格考试《个人贷款》新版真题卷(2025年含答案)
- 民航飞行员招飞心理测试题及答案
- 生地考试测试题及答案
- 《动物保定技术》课件
- 2025年出版:全球市场光伏硅胶总体规模、主要生产商、主要地区、产品和应用细分调研报告
- 北京市朝阳区2023-2024学年四年级下学期语文期末考试卷(含答案)
评论
0/150
提交评论