文档库 最新最全的文档下载
当前位置:文档库 › 俄罗斯方块源代码

俄罗斯方块源代码

俄罗斯方块源代码
俄罗斯方块源代码

1.

using System;

using System.Collections.Generic;

using System.Text;

using System.Drawing;//add

namespace俄罗斯方块

{

public class Block

{

private short width;

private short height;

private short top;

private short left;

private int ID; //方块部件的ID

public int[,] shape;//存储方块部件的形状,0为空白,1为有砖块

public Block()//构造函数

{

Random randomGenerator = new Random();

int randomBlock = randomGenerator.Next(1, 6);//产生1—4的数

this.ID = randomBlock;

switch (this.ID)

{

case 1: //横条形

this.Width = 4;

this.Height = 1;

this.Top = 0;

this.Left = 3;

shape = new int[this.Width, this.Height];

shape[0, 0] = 1; shape[1, 0] = 1;

shape[2, 0] = 1; shape[3, 0] = 1;

break;

case 2://正方形

this.Width = 2;

this.Height = 2;

this.Top = 0;

this.Left = 4;

// Creates the new shape for this block.

shape = new int[this.Width, this.Height];

shape[0, 0] = 1; shape[0, 1] = 1;

shape[1, 0] = 1;shape[1, 1] = 1;

break;

case 3://T形

this.Width = 3;

this.Height = 3;

this.Top = 0;

this.Left = 4;

// Creates the new shape for this block.

shape = new int[this.Width, this.Height];

shape[0, 0] = 1; shape[1, 0] = 1;

shape[2, 0] = 1; shape[1, 1] = 1;

shape[1, 2] = 1;

break;

case 4://L形

this.Width = 2;

this.Height = 3;

this.Top = 0;

this.Left = 4;

// Creates the new shape for this block.

shape = new int[this.Width, this.Height];

shape[0, 0] = 1; shape[0, 1] = 1;

shape[0, 2] = 1; shape[1, 2] = 1;

break;

case 5: //Z形

this.Width = 4;

this.Height = 2;

this.Top = 0;

this.Left = 4;

shape =new int[this.Width ,this.Height ];

shape[0,0] = 1;shape [1,0]=1;shape [2,0]=0;shape [3,0]=0;

shape[0,1] = 0;shape[1,1]=0;shape[2,1]=1;shape [3,1]=1;

break;

}

}

public short Width//Width属性

{

get

{

return width;

}

set

{

width = value;

}

}

public short Height//Height属性

{

get

{

return height;

}

set

{

height = value;

}

}

public short Top//Top属性

{

get

{

return top;

}

set

{

top = value;

}

}

public short Left//Left属性

{

get

{

return left;

}

set

{

left = value;

}

}

public void Draw(Graphics g)

{

Image brickImage = Image.FromFile("image/block0.gif");

for (int i = 0; i < this.Width; i++)

{

for (int j = 0; j < this.Height; j++)

{

if (this.shape[i, j] == 1)//黑色格子

{

//得到绘制这个格子的在游戏面板中的矩形区域

Rectangle rect = new Rectangle((this.Left + i) * Game.BlockImageWidth, (this.Top + j) * Game.BlockImageHeight, Game.BlockImageWidth, Game.BlockImageHeight);

g.DrawImage(brickImage, rect);

}

}

}

}

}//class Block

}

2. using System;

using System.Collections.Generic;

using https://www.wendangku.net/doc/28776281.html,ponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace俄罗斯方块

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

Game game=null;

private void button1_Click(object sender, EventArgs e)

{

game= new Game();

pictureBox1.Height = Game.BlockImageHeight * Game.PlayingFieldHeight + 3;

pictureBox1.Width = Game.BlockImageWidth * Game.PlayingFieldWidth+3;

pictureBox1.Invalidate();//重画游戏面板区域

timer1.Enabled = true;

button1.Enabled = false;

Music.PlaySong(@"E:\sound\molihua.mid");

}

private void button2_Click(object sender, EventArgs e)

{

if (button2.Text == "暂停游戏")

{

timer1.Enabled = false; button2.Text = "继续游戏";

}

else

{

timer1.Enabled = true; button2.Text = "暂停游戏";

}

}

private void button3_Click(object sender, EventArgs e)

{

this.Close();

}

private void pictureBox1_Paint(object sender, PaintEventArgs e)

{

//重画游戏面板

if (game != null)

{

game.DrawPile(e.Graphics);

game.DrawCurrentBlock(e.Graphics);

}

}

private void pictureBox2_Paint(object sender, PaintEventArgs e)

{

////重画下一个方块

if (game != null) game.DrawNextBlock(e.Graphics);

}

private void timer1_Tick(object sender, EventArgs e)

{

if (!game.DownCurrentBlock())

{

pictureBox1.Invalidate();//重画游戏面板区域

pictureBox2.Invalidate();//重画下一个方块

}

lblScore.Text = game.score.ToString();

if (game.over == true)

{

timer1.Enabled = false;

MessageBox.Show("游戏结束,", "提示");

button1.Enabled = true;

}

}

protected override bool ProcessCmdKey(ref Message msg, Keys e)

//重写ProcessCmdKey方法

{

if (button2.Text == "继续游戏") return true;//暂停时不响应键盘

if (e == Keys.Up || e == Keys.Down || e == Keys.Space ||e==Keys.Enter ||

e == Keys.Left || e == Keys.Right)

{

MyKeyPress(this, new KeyPressEventArgs((char)e));

}

return true;

}

//然后在MyKeyPress方法中处理

private void MyKeyPress(object sender, KeyPressEventArgs e)

