• 大小: 14KB
    文件类型: .gz
    金币: 2
    下载: 1 次
    发布日期: 2021-08-03
  • 语言: C/C++
  • 标签: linux  C语言  

资源简介

linux 下C语言俄罗斯方块代码 可以实现支持全部的方块类型,支持左右移动,图形的旋转变化,快速下降,分数统计,级别提升,暂停等功能

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include “print.h“
#include “rand.h“

pthread_mutex_t mutex_lock;
//pthread_mutex_t mutex_lock_run_pause;

/* seven kinds blocks image */
int rus_image[7][4][2]={
{{01}{11}{21}{31}}
{{00}{01}{11}{21}}
{{10}{01}{11}{21}}
{{20}{01}{11}{21}}
{{00}{10}{01}{11}}
{{00}{01}{11}{12}}
{{10}{01}{11}{02}}
};

/* I image */
int rus_image_i[4][4][2]={
{{01}{11}{21}{31}}
{{13}{12}{11}{10}}
{{01}{11}{21}{31}}
{{13}{12}{11}{10}}
};

/* J image */
int rus_image_j[4][4][2]={
{{00}{01}{11}{21}}
{{02}{12}{11}{10}}
{{21}{20}{10}{00}}
{{10}{00}{01}{02}}
};

/*T image */
int rus_image_t[4][4][2]={
{{10}{01}{11}{21}}
{{01}{12}{11}{10}}
{{11}{20}{10}{00}}
{{21}{10}{11}{12}}
};

/* L image */
int rus_image_l[4][4][2]={
{{20}{01}{11}{21}}
{{00}{10}{11}{12}}
{{01}{00}{10}{20}}
{{12}{02}{01}{00}}
};

/* O image */
int rus_image_o[4][4][2]={
{{00}{10}{01}{11}}
{{00}{10}{01}{11}}
{{00}{10}{01}{11}}
{{00}{10}{01}{11}}
};

/* Q image */
int rus_image_q[4][4][2]={
{{00}{01}{11}{12}}
{{01}{11}{10}{20}}
{{00}{01}{11}{12}}
{{01}{11}{10}{20}}
};

/* P image */
int rus_image_p[4][4][2]={
{{10}{01}{11}{02}}
{{00}{11}{10}{21}}
{{10}{01}{11}{02}}
{{00}{11}{10}{21}}
};

int rus_image_change_num=0;

enum RUS_IMAGE{
RUS_I=0
RUS_J
RUS_T
RUS_L
RUS_O
RUS_Q
RUS_P
};


int image_num;
int rus_block_x[4]={0};
int rus_block_y[4]={0};

int image_next_num;
int rus_block_next_x[4]={0};
int rus_block_next_y[4]={0};

int rus_block[12][22]={0};

int score=0;
int level=0;
int sleep_time[5]={500000 300000 200000 100000 50000};

int run_pause=0;

void rus_init();
void rus_print();
void rus_next_print();
void rus_clear();
int rus_move_down();
int rus_move_left();
int rus_move_right();
void rus_move_drop();
void rus_move_change();
void rus_run_pause();
int rus_block_change(int rus_image_tmp[4][4][2]);
int rus_block_stop();
void rus_line_clear();
void rus_line_delete(int n);
void rus_exit();
void *rus_pthread_listen_key(void *ptr);

/* rus praph init  */
void rus_init()
{
int ij;
int dytmp;

dy = 0;
tmp = 0;

/* rus block init */

for(i=0; i<12; i++){
for(j=0; j<22; j++){
rus_block[i][j] = -1;
}
}


/* print graph */
init_graph();
for(i=0; i<12; i++){
rus_block[i][0]=WHITE;
rus_block[i][21]=WHITE;
}
for(i=0; i<22; i++){
rus_block[0][i]=WHITE;
rus_block[11][i]=WHITE;
}


/* get a rus block and a next rus block */
srandNum();

image_num = randNum(0 6);
for(i=0; i<4; i++){
tmp = rus_image[image_num][i][1];
if(dy < tmp){
dy = tmp;
}
}
for(i=0; i<4; i++){
rus_block_x[i] = rus_image[image_num][i][0] + 5;
rus_block_

评论

共有 条评论