linux环境纯命令行俄罗斯方块C语言版

这个博客介绍了一种在Linux环境下使用C语言编写的纯命令行版俄罗斯方块游戏。游戏代码中包含了各种形状定义、方向切换、移动、下降等功能,并使用多线程定时器控制游戏速度。玩家可以通过键盘输入控制方块移动和旋转,当一行被填满时会自动消除并计分。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <pthread.h>
#include <signal.h>
#include <math.h>

enum {
	S_VERTICAL,		
	S_HORIZON,		
	S_SQUARE,		
	S_THUNDER_1,	
	S_THUNDER_2,	
	S_THUNDER_3,	
	S_THUNDER_4,	
	S_EL_1,			
	S_EL_2,			
	S_EL_3,			
	S_EL_4,			
	S_EL_5,			
	S_EL_6,			
	S_EL_7,			
	S_EL_8,			
	S_TBRANCH_1,	
	S_TBRANCH_2,	
	S_TBRANCH_3,	
	S_TBRANCH_4,	
};

enum {
	LEFT,
	RIGHT,
	DOWN,
	UP
};

typedef struct point {
	int x;
	int y;
}point;

struct shape {
	int type;
	point point[4];
	int sid;
};

struct shape smap[] = {
	{0,0,0,1,0,2,0,3,0,0},
	{1,0,3,0,2,0,1,0,0,0},
	{2,0,0,0,1,1,0,1,1,0},
	{3,0,1,1,0,1,1,2,0,0},
	{4,2,2,1,1,2,1,1,0,0},
	{5,0,0,1,0,1,1,2,1,0},
	{6,1,2,1,1,2,1,2,0,0},
	{7,1,2,2,0,2,1,2,2,0},
	{8,2,1,0,0,1,0,2,0,0},
	{9,2,0,1,2,1,1,1,0,0},
	{10,0,0,2,1,1,1,0,1,0},
	{11,1,0,2,0,2,1,2,2,0},
	{12,0,1,0,0,1,0,2,0,0},
	{13,2,2,1,2,1,1,1,0,0},
	{14,2,0,2,1,1,1,0,1,0},
	{15,1,1,2,0,2,1,2,2,0},
	{16,1,1,0,0,1,0,2,0,0},
	{17,1,1,0,2,0,1,0,0,0},
	{18,1,0,2,1,1,1,0,1,0}

};	
		
int bitmap[20][10];
pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER;
struct shape curshape, nextshape;
int g_id = 1;
int score = 0;
int level = 1;
int linestat[20] = {0};
int leftedge = 0, rightedge = 0, bottom = 0;;
long long lasttime = 0;
int state;
int nexts;
struct termios new_setting,init_setting;

void clear_full_line();

int next_shape(int curs)
{
	switch (curs) {
		case S_HORIZON:
		case S_THUNDER_2:
		case S_THUNDER_4:
			return curs - 1;
		case S_EL_4:
		case S_EL_8:
		case S_TBRANCH_4:
			return curs - 3;
		case S_SQUARE:
			return curs;
		default:
			return curs + 1;
	}
}

void draw_bitmap()
{
	int i, j, k;

	printf("\033[2J");	
	
	int news[4][4] = {0};
	for (i = 0; i < 4; i++) {
		news[smap[nexts].point[i].x][smap[nexts].point[i].y] = 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值