{

switch (e.KeyChar)

{

case (char)Keys.Up:

game.RotateCurrentBlock();

break;

case (char)Keys.Down:

if (!game.DownCurrentBlock())

pictureBox1.Invalidate();//重画游戏面板区域

break;

case (char)Keys.Right:

game.MoveCurrentBlockSide(false);

break;

case (char)Keys.Left:

game.MoveCurrentBlockSide(true);

break;

case (char)Keys.Space:

button2.PerformClick();

break;

case(char)Keys.Enter :

button1.PerformClick();

break;

}

pictureBox1.Invalidate();

pictureBox2.Invalidate();

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{

timer1.Interval = 550 - Convert.ToInt16(comboBox1.Text) * 50;

}

private void pictureBox2_Click(object sender, EventArgs e)

{

}

}

}

3. using System;

using System.Collections.Generic;

using System.Text;

using System.Drawing;//add

namespace俄罗斯方块

{

class Game

{

public const int BlockImageWidth = 21;//方砖中每个小方格的大小

public const int BlockImageHeight = 21;

public const int PlayingFieldWidth = 10;//游戏面板大小

public const int PlayingFieldHeight = 20;

private int[,] pile; //存储在游戏面板中的所有方砖;

private Block currentBlock ;//当前的俄罗斯方块

private Block nextBlock ;//下一个的俄罗斯方块

public int score = 0, lines=0;

public bool over=false;//游戏是否结束

public Game()//Game类构造函数

{

pile = new int[PlayingFieldWidth , PlayingFieldHeight];

ClearPile();

CreateNewBlock();//产生新的俄罗斯方块

}

private void ClearPile()//清空游戏面板中的所有方砖

for (int i = 0; i < PlayingFieldWidth ; i++)

{

for (int j = 0; j < PlayingFieldHeight ; j++)

{

pile[i, j]= 0;

}

}

}

private void CreateNewBlock()//产生新的俄罗斯方块

{

if (this.nextBlock != null)

{

currentBlock = nextBlock;

}

else

{

currentBlock = new Block();

}

nextBlock = new Block();

}

public void DrawPile(Graphics g)

{

Image brickImage = Image.FromFile("image/block1.gif");//方砖的图形

for (int i = 0; i < PlayingFieldWidth ; i++)

{

for (int j = 0; j < PlayingFieldHeight ; j++)

{

if (pile[i, j] == 1)

{

Rectangle rect = new Rectangle(i * BlockImageWidth, j * BlockImageHeight, BlockImageWidth, BlockImageHeight);//(j - 1)

g.DrawImage(brickImage, rect);

}

}

}

}

public void DrawCurrentBlock(Graphics g)

{

if (currentBlock != null)//检查当前块是否为空

{

currentBlock.Draw(g);

}

}

public void DrawNextBlock(Graphics drawingSurface)

{

if (nextBlock != null)

{

short currentLeft = nextBlock.Left;

short currentTop = nextBlock.Top;

nextBlock.Left = (short)((6 - nextBlock.Width) / 2);

nextBlock.Top = (short)((6 - nextBlock.Height) / 2);

nextBlock.Draw(drawingSurface);

nextBlock.Left = currentLeft;

nextBlock.Top = currentTop;

}

}

private void MoveBlockToPile()//固定到游戏面板上

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] ==1)

{

pile[fx, fy] = 1;

}

}

}

CheckForLines();

if (CheckForGameOver())//检查游戏是否结束

over = true;

}

public bool DownCurrentBlock()

{

bool hit = false;

currentBlock.Top++;

if ((currentBlock.Top + currentBlock.Height) > PlayingFieldHeight)

{

hit = true;//当前块触游戏面板底

}

else//检查是否接触到下一行其他已落方块

{

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] == 1) && (pile[fx, fy] == 1))//(fy + 1)

{

hit = true;

}

}

}

}

if (hit)//触到其他已落方块或游戏面板底

{

currentBlock.Top--;

MoveBlockToPile();//固定到游戏面板上

CreateNewBlock(); //产生新的俄罗斯方块

}

return hit;

}

public void RotateCurrentBlock()//旋转方块

{

bool canRotate = true;

short newWidth = 0;

short newHeight = 0;

int[,] newShape;

newWidth = currentBlock.Height;

newHeight = currentBlock.Width;

newShape = new int[newWidth, newHeight];

int x,y;

if (((currentBlock.Left + newWidth) <= Game.PlayingFieldWidth)

&& ((currentBlock.Top + newHeight) < Game.PlayingFieldHeight))

{

for (int i = 0; i < currentBlock.Width; i++)

{

for (int j = 0; j < currentBlock.Height; j++)

{

x = ((currentBlock.Height - 1) - j);

y = i;

newShape[x, y] = currentBlock.shape[i, j];

if (newShape[x, y] == 1 && pile[x + currentBlock.Left, y + currentBlock.Top] == 1)

{

canRotate = false; return;//不能旋转}

}

}

}

if (canRotate)

{

currentBlock.Width = newWidth;

currentBlock.Height = newHeight;

currentBlock.shape = newShape;

}

}

}

public void MoveCurrentBlockSide(bool left)//左右移动

{

bool canMove = true;

if (left)//左移动

{

if (currentBlock.Left > 0)

{

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] == 1) && (pile[(fx - 1), fy] ==1))

{

canMove = false;

}

}

}

if (canMove)

{

currentBlock.Left--;

}

}

}

else//右移动

{

if ((currentBlock.Left + currentBlock.Width) < PlayingFieldWidth)

{

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] == 1) && (pile[(fx + 1), fy]==1))

{

canMove = false;

}

}

}

