C++ 俄罗斯方块

俄罗斯方块,相信大家已经很熟悉了,这里我用C++复刻了一个,这是第二版,代码如下:

#include<iostream>
#include<Windows.h>
#include<ctime>
#include<conio.h>
#include<cstdlib>
#include<fstream>
#include<iomanip>

using namespace std;

#define lenth 20//方块所在屏幕 长 
#define height 30//方块所在屏幕 高 
int map[lenth][height];//方块所在屏幕 
#define pause 1.6//下落间距 单位为秒 
#define interval 0.2//帧间距 
#define center 1//旋转中心(0-3的整数)
int type;//0:■  1:■■  2:■■  3:■    4:  ■  5:■■  6:■    7:  ■
         //  ■      ■    ■      ■■    ■■    ■■    ■■    ■■
         //  ■      ■    ■        ■    ■              ■        ■
         //  ■                                                        
int Copy;//
clock_t t=clock(),ft=clock();//下落计时器 与 帧计算器 
char op;//用户输入 
struct pointer//被操纵的方块(其中一个) 
{
	int x;
	int y;
};
pointer p[4];//0:0  1:01  2:01  3:0   4: 0  5:01  6:0   7: 0
			 //  1     2    2     12    12    23    12    12
	         //  2     3    3      3    3           3      3
             //  3                                                        
int speed;//下落速率(以后要改 
int score;//分数(每消一行+100,以后要改) 
struct highscore//三次最高分 
{
	int store[3];
};
highscore hs;//最高分 
ifstream fin;//文件输入 
ofstream fout;//文件输出 
const char*file="history.dat";//历史记录文件名 
bool tip=false;//对准器是否开启 
pointer tips[4];//对准器本体 

inline bool judge_time();//判断时间 
inline void enter_frame();//进入帧 
inline char get_op();//获取用户操作 
inline void input_op();//输入 
inline bool judge_clear(int line);//检测一行是否占满 
inline void clear(int h);//消除一行 
inline bool judge_over();//判断是否封顶 
inline bool judge_touched(pointer A[]);//检测方块是否碰撞(以后要改) 
inline void stick();//固定方块 
inline void set_rand();//重置随机数种子 
inline void init();//初始化 
inline void set_type(int type);//定义方块形状 
inline void move(int a,pointer A[]);//(三向)移动方块 
inline void rotate();//旋转(以后要改) 
inline void draw_map(int a,pointer A[]);//绘制屏幕 
inline void clean_map(pointer A[]);//清除(上一次)屏幕 
inline void show();//显示所有内容 

inline void fill();//事空格( 
inline void show_menu(int mp);//显示菜单 
inline void menu();//菜单操作 
inline void eatline();//清空输入流(只是以防万一,可能没什么大用) 
inline void set_hs(int score);//判断及更新最高分 
inline void clean_hs();//清空最高分 
inline void tip_t();//翻转tip的值 
inline void tip_();//将对准器移至最低处 

int main()
{
	//clean_hs();
	//std::ios::sync_with_stdio(false);
	system("mode con cols=60 lines=40");//设置边框 
	init();//初始化 
	while(true)//主循环 
	{
		while(!judge_over())
		{
			if(kbhit())
				input_op();
			if(judge_time())
				enter_frame();
		}
		set_hs(score);
		cout<<"输入<r>重来\n输入<q>退出\n";
		while(true)//捕捉输入 
		{
			if(kbhit())
			{
				input_op();
				break;
			}
		}
		if(get_op()=='q'||get_op()=='Q')//退出 
			break;
		else if(get_op()=='r'||get_op()=='R')//再来一次 
			init();
	}
	return 0;
}

inline bool judge_time()
{
	float differ=(((float)clock()-t)/CLOCKS_PER_SEC);//移动时间差 
	float fd
  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值