问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

vb6.0如何编写俄罗斯方块?

发布网友 发布时间:2022-05-04 11:29

我来回答

1个回答

热心网友 时间:2022-06-21 11:54

using System;
using System.Drawing;
using Microsoft.Win32;

namespace AnotherBlock
{
/// <summary>
/// Represents a Tetris game engine.
/// </summary>
public class Game
{
/// <summary>
/// Constant with the image width of the block unit (in pixels).
/// </summary>
public const int BlockImageWidth = 21;
/// <summary>
/// Constant with the image height of the block unit (in pixels).
/// </summary>
public const int BlockImageHeight = 21;
/// <summary>
/// Constant with the playing field width (in block units).
/// </summary>
public const int PlayingFieldWidth = 10;
/// <summary>
/// Constant with the playing field height (in block units).
/// </summary>
public const int PlayingFieldHeight = 20;
/// <summary>
/// Constante with the number of lines for each level.
/// </summary>
public const int LevelEveryLines = 12;

/// <summary>
/// Private attribute that holds the current game score.
/// </summary>
private int score = 0;
/// <summary>
/// Private attribute that holds the current game level.
/// </summary>
private short level = 1;
/// <summary>
/// Private attribute that holds the current number of completed lines.
/// </summary>
private int lines = 0;
/// <summary>
/// Private attribute that holds the current game state.
/// </summary>
private GameState gameState;
/// <summary>
/// Private attribute that holds the level where the game started.
/// </summary>
private short startLevel = 1;
/// <summary>
/// Private attribute that holds the current game pile.
/// </summary>
private Brick[,] pile = new Brick[(PlayingFieldWidth + 1), (PlayingFieldHeight + 1)];
/// <summary>
/// Private attribute that holds the current block.
/// </summary>
private Block currentBlock = new Block();
/// <summary>
/// Private attribute that holds the next block.
/// </summary>
private Block nextBlock = new Block();

/// <summary>
/// Class constructor that creates a game.
/// </summary>
public Game()
{
// Clears the game pile.
ClearPile();
}

/// <summary>
/// Class constructor that creates a game in a given level.
/// </summary>
/// <param name="level">The level where the game should start.</param>
public Game(short level)
{
// Sets the level attribute to the game level where the game should start.
this.level = level;
// Sets the startLevel attribute to the game level where the game should start.
startLevel = level;
// Clears the game pile.
ClearPile();
}

/// <summary>
/// Readonly property that holds the score of the current game.
/// </summary>
public int Score
{
get
{
// Returns the value in the score attribute.
return score;
}
}

/// <summary>
/// Readonly property that holds the level of the current game.
/// </summary>
public short Level
{
get
{
// Returns the value in the level attribute.
return level;
}
}

/// <summary>
/// Readonly property that holds the number of complete lines in the current game.
/// </summary>
public int Lines
{
get
{
// Returns the value in the lines attribute.
return lines;
}
}

/// <summary>
/// Property that holds and sets the current game state.
/// </summary>
/// <remarks>
/// The game state can be "Running", "Paused" or "Over".
/// </remarks>
public GameState GameState
{
get
{
// Returns the value in the gameState attribute.
return gameState;
}
set
{
// Checks if the current game state is "Over", and if the value to change is not "Over".
if ((gameState == GameState.Over) && (value != GameState.Over))
{
// The current game state is "Over", and it's changing to something else than "Over".
// Resets the score, level and lines.
score = 0;
level = startLevel;
lines = 0;
// Creates a new current block, and a new next block.
currentBlock = new Block();
nextBlock = new Block();
// Clears the game pile.
ClearPile();
}

// Sets the gameState attribute to the value.
gameState = value;
}
}

/// <summary>
/// Method that moves the current block down one position.
/// </summary>
/// <returns>True if there was a hit on the ground or on the pile, false if there wasn't.</returns>
public bool MoveCurrentBlockDown()
{
// Creates a "hit" flag, to check if the block has hit the pile or the ground.
bool hit = false;

// Increases the Top of the current block.
currentBlock.Top++;

// Checks if the current block has hit the ground.
// COLLISION DETECTION
if ((currentBlock.Top + currentBlock.Height) > PlayingFieldHeight)
{
// Current block has hit the ground.
// Sets the "hit" flag to "true".
hit = true;
}
else
{
// Checks if the current block has hit the pile.
// COLLISION DETECTION
for(int i = 0; i < currentBlock.Width; i++)
{
for(int j = 0; j < currentBlock.Height; j++)
{
int fx, fy;
fx = currentBlock.Left + i;
fy = currentBlock.Top + j;
if ((currentBlock.Shape[i, j].Filled == true) && (pile[fx, (fy + 1)].Filled == true))
{
// Current block has hit the pile.
// Sets the "hit" flag to "true".
hit = true;
}
}
}
}

// Checks if there was a hit.
if (hit)
{
// There was a hit.
// Puts the current block in the pile.
MoveBlockToPile();
// Checks if the current game state is not "Over".
if (this.GameState != GameState.Over)
{
// Current game state is not "Over".
// Creates a new block.
CreateNewBlock();
}
}

// Returns if there was a hit or not.
return hit;
}

/// <summary>
/// Method that moves the current block down until there is a hit.
/// </summary>
public void MoveCurrentBlockCompletelyDown()
{
// Moves the current block down until it has a hit.
while(!MoveCurrentBlockDown());
}

/// <summary>
/// Method that rotates the current block.
/// </summary>
/// <param name="clockwise">True if the block will be rotated clockwise, false if counterclockwise.</param>
public void RotateCurrentBlock(bool clockwise)
{
// Creates a "canRotate" flag, to check if the block can be rotated.
bool canRotate = true;

// Rotates the current block.
// This should be different. There should be an easy way to check FIRST if the block could
// be rotated, and then rotate it. I'll study this later.
currentBlock.Rotate(clockwise);

// Checks if the current block could be rotated.
// COLLISION DETECTION
for(int i = 0; i < currentBlock.Width; i++)
{
for(int j = 0; j < currentBlock.Height; j++)
{
int fx, fy;
fx = currentBlock.Left + i;
fy = (currentBlock.Top + 1) + j;
if ((currentBlock.Shape[i, j].Filled == true) && (pile[fx, fy].Filled == true))
{
// Current block can't be rotated.
// Sets the "canRotate" flag to "false".
canRotate = false;
}
}
}

// Checks if the block can't be rotated.
if (!canRotate)
{
// Block can't be rotated.
// Rotates the block back to its first position.
currentBlock.Rotate(!clockwise);
}
}

/// <summary>
/// Method that moves the current block to the right or to the left.
/// </summary>
/// <param name="left">True if the block will be moved to the left, false if to the right.</param>
public void MoveCurrentBlockSide(bool left)
{
// Creates a "canMove" flag, to check if the block can be moved to the sides.
bool canMove = true;

// Checks if the block is to be moved to the left.
if (left)
{
// The block is to be moved to the left.
// Checks if the block is not already at the most left of the playing field.
if (currentBlock.Left > 0)
{
// Block is not at the most left of the playing field.
// Checks if the current block can move to the left.
// COLLISION DETECTION
for(int i = 0; i < currentBlock.Width; i++)
{
for(int j = 0; j < currentBlock.Height; j++)
{
int fx, fy;
fx = currentBlock.Left + i;
fy = (currentBlock.Top + 1) + j;
if ((currentBlock.Shape[i, j].Filled == true) && (pile[(fx - 1), fy].Filled == true))
{
// Current block can't move to the left.
// Sets the "canMove" flag to "false".
canMove = false;
}
}
}

// Checks if the block can be moved to the left.
if (canMove)
{
// Block can be moved to the left.
// Moves the block to the left.
currentBlock.Left--;
}
}
}
else
{
// The block is not to be moved to the left (it is to be moved to the right).
// Checks if the block is not already at the most right of the playing field.
if ((currentBlock.Left + currentBlock.Width) < PlayingFieldWidth)
{
// Block is not at the most right of the playing field.
// Checks if the current block can move to the right.
// COLLISION DETECTION
for(int i = 0; i < currentBlock.Width; i++)
{
for(int j = 0; j < currentBlock.Height; j++)
{
int fx, fy;
fx = currentBlock.Left + i;
fy = (currentBlock.Top + 1) + j;
if ((currentBlock.Shape[i, j].Filled == true) && (pile[(fx + 1), fy].Filled == true))
{
// Current block can't move to the right.
// Sets the "canMove" flag to "false".
canMove = false;
}
}
}

// Checks if the block can be moved to the right.
if (canMove)
{
// Block can be moved to the right.
// Moves the block to the right.
currentBlock.Left++;
}
}
}
}

/// <summary>
/// Method that draws the pile in a surface.
/// </summary>
/// <param name="drawingSurface">The graphics surface where the pile will be drawn.</param>
public void DrawPile(Graphics drawingSurface)
{
// Runs through the playing field Width.
for (int i = 0; i < (PlayingFieldWidth + 1); i++)
{
// Runs through the playing field Height.
for (int j = 0; j < (PlayingFieldHeight + 1); j++)
{
// Checks if the current brick of the pile is set to be solid.
if (pile[i, j].Filled == true)
{
// Current brick of the pile is set to be solid.
// Creates a rectangle in the right position of this brick.
Rectangle rect = new Rectangle(i * BlockImageWidth, (j - 1) * BlockImageHeight, BlockImageWidth, BlockImageHeight);
// Draws the block image in the just created rectangle.
drawingSurface.DrawImage(pile[i, j].BrickImage, rect);
}
}
}
}

/// <summary>
/// Method that draws the current block in a surface.
/// </summary>
/// <param name="drawingSurface">The graphics surface where the current block will be drawn.</param>
public void DrawCurrentBlock(Graphics drawingSurface)
{
// Checks if there is a current block.
if (currentBlock != null)
{
// There is a current block.
// Draws the current block in the drawing surface.
currentBlock.Draw(drawingSurface);
}
}

/// <summary>
/// Method that draws the next block in a surface.
/// </summary>
/// <param name="drawingSurface">The graphics surface where the current block will be drawn.</param>
public void DrawNextBlock(Graphics drawingSurface)
{
// Checks if there is a next block.
if (nextBlock != null)
{
// There is a next block.
// Saves the current Left and Top properties of the next block.
short currentLeft = nextBlock.Left;
short currentTop = nextBlock.Top;

// Changes the current Left and Top properties of the next block, so they can be shown
// in the center of a drawing surface that has a size of 6x6 blocks.
nextBlock.Left = (short)((6 - nextBlock.Width) / 2);
nextBlock.Top = (short)((6 - nextBlock.Height) / 2);

// Draws the next block in the drawing surface.
nextBlock.Draw(drawingSurface);

// Retrieves the previously saved Left and Top properties, and put them back in the next block.
nextBlock.Left = currentLeft;
nextBlock.Top = currentTop;
}
}

/// <summary>
/// Private method that clears the current game pile.
/// </summary>
private void ClearPile()
{
// Runs through the playing field Width.
for(int i = 0; i < (PlayingFieldWidth + 1); i++)
{
// Runs through the playing field Height.
for(int j = 0; j < (PlayingFieldHeight + 1); j++)
{
// Clears the current brick of the pile.
pile[i, j].Filled = false;
}
}
}

/// <summary>
/// Private method that creates a new current block by getting it from the next block,
/// and creates a new random next block.
/// </summary>
private void CreateNewBlock()
{
// Checks if there is a next block.
if (this.nextBlock != null)
{
// There is a next block.
// Sets the current block to the next block.
currentBlock = nextBlock;
}
else
{
// There isn't a next block.
// Sets the current block as a new random block.
currentBlock = new Block();
}

// Sets the next block as a new random block.
nextBlock = new Block();
}

/// <summary>
/// Private method that moves the current block to the game pile.
/// While moving the block to the pile, it checks if there are complete lines, and count them, in
/// order to update the score, the lines and the level. It also checks for game over.
/// </summary>
private void MoveBlockToPile()
{
// Runs through the current block Width.
for(int i = 0; i < currentBlock.Width; i++)
{
// Runs through the current block Height.
for(int j = 0; j < currentBlock.Height; j++)
{
// Converts the current brick position the a playing field position.
int fx, fy;
fx = currentBlock.Left + i;
fy = currentBlock.Top + j;
// Checks if the current brick is solid.
if (currentBlock.Shape[i, j].Filled == true)
{
// The current brick is solid.
// Moves the current brick to the pile.
pile[fx, fy].Filled = true;
pile[fx, fy].BrickImage = currentBlock.Shape[i, j].BrickImage;
}
}
}

// Checks for complete lines.
CheckForLines();

// Checks for game over.
CheckForGameOver();
}

/// <summary>
/// Private method that checks the pile for complete lines.
/// </summary>
/// <returns>The number of found lines.</returns>
private int CheckForLines()
{
// Creates a variable that will hold the number of lines found.
int numLines = 0;
// Creates a variable that will hold the number of the complete lines found.
int[] completeLines = new int[PlayingFieldHeight];

// Runs through the playing field lines.
for (int j = PlayingFieldHeight; j > 0; j--)
{
// Checks if there is a complete line.
bool fullLine = true;

for (int i = 0; i < PlayingFieldWidth; i++)
{
if (pile[i, j].Filled == false)
{
fullLine = false;
break;
}
}

// Checks if there was a complete line.
if (fullLine)
{
// There was a complete line.
// Increases the number of complete lines found.
numLines++;
// Pauses the game so no block will come down while clearing the complete line.
this.GameState = GameState.Paused;
// Holds the number of the complete line found.
completeLines[numLines] = j;
// Sets the game state to "Running" again, to release the game.
this.GameState = GameState.Running;
}
}

// Checks if there were any complete lines.
if (numLines > 0)
{
// There were complete lines.
// Runs through all the complete lines, and clears them.
for(int i = 1; i <= numLines; i++)
{
// Clear a complete line.
ClearLine((completeLines[i] + (i - 1)));
}
// Updates the game score, lines and level.
score += 5 * (numLines * (numLines + 1));
lines += numLines;
level = (short)((lines / LevelEveryLines) + startLevel);
}

// Returns the number of complete lines.
return numLines;
}

/// <summary>
/// Private method that checks the pile for game over.
/// </summary>
private void CheckForGameOver()
{
// Checks if the top of the current block is on the top of the pile.
if (currentBlock.Top == 1)
{
// Current block is on the top the the pile.
// Sets the game state to "Over".
this.GameState = GameState.Over;
}
}

/// <summary>
/// Private method that clears a line from the pile.
/// </summary>
/// <param name="lineNumber">The number of the line to be cleared.</param>
private void ClearLine(int lineNumber)
{
// Runs through all the lines, from the line to be cleared up.
for (int j = lineNumber; j > 0; j--)
{
// Runs through all the bricks in one line.
for (int i = 0; i < PlayingFieldWidth; i++)
{
// Move the current brick down.
pile[i, j] = pile[i, (j - 1)];
}
}

// Runs through the top line bricks.
for (int i = 0; i < PlayingFieldWidth; i++)
{
// Sets the current brick to empty.
pile[i, 0].Filled = false;
}
}
}
}

