打砖块游戏课程设计报告 - 图文

loading 分享 2026-7-19 下载文档

辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)

2.3程序部分源代码及注释

2.3.1 RussiaBlock类

以下涉及的词语基本块指的是由四个小方块构成的实体,四个小方块指的是小正方形。方块与基本块同义。

1) 构造函数,通过给定的参数:控件实例,左边界,底边界,小方块(一个基本块由4个小方块构成)单位象素,形状号,起始位置,颜色。 2) 程序部分源代码及注释

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;

using System.Windows.Forms; using System.Threading;

namespace Arkanoid {

public partial class GameCol1 : Form {

public GameCol1() {

InitializeComponent(); }

Point[] pointPic = new Point[50]; // string keySpace = \ string key = \ string xfangxiang = \ string yfangxiang = \ int x = 4; //X int y = 4; //Y public static int count = 3; // int bw = 0; // int bh = 0; // int qr = 0; // Point dispoint = new Point(999, 999); // public static int score = 0; // int _count = -1; int countB = 50;

ReturnDataBean rdb = new ReturnDataBean();

//控制球的移动timer事件

8

封装pictureBox对象 是否按下空格键 是否按下左右键 方向默认为右 方向默认为上 坐标移动方向 坐标移动方向 剩余机会 砖块宽度 砖块高度 球的直径

移动砖块到XY位置 得分 辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)

private void timer1_Tick(object sender, EventArgs e) {

_count = -1; //击中的哪一个砖块 if (countB == 0) {

keySpace = \ xfangxiang = \ yfangxiang = \

this.picNext.Location = new Point(12, 254); }

//右上

if (keySpace == \ {

this.TopRight(); }

//左下

else if (keySpace == \&& xfangxiang == \&& yfangxiang == \ {

this.TopLeft(); }

//左下

else if (keySpace == \&& xfangxiang == \&& yfangxiang == \ {

this.DownLeft(); }

//右下 else if (keySpace == \&& xfangxiang == \&& yfangxiang == \ {

this.DownRight(); }

//判断是否击中球

if (_count >= 0 && _count < 50) {

this.IsScore(_count); }

}

//按下键盘键发生事件

private void GameCol1_KeyDown(object sender, KeyEventArgs e) {

if (e.KeyCode == Keys.Left) {

9

辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)

key = e.KeyCode.ToString(); }

if (e.KeyCode == Keys.Right) {

key = e.KeyCode.ToString(); }

if (e.KeyCode == Keys.Space) {

keySpace = e.KeyCode.ToString(); } }

//释放键盘键发生事件

private void GameCol1_KeyUp(object sender, KeyEventArgs e) {

key = \ }

//单击退出键发生事件

private void lblClose_Click(object sender, EventArgs e) {

GameMain.isLoginGame = false; Program.bol = true; this.Close(); }

private void lblClose_MouseEnter(object sender, EventArgs e) {

this.lblClose.ForeColor = Color.Red; }

private void lblClose_MouseLeave(object sender, EventArgs e) {

this.lblClose.ForeColor = Color.Black; }

private void goFeichuan_Tick(object sender, EventArgs e) {

if (key == \ {

Point Fpoint = this.picFeichuan.Location; Point Qpoint = this.picQiu.Location;

if (this.picFeichuan.Location.X >= (this.picLeftborder.Location.X + 18)) {

Fpoint.X -= 10; if (keySpace == \ {

Qpoint.X -= 10;

10

辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)

} }

this.picFeichuan.Location = Fpoint; this.picQiu.Location = Qpoint; }

else if (key == \ {

Point Fpoint = this.picFeichuan.Location; Point Qpoint = this.picQiu.Location; if (this.picFeichuan.Location.X <= (this.picRightborder.Location.X - 97)) {

Fpoint.X += 10; if (keySpace == \ {

Qpoint.X += 10; } }

this.picFeichuan.Location = Fpoint; this.picQiu.Location = Qpoint; } }

3) 游戏结束代码

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;

using System.Windows.Forms; using System.IO;

namespace Arkanoid {

public partial class GameOver : Form {

public GameOver() {

InitializeComponent(); }

private void lblExit_Click(object sender, EventArgs e) {

Application.Exit();

11


打砖块游戏课程设计报告 - 图文.doc 将本文的Word文档下载到电脑
搜索更多关于: 打砖块游戏课程设计报告 - 图文 的文档
相关推荐
相关阅读