if (canMove)

{

currentBlock.Left++;

}

}

}

}

private int CheckForLines()//检查是否满行并消去

{

int numLines = 0;

int[] completeLines = new int[PlayingFieldHeight];

for (int j = PlayingFieldHeight-1; j > 0; j--)//j = PlayingFieldHeight

{

bool fullLine = true;

for (int i = 0; i < PlayingFieldWidth; i++)

{

if (pile[i, j] == 0)

{

fullLine = false;

break;

}

}

if (fullLine)

{

numLines++;

completeLines[numLines] = j;

}

}

if (numLines > 0)

{

for (int i = 1; i <= numLines; i++)

{

ClearLine((completeLines[i] + (i - 1)));

}

score += 5 * (numLines * (numLines + 1));

lines += numLines;

}

return numLines;

}

private void ClearLine(int lineNumber)

{

for (int j = lineNumber; j > 0; j--)

{

for (int i = 0; i < PlayingFieldWidth; i++)

{

pile[i, j] = pile[i, (j - 1)];

}

}

for (int i = 0; i < PlayingFieldWidth; i++)

{

pile[i, 0] = 0;

}

}

public bool CheckForGameOver()//检查游戏是否结束

{

if (currentBlock.Top == 0)

return true;

else

return false;

}

}

}

4. using System;

using System.Collections.Generic;

using System.Text;

using System.Media;

using System.Runtime.InteropServices;

namespace俄罗斯方块

{

class Music

{

[DllImport("winmm.dll")]

private static extern int mciSendString

(

string lpstrCommand,

string lpstrReturnString,

int uReturnLength,

int hwndCallback

);

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]

public static extern int GetShortPathName

(

[MarshalAs(UnmanagedType.LPTStr)] string path,

[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,

int shortPathLength

);

///

///背景音乐播放

///

///

public static void PlaySong(string FileName)

{

StringBuilder shortPathTemp = new StringBuilder(255);

int result = GetShortPathName(FileName, shortPathTemp, shortPathTemp.Capacity);

string ShortPath = shortPathTemp.ToString();

mciSendString("open " + ShortPath + " alias song", "", 0, 0);

mciSendString("play song ", "", 0,0);

mciSendString("play song repeat ", "", 0, 0);

}

private static SoundPlayer soundPlayer = new SoundPlayer();

}

}

5. using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace俄罗斯方块

{

static class Program

{

///

///应用程序的主入口点。

///

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

}

}

}

C语言俄罗斯方块游戏源代码

/*学无止境*/ #include #include #include #define ESC 27 #define UP 328 #define DOWN 336 #define LEFT 331 #define RIGHT 333 #define BLANK 32 #define BOTTOM 2 #define CANNOT 1 #define CAN 0 #define MAX 30 #define F1 315 #define ADD 43 #define EQUAL 61 #define DEC 45 #define SOUNDs 115 #define SOUNDS 83 #define PAUSEP 80 #define PAUSEp 112

void Init(); void Down(); void GoOn(); void ksdown(); void Display(int color); void Give(); int Touch(int x,int y,int dx,int dy); int GeyKey(); void Select(); void DetectFill(); void GetScores(); void Fail(); void Help(); void Quit(); void DrawBox(int x,int y,int Color); void OutTextXY(int x,int y,char *String); void DispScore(int x,int y,char Ch); void DrawNext(int Color); int Heng=12,Shu=20; /*横竖*/ int Position[MAX][MAX]; int middle[MAX][MAX]; int ActH,ActS;

C++俄罗斯方块代码(北邮版)

#include #include #include #include #include #include "colorConsole.h" //老师的文件 void begin(); //开始游戏 void frame(); //边框设定 int * getblocks(); //方块产生 void move(int line); //移动 void drawblocks(int line); //方块显示 void clearsquare(int line); //方块擦出 void turn(int line); //方块旋转 bool isavailable(int line); //判断是否能下落 void remember(int line); //记忆方块位置 void deleteline(int line); //方块满一行消除 bool ifgameover(); //判断是否游戏结束 void end(); //游戏结束 #define up 72 #define down 80 #define left 75 #define right 77 #define esc 27 HANDLE handle; int a1[4][4]={{1},{1,1,1}}; //七种方块的二维数组 int a2[4][4]={{0,1},{1,1,1}}; int a3[4][4]={{1,1},{0,1,1}}; int a4[4][4]={{0,0,1},{1,1,1}}; int a5[4][4]={{0,1,1},{1,1}}; int a6[4][4]={{1,1,1,1}}; int a7[4][4]={{1,1},{1,1}}; int row=0; //列数 int score=0; int level=0; int * block1=NULL; int * block2=NULL; int * block3=NULL; int coordinate[12][18]={0}; //坐标数组,边框12*18(最后一行,两边边框计算在内) int judge=0;

俄罗斯方块C语言代码

