c++写的俄罗斯方块源码

游戏控制:
enter键开始游戏
空格 键 暂停
剩下的就是地球人都知道的方向键

该游戏用c++和windows api在eclipse_cpp中编写,创建控制台程序即可
改程序在vc6.0,和eclipse_cpp中运行正常

写此程序职位练手,

欢迎大家测试交流 如发现程序问题请联系wangzhen_621@126.com

 

/*
 * Data.h
 *      Author: 王振 (吉林大学)
 *      wangzhen_621@126.com
 *  Created on: 2008-11-11
 *
 */
#ifndef DATA_H_
#define DATA_H_
/*
 * index:7行10列数组 每行对应一种方块类别。
 *       每行的前四列为x坐标,中间四列为y坐标
 *       第九列为方块类别代码,最后一列为该类型方块有几种变形
 *  用一个5*5的矩阵表示 7种类别方块 共19种变形
 */
#include<windows.h>

static const int KINDS=7;//方块种类数量
static const int COLS=10;//数据列数

//每种方块的代号
static const int TYPE1=1;
static const int TYPE2=2;
static const int TYPE3=3;
static const int TYPE4=4;
static const int TYPE5=5;
static const int TYPE6=6;
static const int TYPE7=7;

//变形的种类
static const int RTYPE1=1;
static const int RTYPE2=2;
static const int RTYPE3=4;

static int rTypeNext;
static int rTypeDown;

//初始化方块坐标及对应的类别和变形种类
static const int index[KINDS][COLS]={
  {0,1,0,1,0,0,-1,-1,TYPE1,RTYPE1},
  {-1,0,1,2,0,0,0,0,TYPE2,RTYPE2},
  {0,0,1,1,1,0,0,-1,TYPE3,RTYPE2},
  {0,0,1,1,-1,0,0,1,TYPE4,RTYPE2},
  {-1,0,0,1,0,0,1,0,TYPE5,RTYPE3},
  {-1,0,1,1,0,0,0,-1,TYPE6,RTYPE3},
  {-1,0,1,1,0,0,0,1,TYPE7,RTYPE3}
};

//定时器ID
static const int TIMER=1;
//
//初始游戏级别对应的时间间隔
static int CURRENTLEVEL=600;
static int level=1;

//每种图形所包含的小方块数
static const int CTN=4;

//方块形状定义
typedef struct {
 int x;
 int y;
}sCord;
sCord sDown[CTN],sNext[CTN];

//下一个方块的坐标
static RECT rectNext[CTN];
//正在下落方块的坐标
static RECT rectDown[CTN];

//显示区域的大小
static const int cxSize=25;
static const int cySize=35;

//方块偏离(0,0)得位置
static int offsetx;
static int offsety;

static int offsetxNext;
static int offsetyNext;

//自定义消息
static const int MS_DOWN=10001;
//暂停
static bool go=true;
//开始
static bool startGame=false;
//结束
static bool gameOver=false;
//得分
static int score;


RECT rt={326,81,425,455};

//每个方格包含的像素
static const int pelsSize=13;

//显示区域大小的定义
static const POINT area[]={0,455,326,455,326,0};
//显示区域的表示方法 最后一列最后一行分别对应该行该列所具有的方块总数 0表示没有方块1表示有
static int fillArea[cySize+1][cxSize+1];

HBRUSH hBrush1=CreateSolidBrush(RGB(0,0,0));//方块颜色
//HBRUSH hBrush1=CreateSolidBrush(RGB(240,250,100));//黄色
HBRUSH hBrush2=CreateSolidBrush(RGB(255,255,255));
HPEN hPen1=CreatePen(PS_SOLID,0,RGB(230,230,230));//背景格颜色
#endif /* DATA_H_ */

 

/*
 * MainPro.cpp
 *
 *  Created on: 2008-11-11
 *      Author: 王振 (吉林大学)
 *      wangzhen_621@126.com
 */

#include"Data.h"
#include<iostream>
#include<cstdlib>
using namespace std;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/*
 * 逆时针方向旋转方格 返回能否旋转
 * @param lpsCord 要旋转的方块坐标指针
 * @param rType  旋转类型
 * @param rNumber 旋转次数
 * @param 是否第一次旋转
 */
bool rotate(sCord *lpsCord,int rType,int rNumber,bool firstRotate);
void getRandom();//初始化方格形状
void getNext(sCord *targ,const sCord* sur);//取出下一个方块
void draw();//绘出方格
void start();//开始游戏
bool downAble();//能否下落
bool leftAble();//能否左移
bool rightAble();//能否右移
bool disRows(HWND hwnd);//判断能否消行

//int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
//
//     

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值