C++实实现现俄俄罗罗斯斯方方块块 ((linux版版本本))
本文实例为大家分享了C++实现俄罗斯方块的具体代码,供大家参考,具体内容如
主主程程序序
RussiaBlock.cpp
//
// Created by adl on 2020/7/18.
//
#include "Block.h"
#include "Table.h"
#include
#include
#include "hierarchical_mute .h"
#include "fstream"
using namespace std;
thread_local uint64_t
hierarchical_mute ::this_thread_hierarchical_value = ULONG_MAX;
int main(int argc, char **argv) {
int level = 1;
if (argc == 2) {
if ((level = atoi(argv[1])) == 0) {
cerr << "./a.out number " << endl;
e it(-1);
}
}
static int flag = 1;//全局变量
static Table tab(20, 20, level); //构造一个15,20的棋盘
static Block bl; //构造一个落 方块
hierarchical_mute table_mt (2);
hierarchical_mute mt (1);
thread getkey([&]() {
unsigned char buf[2];
struct termios saveterm, nt;
fd_set rfds, rs;
struct timeval tv;
int i = 0, q, r, fd = 0;//标准输入
tcgetattr(fd, &saveterm);
nt = saveterm;
nt.c_lflag &= ~ECHO;
nt.c_lflag &= ~ISIG;
nt.c_lflag &= ~ICANON;
tcsetattr(fd, TCSANOW, &nt);
FD_ZERO(&rs);
FD_SET(fd, &rs);
tv.tv_usec = 0;
tv.tv_sec = 0;
while (1) {
read(0, buf, 1);
buf[1] = '\0 ';
r = select(fd + 1, &rfds, nullptr, nullptr, &tv);
if (r < 0) {
write(fileno(stderr), "select error.\n", sizeof("select error.\n"));
}
rfds = rs;
std::unique_lock table_lock(table_mt );
//上 左右
switch (buf[0]) {
case 'A ': {
//旋转
tab.clr_block(bl);//
if (bl.get_type() == 5)continue;
bl.rotate();
if (tab.set_block(bl) == -1) {
bl.rotate_back();
tab.set_block(bl);
continue;
}
break;
}
case 'B': {
//向 (加速)
tab.clr_block(bl);
bl.mov