【转载】88行代码实现俄罗斯方块游戏(含讲解) 来源:https://www.wendangku.net/doc/28776281.html,/p/8 在正式阅读本文之前,请你记得你应该用娱乐的心态来看, 本代码所使用到的技巧,在工作了的人眼里会觉得很纠结,很蛋疼,很不可理喻,很丑, 注意,是你蛋疼,不关我的事 通常,写一个俄罗斯方块,往往动不动就几百行,甚至上千行,而这里只有88行 正所谓头脑风暴,打破常规。这里将使用很多不平常的手段来减少代码 以下是Win-TC可以成功编译并执行的代码(代码保证单行长度不超过80字符,如果你是Win7系统,那请看后文): 程序代码: #include"graphics.h" #include #include int gcW = 20, gcColor[] = {DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA,MAGENTA, YELLOW}; struct tetris { int _pool[16][32], (*pool)[32], tmap[8][4][16]; int x, y, s, st, t; }gt; void trsInit() { int sp[8][4] = {{15,4369},{23,785,116,547},{71,275,113,802}, {39,305,114,562},{54,561},{99,306},{51,51},{-1}}; int *p, i, j, b; for (p = sp[0]; *p >= 0; ++p) if ( *p == 0 ) *p = p[-2]; gt.pool = >._pool[4]; for (j = 0; j < 7; ++j) for (i = 0; i < 4; ++i) for (b = 0; b < 16; ++b) gt.tmap[j+1][i][b] = (sp[j][i] & 1) * (j + 1), sp[j][i] >>= 1; memset(gt._pool, -1, sizeof(gt._pool));

C语言课程设计俄罗斯方块源代码

1、新建“.h”头文件,将“头文件” 代码粘贴至其中, 2、新建“.c”源文件,将“源代码” 代码粘贴到其中。 3、新建空白工程,将头文件和源代码 添加进去,调试使用。 //头文件 //1.自定义枚举类型,定义7种形态的游戏方块 typedef enum tetris_shape { ZShape=0, SShape, LineShape, TShape, SquareShape, LShape, MirroredLShape }shape; //2.函数声明 //(1)操作方块函数 int maxX();//取得当前方块的最大x坐标 int minX();//取得当前方块的最小x坐标 void turn_left();//当前方块逆时针旋转90度 void turn_right(); int out_of_table(); void transform(); int leftable(); int rightable(); int downable(); void move_left(); void move_right(); //(2)操作游戏桌面的函数 int add_to_table();

void remove_full(); //(3)控制游戏函数 void new_game(); void run_game(); void next_shape(); int random(int seed); //(4)绘图函数 void paint(); void draw_table(); //(5)其他功能函数 void key_down(WPARAM wParam); void resize(); void initialize(); void finalize(); //(6)回调函数,用来处理Windows消息 LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM); //源代码 //1.文件包含 #include #include #include #include"tetris.h" //2.常量定义 #define APP_NAME "TETRIS" #define APP_TITLE "Tetris Game" #define GAMEOVER "GAME OVER" #define SHAPE_COUNT 7 #define BLOCK_COUNT 4 #define MAX_SPEED 5 #define COLUMS 10 #define ROWS 20 #define RED RGB(255,0,0)

C.C++语言-俄罗斯方块源码

注意:本源代码包含头文件,VC6.0请自行下载库文件包,解决没有库文件的问题 环境:WINDOWS7 VC6.0 程序清单:库文件MYFILE.H /****************************************************************************** ********************* File Name : MYFILE.H Copyright : Module Name : CPU : Intel i7 RTOS : Creat Date : 2017/1/13 Author : Yang Abstract Description: C++、C实用函数 ******************************************************************************* *********************/ #ifndef _MYFILE_ #define _MYFILE_ #include #include void introduce() { printf("欢迎使用!MYFILE.H\n"); } /*********************************C++常用类******************************/ template //栈 class STACK { private: int top; T_STACK stackspace[100]; public: STACK() { top =-1; } void PUSH(T_STACK x) {

俄罗斯方块源代码

1. using System; using System.Collections.Generic; using System.Text; using System.Drawing;//add namespace俄罗斯方块 { public class Block { private short width; private short height; private short top; private short left; private int ID; //方块部件的ID public int[,] shape;//存储方块部件的形状,0为空白,1为有砖块 public Block()//构造函数 { Random randomGenerator = new Random(); int randomBlock = randomGenerator.Next(1, 6);//产生1—4的数 this.ID = randomBlock; switch (this.ID) { case 1: //横条形 this.Width = 4; this.Height = 1; this.Top = 0; this.Left = 3; shape = new int[this.Width, this.Height]; shape[0, 0] = 1; shape[1, 0] = 1; shape[2, 0] = 1; shape[3, 0] = 1; break; case 2://正方形 this.Width = 2; this.Height = 2; this.Top = 0; this.Left = 4; // Creates the new shape for this block. shape = new int[this.Width, this.Height]; shape[0, 0] = 1; shape[0, 1] = 1; shape[1, 0] = 1;shape[1, 1] = 1; break; case 3://T形 this.Width = 3; this.Height = 3; this.Top = 0; this.Left = 4; // Creates the new shape for this block. shape = new int[this.Width, this.Height]; shape[0, 0] = 1; shape[1, 0] = 1; shape[2, 0] = 1; shape[1, 1] = 1; shape[1, 2] = 1; break; case 4://L形 this.Width = 2; this.Height = 3; this.Top = 0; this.Left = 4;

俄罗斯方块完整源代码

//不多说,直接可以拷贝下面的东西,就可以运行。 package day04; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.*; import https://www.wendangku.net/doc/28776281.html,ng.String.*; import https://www.wendangku.net/doc/28776281.html,ng.*; import java.io.*; public class ERSBlock extends JPanel implements ActionListener,KeyListener//应该是继承JPanel { static Button but[] = new Button[6]; static Button noStop = new Button("取消暂停"); static Label scoreLab = new Label("分数:"); static Label infoLab = new Label("提示:"); static Label speedLab = new Label("级数:"); static Label scoreTex = new Label("0"); static Label infoTex = new Label(" "); static Label speedTex = new Label("1");