这是其中之一最重要的部分,要全部代码给我发邮件
forstrongest@163.com

参考资料:http://zhidao.baidu.com/question/47934030.html

vb6.0如何编写俄罗斯方块?

VB 高手进。 2014-06-25 我想用VB6.0做一个小游戏(俄罗斯方块即可)。哪位高手能提... 2 2012-06-25 用VB设置俄罗斯方块,像下图这些方块是怎么产生的 1 2012-03-11 我要用vb写俄罗斯方块。求高手详细指导。附上操作和代码。(包... 1 2011-03-26 VB 俄罗斯方块设计程序代码 VB程序做的 俄罗斯方块...

aippt自动生成工具

随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图、条形...

用vb6.0编俄罗斯方块应该怎么写程序?谢

可以试想窗口X行Y列,的格子.几个格子拼成一定形状,一些判断,一个控制速度和向下运动的时钟.配套的积分 等级 什么的 就差不多了.呵呵,我有的时侯写小游戏还 加一些作弊模式也很有意思的 ---

怎么用vb制作俄罗斯方块游戏啊,简单点的。

3.当某一行的方块排列满时,将自动将这一行方块消除,然后将上面所有方块向下移动,可以支持连续消行。 4.游戏前可以选择游戏的速度和游戏的等级,游戏速度既为方块下落速度,游戏等级为初始游戏时在基层随机生成一定行数的无规律方块,生成的行数由你来选择,每行至少产生5个以上的无规律方块,这样增加了游戏难度,对于游...

谁能给我一个VB的,俄罗斯方块的程序??

var obj_start_left = 132; //方块起始位置 var obj_start_top = 0;var can_move_block = false; //设置用户是否可以移动方块 var can_play = false; //游戏的开始 var one_score = 10; //一个的得分 var block_score = 4*one_score //一个方块的得分 var line_score = 12*one_score //一行...

【救命!vb高人进】vb6.0中如何写障碍物的代码?

TO 2,0 TO 2) AS STRING,人在中间,用坐标表示(X=1,Y=1)要判断上下左右可以这样:左表示为A(X-1,Y),右表示为A(X+1,Y)上表示为A(X,Y-1),下表示为A(X,Y+1)判断则可以用 IF A(m,n)=“石头”THEN ’做什么 ENDIF IF A(m,n)=“箱子”THEN ‘做什么 END IF ...

