linux俄罗斯方块源程序,C++实现俄罗斯方块(linux版本).pdf

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值