static JFrame jf = new JFrame(); static MyTimer timer; static ImageIcon icon=new ImageIcon("resource/Block.jpg"); static JMenuBar mb = new JMenuBar(); static JMenu menu0 = new JMenu("游戏 "); static JMenu menu1 = new JMenu("帮助 "); static JMenuItem mi0 = new JMenuItem("新游戏"); static JMenuItem mi1 = new JMenuItem("退出"); static JMenuItem mi1_0 = new JMenuItem("关于"); static JDialog dlg_1; static JTextArea dlg_1_text = new JTextArea(); static int startSign= 0;//游戏开始标志 0 未开始 1 开始 2 暂停 static String butLab[] = {"开始游戏","重新开始","降低级数","提高级数","游戏暂停","退出游戏"}; static int game_body[][] = new int[19][10]; static int game_sign_x[] = new int[4];//用于记录4个方格的水平位置 static int game_sign_y[] = new int[4];//用于记录4个方格的垂直位置

俄罗斯方块C语言程序设计报告

C语言课程设计报告 俄罗斯方块程序设计报告 一、问题描述 俄罗斯方块(Tetris,俄文:Тетрис)是一款电视游戏机和掌上游戏机游戏,它由俄罗斯人阿列克谢·帕基特诺夫发明,故得此名。俄罗斯方块的基本规则是移动、旋转和摆放游戏自动输出的各种方块,使之排列成完整的一行或多行并且消除得分。 在本次设计中,要求支持键盘操作和若干种不同类型方块的旋转变换,并且界面上显示下一个方块的提示以及当前的玩家的得分,随着游戏的进行,等级越高,游戏难度越大,即方块的下落速度越快,相应的等级,等级越高,为玩家提供了不同的选择。 二、功能分析 I、俄罗斯方块游戏需要解决的问题包括: ⑴、随机产生方块并自动下移 ⑵、用Esc键退出游戏 ⑶、用键变体 ⑷、用键和键左右移动方块 ⑸、用空格键使游戏暂停

⑹、能正确判断满行并消行、计分、定级别 ⑺、设定游戏为不同级别,级别越高难度越大 II、俄罗斯方块游戏需要设计的功能函数包括: ⑴、声明俄罗斯方块的结构体 ⑵、函数原型声明 ⑶、制作游戏窗口 ⑷、制作俄罗斯方块 ⑸、判断是否可动 ⑹、随机产生俄罗斯方块类型的序号 ⑺、打印俄罗斯方块 ⑻、清除俄罗斯方块的痕迹 ⑼、判断是否满行并删除满行的俄罗斯方块 三、程序设计 1、程序总体结构设计 (1)、游戏方块预览功能。在游戏过程中,游戏界面右侧会有预览区。由于在此游戏中存在多种不同的游戏方块,所以在游戏方块预览区域中显示随机生成的游戏方块有利于游戏玩家控制游戏的策略。 (2)、游戏方块控制功能。通过各种条件的判断,实现对游戏方块的左移、右移、自由下落、旋转功能,以及行满消除行的功能。 (3)、游戏数据显示功能。在游戏玩家进行游戏过程中,需要按照一定的游戏规则给玩家计算游戏分数。例如,消除一行加100分,游戏分数达到一定数量

俄罗斯方块程序代码

//包含头文件 #include #include #include #include #include #include "Tetris.h" //int score=0; //int lever=1; //char scores[10]; //char levers[10]; /* enum cmd { round, //旋转方块 left, //左移方块 right, //右移方块 down, //下一方块 bottom, //方块沉底 quit //离开游戏 }; //定义绘制方块的状态的枚举类型 enum draw { show, //显示方块 hide //抹掉方块 }; //定义俄罗斯方块的结构体 struct block { int dir[4]; //方块的四个旋转的状态 int color; //方块的颜色 }*/ static T_TrsBlockStyle gz_tBlockStyleTab[7] = {/* 口口 口口口口口口口口口口 口口 口口*/ {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, /*

