C语言游戏:俄罗斯方块

最近比较无聊,用C语言写了个俄罗斯方块,游戏效果如下:

游戏演示

代码如下,后续有时间再进行改进。。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <string.h>
#include <termios.h>
#include <pthread.h>

#define MAP_H 21    
#define MAP_L 10

#define FALL_SPEED 420000  //MICROSECOND
#define FASTER_SPEED 5000  //MICROSECOND
#define FLASH_TIME 130000

const char no_block = '.';
const char block_body = '#';
const char block_flash = '*';

int key;
int speed;
int block_type_count;
int over=0;
int next_block=0;
int point=0;
int has_bomb=0;
int block_attr_changing_flag=0;
char GameField[MAP_H][MAP_L];
static struct termios stored_settings;
pthread_t id;

typedef struct Block
{
    char block_form[4][4];
    int type;
    int x,y;
} s_Block;
s_Block Block;
s_Block Block_Next;

enum block_type
{
    Square=0,
    Strip=1,
    JShape,
    LShape,
    TShape,
    ZShape,
    SShape,
    Bomb,
};

void Initial();
void CreateBlock();
void ShowGame();
void PrintMap();
void CheckPoints();
void KeyDetectThread(void);
void GetButton();

void move_down();
void move_left();
void move_right();
void move_up();
void move_down_faster();

void FillBlockIntoMap();
void RmBlockFromMap();
int BlockCollide(s_Block *block);
void BlockRotate(s_Block *block);
void BlockExplode(int x,int y);

void set_keypress(void);
void reset_keypress(void);

int main(int argc, char *argv[])
{
    Initial();
    ShowGame();
    return 0;
}

void Initial()
{
    int ret;
    int key;

    memset(GameField, no_block, sizeof(GameField));
    set_keypress();
    speed = FALL_SPEED;
    point = 0;
    over = 0;
    has_bomb = 0;
    system("clear");
    printf("\nYou wanna get bomb block randomly? (y/n)\n ");
    key=getchar();
    if(key=='y')
    {
        block_type_count=8;
    }else
        block_type_count=7;
    system("clear");
    CreateBlock();
    Block = Block_Next;
    CreateBlock();
    PrintMap();
    getchar();
    GetButton();

    ret=pthread_create(&id,NULL,(void *)KeyDetectThread,NULL);
    if(ret)
    {
        printf("Create thread error!\n");
        sleep(2);
        exit(0);
    }
}


void CreateBlock()
{
    int b_type;

    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值