我不懂电脑编程,想学VB6.0可以吗难吗,怎么学?

你学VB的目的是什么?如果要是打算从事编程这个行业的话建议你学C语言,如果只为了拿个计算机二级证书的话可以学学!不是很难!但是要记住一些规定的框架!还有一些相对应的函数!

游戏软件设计 高手进

书名:Visual Basic 6.0/.NET游戏开发实例作者:姜波 宁峰说明:本书是一本面向广大编程爱好者的游戏设计类图书。本书最大的特色在于以游戏开发案例为主要的内容。书中涉及到的游戏都是大家耳熟能详的。比如推箱子,俄罗斯方块,五子棋,坦克大战等。为了使您紧跟技术进步的潮流,我们还为您介绍了目前非常流行的智能设备...

写程序有什么用?

桌面应用的话,可以写一些小游戏:贪吃蛇、俄罗斯方块等,后缀名是.jar。企业应用的话,就是说公司里面用的一些管理软件,网站也可以,我记得好像校内网就是用java做的。手机游戏,这不说了吧?那些.exe文件应该是跟c有关的(c++、c#),我不是很清楚,但java写的一定不是.exe学编程,如果只是为了写一些小程序,可以直接...

初学电脑编程需要什么

2、选择一门编程语言 选择一门编程语言。虽然目前编程语言有600种左右,但是比较流行的编程语言只有几十种,所以尽量选择流行程度比较高的编程语言来入门编程。对于没有明确编程场景的初学者来说,尽量选择全场景编程语言,比如Java、Python、C#等就是不错的选择 3、数学基础 当然拥有初中阶段的数学基础也...

我要计算机毕业论文

VB007光盘信息管理系统VB+SQLVB008火车售票系统VB009计算机等级考试管理系统VB6.0+ACECSSVB010酒店客房管理VB+SQLVB011期刊信息管理系统VB+SQLVB012书店管理系统(vb+access)VB013图书借阅管理系统VB014合同管理系统VB015学生公寓管理系统VB016学生管理系统1(vb+sql)VB017医院门诊管理系统VB018银行设备管理(vb+sql)VB...

用vb编写俄罗斯方块 vb怎么做俄罗斯方块 vb俄罗斯方块 俄罗斯方块vb代码 vb俄罗斯方块程序设计 vb程序设计俄罗斯方块简单 vbs俄罗斯方块代码 vb小游戏俄罗斯方块 用vb编写贪吃蛇的教程
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
开心学国学不可不知的1000个国学常识基本信息 开心学国学的内容简介 开心学国学内容简介 我手腕上有伤疤,想纹身盖住,请问我纹什么图案能给自己带来好运,我是... 统计四条红线是什么时候提出的 四条红线是什么 电信天翼宽带密码是多少? 在男人眼中家务和事业哪个重要? 火影忍者173集背景音乐是什么? 火影忍者第173集的背景曲 成都青白江哪里可以打个人征信报告? 双向约瑟夫问题 等腰直角三角形用英语怎么说 The direction a hurricane&#39;s spiral mover is counterclockwise的补语 Everyone gets a turn,going counterclockwise left to right 谁能帮我从语法角度分析议一下这个句子 副词后缀有哪些? counterclockwise和anticlockwise有什么区别 anticlockwise和counterclockwise的区别? counterclockwise是什么意思 华夏smart信用卡好还是招商young卡好? 大学期间办张信用卡(如招行的YOUNG卡)有必要吗? 招行Young卡怎样 招商银行young卡质量怎么样啊 招行YOUNG卡怎么样? 关于动物救人的故事有哪些?急需五六个~~~ 画画作诗算不算生物多样性的间接价值 为什么大自然那么漂亮? 怎么用r语言进行生物多样性分析 地球是我们美丽的家园,各种各样的生物相互衣存,相互影响着。生物多样性对我们人类有哪些意义?根据你... 我写生物多样性与我的家作文600字 自然灾害飓风的英文介绍 adobe+acrobat+pro中怎样复制粘贴图片? 大家有谁知道这款软件是什么,可以拍短视频还可以变发色,最近快手很火的,但没人说是什么 uefi怎么ghostwin10 我穿了一个比较血腥的视频在快手上,结果就变成下图这样了,怎么办?可以弄回来吗? ghost的win10用的是uefi吗? 如何在uefi下安装ghost win10 快手上最近很火的一个滤镜软件是什么 ghost在uefi win10下怎么运行吗 win10ghost版支持uefi启动吗 win10gho版怎么装uefi 请问北京地区omega手表换电池需要多少钱 请问卡西欧手表换一块电池得花多少钱? 北京地区价格,谢谢! 有支持win10和UEFI的Ghost软件吗 手表没电了,要换电池,一般多少钱阿 guid+uefi模式下到底能不能装ghost系统? 这个手表换个电池要多少钱?今天在北京一个大商场换的,他说50或80的,我换了个50的,他说只能用一 一般手表 维修多少钱 体重大的人穿什么篮球鞋好 李宁有那个篮球鞋适合90公斤左右的人穿?