口口口口口口口口 口口口口口口口口 */ {0x0660, 0x0660, 0x0660, 0x0660, BLUE}, /* 口 口口口口口口口 口口口口口口口 口*/ {0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, /* 口 口口口口口口口 口口口口口口口 口*/ {0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, /* 口口 口口口口口口口口 口口口口口口 */ {0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, /* 口口 口口口口口口口口 口口口口口口 */ {0x0360, 0x4620, 0x0360, 0x4620, GREEN}, /* 口口口 口口口口口口口口口口 口口口 */ {0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; /* //定义俄罗斯方块的信息的结构体 struct blockinfo { int id; //7中方块中的哪一种 byte dir:2; //1种方块中四个方向中的哪个 char x,y; //方块的坐标(不是屏幕中的而是自己设置的游戏区域中的)} curblock,nextblock; */ // 定义游戏区 //unsigned char area[width][high] = {0}; //函数声明

C语言程序设计-俄罗斯方块源程序

其中的主要逻辑有: (1)由于c的随机性函数不好,所以每次游戏开始根据bios时间设置种子。 (2)得分越高,方块下降速度越快(每200分为单位)。 (3)每下落一个方块加1分,每消除一行加10分,两行加30分,三行加70分,四行加150分。初试分数为100分。 游戏控制: up-旋转;空格-下落到底;左右下方向键-控制方向。P-开始或暂停游戏。ESC-退出。 特点: (1)由于tc不支持中文,所以基本都是英文注释。 (2)函数命名尽可能规范的表达其内部处理目的和过程。 (3)代码加上注释仅有577行。(我下载过的两个俄罗斯方块代码一个在1087行,一个在993行,我的比它们代码少)。 (4)除了消除空格时算法比较复杂,其他算法都比较简单易读。 (5)绘图效率和局部代码效率扔有待提高。 (6)FrameTime参数可能依据不同硬件环境进行具体设置,InitGame需要正确的TC路径。 俄罗斯方块源于大约9年前上大一时的一个梦,我们在学习c语言时,我的同寝室友邀请我合作一起完成俄罗斯方块(课外作业性质),但是当时限于我们的水平比较菜和学习状态比较懒散,我们没有完成。大一的时候我在机房里无意发现别人留下的俄罗斯方块程序,运行,老师发现后激动的问我是我写的吗,我惭愧的摇摇头。那时看到别人做c的大程序深感羡慕(自己只是写几十行的程序)。数年后我仍然看到有不同样式的实现,但是我一直没有实现它,知道今天忽然有这个想法去做,算是弥补多年前的遗憾和心愿吧。 --------------------------------------------- Q&A: ---------------------------------------------- Q:我编译时出现错误:fatal error C1083: Cannot open include file: 'bios.h': Nosuch file or directory,该如何解决? A:正文中的代码,是使用Borland公司的TC2.0编译的,编译结果运行在Windows的16位虚拟机上。bi os.h是属于TC的头文件,在VC或者其他编译器中可能没有这个头文件。因此会产生这个错误。 解决办法: (1)可以下载附件中的压缩包,是使用VC6.0进行编译的版本,编译结果是Windows程序,运行在wind ows 32系统上。两者之间的算法完全一致,区别仅仅是绘图时采用的接口不同,TC下采用BGI(进入图形模式),VC下采用的是GDI(使用DC进行绘图)。 (2)下载TC2.0进行编译。 Q:使用TC3.0进行编译时,提示未能初始化图形模式,请使用initgraph函数。 A:这是因为TC3.0的BGI文件的路径和TC2.0有所不同。TC2.0的BGI文件位于TC路径下。而TC3.0的BGI文件位于BGI文件夹中。请把initgame函数中的initgraph函数中的第三个参数设置为正确的路径。例如:initgraph(&..,&..,"C:\\TC\\BGI"); Q:编译后运行时,弹出错误对话框报告16位虚拟机遇到不可执行的指令,点击确定后退出。 A:该问题在某些环境中出现,可能是基于软件或者硬件环境造成,具体原因暂时未知。为避免该问题,请加载附件中的压缩包VC6.0版本。

JAVA俄罗斯方块源代码

不多说,,直接可以拷贝下面的东西,然后记得把那个BLOCK的名字改成你自己的类名,这个很关键哦,不然是错的可别怪我,呵呵~~ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.*; import https://www.wendangku.net/doc/28776281.html,ng.String.*; import https://www.wendangku.net/doc/28776281.html,ng.*; import java.io.*; public class Block extends JPanel implements ActionListener,KeyListener//应该是继承JPanel { static Button but[] = new Button[6]; static Button noStop = new Button("取消暂停"); static Label scoreLab = new Label("分数:"); static Label infoLab = new Label("提示:"); static Label speedLab = new Label("级数:"); static Label scoreTex = new Label("0"); static Label infoTex = new Label(" "); static Label speedTex = new Label("1"); static JFrame jf = new JFrame(); static MyTimer timer; static ImageIcon icon=new ImageIcon("resource/Block.jpg"); static JMenuBar mb = new JMenuBar(); static JMenu menu0 = new JMenu("游戏 "); static JMenu menu1 = new JMenu("帮助 "); static JMenuItem mi0 = new JMenuItem("新游戏"); static JMenuItem mi1 = new JMenuItem("退出"); static JMenuItem mi1_0 = new JMenuItem("关于"); static JDialog dlg_1; static JTextArea dlg_1_text = new JTextArea(); static int startSign = 0;//游戏开始标志 0 未开始 1 开始 2 暂停 static String butLab[] = {"开始游戏","重新开始","降低级数","提高级数","游戏暂停","退出游戏"}; static int game_body[][] = new int[19][10]; static int game_sign_x[] = new int[4];//用于记录4个方格的水平位置 static int game_sign_y[] = new int[4];//用于记录4个方格的垂直位置 static boolean downSign = false;//是否落下 static int blockNumber = 1;//砖块的编号 static int gameScore = 0;//游戏分数 static int speedMark = 1;

C语言俄罗斯方块游戏源代码

/*学无止境*/ #include <> #include <> #include <> #define ESC 27 #define UP 328 #define DOWN 336 #define LEFT 331 #define RIGHT 333 #define BLANK 32 #define BOTTOM 2 #define CANNOT 1 #define CAN 0 #define MAX 30 #define F1 315 #define ADD 43 #define EQUAL 61 #define DEC 45 #define SOUNDs 115 #define SOUNDS 83 #define PAUSEP 80 #define PAUSEp 112

void Init(); void Down(); void GoOn(); void ksdown(); void Display(int color); void Give(); int Touch(int x,int y,int dx,int dy); int GeyKey(); void Select(); void DetectFill(); void GetScores(); void Fail(); void Help(); void Quit(); void DrawBox(int x,int y,int Color); void OutTextXY(int x,int y,char *String); void DispScore(int x,int y,char Ch); void DrawNext(int Color); int Heng=12,Shu=20; /*横竖*/ int Position[MAX][MAX]; int middle[MAX][MAX]; int ActH,ActS;

Java小游戏俄罗斯方块附完整源代码_毕业设计

**** 届毕业设计Java小游戏俄罗斯方块

┊┊┊┊┊┊┊┊┊┊┊┊┊装┊┊┊┊┊订┊┊┊┊┊线┊┊┊┊┊┊┊┊┊┊┊┊┊ 摘要 在现今电子信息高速发展的时代,电子游戏已经深入人们的日常生活,成为老少皆宜的娱乐方式。但是游戏设计结合了日新月异的技术,在一个产品中整合了复杂的设计、艺术、声音和软件,所以并不是人人皆知。直到今天,在中国从事游戏设计的人仍然很少,但是游戏行业的发展之快,远超如家电、汽车等传统行业,也正因为如此,游戏人才的教育、培养远落后于产业的发展。 俄罗斯方块是个老幼皆宜的小游戏,它实现由四块正方形的色块组成,然后存储在一个数组的四个元素中,计算机随机产生不同七种类型的方块,根据计算机时钟控制它在一定的时间不停的产生,用户根据键盘的四个方向键控制翻转、向左、向右和向下操作,(控制键的实现是由键盘的方向键的事件处理实现)。然后程序根据这七种方块堆叠成各种不同的模型。 论文描述了游戏的历史,开发此游戏的环境,游戏开发的意义。遵循软件工程的知识,从软件问题定义开始,接着进行可行性研究、需求分析、概要设计、详细设计,最后对软件进行了测试,整个开发过程贯穿软件工程的知识体系。 此次设计在Microsoft Windows 7系统下,以Java为开发语言,在eclipse开发平台上进行游戏的设计与实践。从游戏的基本玩法出发,主要就是俄罗斯方块的形状和旋转,我在设计中在一个图片框中构造了一些的网状小块,由这些小块组合成新的形状,每四个小块连接在一起就可以构造出一种造型,因此我总共设计了7中造型,每种造型又可以通过旋转而变化出2到4种形状,利用随机函数在一个欲览窗体中提前展示形状供用户参考,在游戏窗体中用户就可以使用键盘的方向键来控制方块的运动,然后利用递归语句对每一行进行判断,如果有某行的方块是满的,则消除这行的方块,并且使上面的方块自由下落,最后就可以得出用户的分数。 关键词:游戏设计,算法,数组,事件

俄罗斯方块游戏的开发需求分析

俄罗斯方块游戏的开发 组长:XXX 组员:XXX XXX XXX XXX 05软件工程一班 一、课程设计的目的和意义 俄罗斯方块游戏是一个经典的小游戏,由于它简单有趣,因而得到了广泛的流行,男女老幼都适合。而俄罗斯方块游戏的设计工作复杂且富有挑战性,它包含的内容多,涉及的知识广泛,与图形界面联系较大,包括界面的显示与更新、数据收集等,在设计的过程中,必将运用到各方面的知识,这对于visualbasi语 言设计者而言,是个很好的锻炼机会。 二、系统功能设计 本系统主要设计以下几种功能 1、游戏难度选择功能 游戏难度选择界面设置在程序运行开始时,一共有九种难度供玩家选择,每选一级难度,都会相应地显示出代表该难度的图片。开始时不设置任何默认的难度,如果玩家不选难度直接按“Enter”进入,将会弹出提示框,提示其先选难度再 进入。 2、方块下落、变形功能 在整个俄罗斯方块游戏中,方块的设计是核心。这里设计了一个方块类:Square( ),用来生成方块以及实现块的左移、右移、向下、变形、重画、同步显 示、初始化新块等。 3、自动升级功能 当分数累积到一定大小时,系统将自动为玩家提高难度。这里设置了每消除10行方块,就增加一级难度。当难度增加的时候,方块会相应地改变颜色,以作为 对玩家的提示。 4、游戏音乐功能 游戏开始音乐就自动播放,游戏暂停与结束时音乐相应消除。 5、获取帮助功能 这里设置了一个类,用来显示帮助,按F1键就能弹出窗口,显示游戏规则。

三、系统功能设计分析 俄罗斯方块游戏根据功能的不同,设置了如下12个类:Square, Command, GameArea, GameSetting, GameOver, Help, ImagePanel, JieMian, MyPanel, MyTimer, PlayMidi, WinListener,每个类的描述如下: 1、Square,方块类。这个类中定义了生成方块的方法,用二维数组int[][] pattern,存放7种方块的四种状态。在构造方法中以随机的形式生成方块,同时提供了以下几种方法:reset( ),leftTurn( ),leftMove( ),rightMove( ),fallDown( ),assertValid(int t,int s,int row,int col),dispBlock(int s)。分别实现方块的重画、翻转、 左移、右移、下落、同步显示等功能。 2、Command,处理控制类。这是一个实现ActionListener接口的类,主要处理 点击按钮事件。类中定义了三个int型变量:button_play,button_quit,button_pause,和一个boolean型的变量:pause_resume,并赋值。在GameArea 类中通过事件响应,在按钮执行方法中调用其值,使用switch语句,根据不同 按钮不同的值,来响应不同的事件。 3、GameArea,游戏界面类。GameArea继承了JFrame,是俄罗斯方块的主要游 戏界面。这个类定义了GameSetting类的gameScr对象和ImagePanel类的imagepanel对象作为游戏区域面板和控制区域面板。在游戏区域,主要是根据相应格子的设置标志来显示相应的图形图片,这样就实现了俄罗斯方块的实时显 示。 4、GameSetting, 游戏画布类。这个类生成的对象将作为游戏界面的方块下落区域,画布的设置为15行10列,当中的方格边长为30,类中还定义了一个二维数组int [][] scrArr作为屏幕数组,表示每一个方格。游戏区域中每一个方格是否存在游戏方块是由该方格的值来决定的,如果该方格的值为1,则表示该方格中存在游戏方块;如果该方格中的值为0,则表示该方格中不存在游戏方块,因此二维数组用于记录游戏区域中每个小方格的值。此外,类中还定义了画方块的方法,根据不同的难度画出不同颜色的方块。单击Play按钮时,系统调用initScr( )方法,初始化屏幕,将屏幕数组清零。当满足满行删除的条件时,系统调用deleteFullLine( )方法,进行删行加分,而且每删除十行,难度自动增加一级,方块颜色改变,并在难度显示框中相应显示。 5、GameOver,游戏结束弹出提示框类。当游戏结束时,系统弹出提示,包括玩 家分数以及询问玩家要继续游戏还是退出。 6、Help,帮助类。在游戏界面,按F1键,弹出提示窗口,获取帮助。 7、ImagePanel,背景图片类。这个类继承了JPanel类,用来作为游戏界面中控 制区域的容器,并添加图片。 8、JieMian,主界面类。这个类继承了JPanel类,作为游戏的第一个界面,也是难度选择界面。定义了9个单选按钮,当玩家未选任何难度就按Enter时,系统会弹出一个提示框,提示玩家先选难度再进入。 9、MyPanel,重写MyPanel类,使Panel的四周留空间。

俄罗斯方块C语言代码

#include #include #include #include #include #ifdef__cplusplus #define __CPPARGS ... #else #define __CPPARGS #endif #define MINBOXSIZE 15 /* 最小方块的尺寸*/ #define BGCOLOR 7 /* 背景着色*/ #define GX 200 #define GY 10 #define SJNUM 10000 /* 每当玩家打到一万分等级加一级*/ /* 按键码*/ #define VK_LEFT 0x4b00 #define VK_RIGHT 0x4d00 #define VK_DOWN 0x5000 #define VK_UP 0x4800 #define VK_HOME 0x4700 #define VK_END 0x4f00 #define VK_SPACE 0x3920 #define VK_ESC 0x011b #define VK_ENTER 0x1c0d /* 定义俄罗斯方块的方向(我定义他为4种)*/ #define F_DONG 0 #define F_NAN 1 #define F_XI 2 #define F_BEI 3 #define NEXTCOL 20 /* 要出的下一个方块的纵坐标*/ #define NEXTROW 12 /* 要出的下一个方块的横从标*/ #define MAXROW 14 /* 游戏屏幕大小*/ #define MAXCOL 20 #define SCCOL 100 /*游戏屏幕大显示器上的相对位置*/ #define SCROW 60 int gril[22][16]; /* 游戏屏幕坐标*/

俄罗斯方块代码

using System; using System.Collections.Generic; using System.Text; using System.Drawing;//add namespace俄罗斯方块 { class Game { public const int BlockImageWidth = 21;//方砖中每个小方格的大小 public const int BlockImageHeight = 21; public const int PlayingFieldWidth = 10;//游戏面板大小 public const int PlayingFieldHeight = 20; private int[,] pile; //存储在游戏面板中的所有方砖; private Block currentBlock ;//当前的俄罗斯方块 private Block nextBlock ;//下一个的俄罗斯方块 public int score = 0, lines=0; public bool over=false;//游戏是否结束 public Game()//Game类构造函数 { pile = new int[PlayingFieldWidth , PlayingFieldHeight]; ClearPile();

CreateNewBlock();//产生新的俄罗斯方块 } private void ClearPile()//清空游戏面板中的所有方砖{ for (int i = 0; i < PlayingFieldWidth ; i++) { for (int j = 0; j < PlayingFieldHeight ; j++) { pile[i, j]= 0; } } } private void CreateNewBlock()//产生新的俄罗斯方块{ if (this.nextBlock != null) { currentBlock = nextBlock; } else { currentBlock = new Block(); }

俄罗斯方块源程序

//这是一个Windows程序,简单的俄罗斯方块程序。最下面附有截图 //这是一个Win32 Application程序 // ToyBricks.cpp : Defines the entry point for the application. // #include "stdafx.h" #include #include #include #define CELL 15 // 【方格】的边长(pix) #define W 22 // 游戏区宽(22个【方格】边长) #define H 30 // 游戏区高(30个【方格】边长) #define MS_NEWBLOCK WM_USER+1 // 消息ID,产生新的【方块】 #define MS_DRAW WM_USER+2 LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);/*窗口过程处理*/ int WINAPI WinMain ( HINSTANCE hInstance, //当前实例句柄 HINSTANCE hPrevInstance, //前一实例句柄 PSTR szCmdLine, //指向程序命令行参数的指针 int iCmdShow) //应用程序开始执行窗口时显示方式用int类型标志 { static char AppName[]="ToyBrick";//定义一个静态字符数组保存字符串"ToyBrick"(机应用程序名) HWND hwnd; //定义一个窗口句柄 MSG msg; //定义一消息结构体变量 WNDCLASSEX wndclass; //定义一窗口类结构变量,包含窗口类全部信息 int iScreenWide; //定义屏幕显示宽度 wndclass.cbSize=sizeof(wndclass); //窗口类对象大小 wndclass.style=CS_HREDRAW|CS_VREDRAW; //窗口类对象风格 wndclass.lpfnWndProc=WndProc; //窗口处理函数为WndProc wndclass.cbClsExtra=0; //窗口类无扩展 wndclass.cbWndExtra=0; //窗口类实例没有扩展 wndclass.hInstance =hInstance; //当前实例句柄 wndclass.hIcon=LoadIcon(NULL, IDI_APPLICATION);//窗口最小化图标为默认图标 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);//窗口当前光标为箭头光标 wndclass.hbrBackground=(HBRUSH)GetStockObject (BLACK_BRUSH);//获得当前背景设置为黑色 wndclass.lpszMenuName=NULL; //窗体菜单名为空

相关文档
相关文档 最新文档