资源简介
不到500行的代码实现俄罗斯方块,请在linux环境下,先执行make,然后./test运行

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include “block.h“
//init for globle
void
init_for_globle(void)
{
x = X / 2 - 2; // the first diamond appear postion
flag_erase = 1;
srand(getpid()); //srand
num = rand() % 7; // random appear first diamond
mode = rand() % 4; // random appear first diamond mode
color = rand() % 7 + 41; // random first diamond color
next_num = rand() % 7;
next_mode = rand() % 4;
save_color = rand() % 7 + 41;
print_start_interface(); // print game start interface
print_score(); // print init score 0
print_level(); // print init level 1
}
//print start interface
void
print_start_interface(void)
{
int x y;
printf(“\33[2J“);
printf(“\33[%d;%dH\33[32m分数:\33[0m“ p_y + 10 p_x + 25);
printf(“\33[%d;%dH\33[32m等级:\33[0m“ p_y + 14 p_x + 25);
for (x = p_x y = p_y; x <= 46; x++)
printf(“\33[%d;%dH\33[41m==\33[0m“ y x);
for (x = p_x y = p_y + 1; y <= 25; y++)
printf(“\33[%d;%dH\33[41m||\33[0m“ y x);
for (x = p_x + 22 y = p_y + 1; y <= 25; y++)
printf(“\33[%d;%dH\33[41m||\33[0m“ y x);
for (x = p_x + 36 y = p_y + 1; y <= 25; y++)
printf(“\33[%d;%dH\33[41m||\33[0m“ y x);
for (x = p_x + 24 y = p_y + 8; x <= 44; x++)
printf(“\33[%d;%dH\33[41m--\33[0m“ y x);
for (x = p_x y = p_y + 21; x <= 46; x++)
printf(“\33[%d;%dH\33[41m==\33[0m“ y x);
printf(“\33[?25l“);
fflush(stdout);
}
//erase last diamonds
void
erase_last(void)
{
int j x1 y1 n;
x1 = save_x + p_x + 2;
for (j = 0 n = 0; j < 16; j++) {
if (j / 4 >= shape[num][save_mode][16] && j % 4 == 0) {
y1 = save_y + p_y + 1 + n;
printf(“\33[%d;%dH“ y1 x1);
n++;
}
if (j / 4 >= shape[num][save_mode][16]
&& j % 4 >= shape[num][save_mode][17]) {
if (shape[num][save_mode][j] == 0) {
printf(“\33[2C“);
}
if (shape[num][save_mode][j] == 1) {
printf(“ “);
}
}
}
fflush(stdout);
}
//print modes shape
void
print_mode_shape(void)
{
int j x1 y1 n;
int left_flag = 0;
if (flag_erase == 0) {
erase_last();
}
x1 = x + p_x + 2;
for (j = 0 n = 0; j < 16; j++) {
if (j / 4 >= shape[num][mode][16] && j % 4 == 0) {
y1 = y + p_y + 1 + n;
printf(“\33[%d;%dH“ y1 x1);
n++;
}
if (j / 4 >= shape[num][mode][16]
&& j % 4 >= shape[num][mode][17]) {
if (shape[num][mode][j] == 0) {
printf(“\33[2C“);
}
if (shape[num][mode][j] == 1) {
printf(“\33[%dm[]\33[0m“ color);
}
}
fflush(stdout);
}
printf(“\33[0m“);
fflush(stdout);
save_x = x;
save_y = y;
save_mode = mode;
save_row = 4 - shape[num][mode][16];
save_col = 4 - shape[num][mode][17];
flag_erase = 0;
}
//store diamonds to matrix by color to flag
void
store_flag_color(void)
{
int i a = 0 b = 0;
for (i = 0; i < 16; i++) {
if (i / 4 >= shape[num][mode][16] && i % 4 == 0) {
a++;
b = 0;
}
if (i / 4 >= shape[num][mode][16]
&& i % 4 >= shape[num][mode][17]) {
if (shape[num][sa
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9195 2010-11-02 22:02 block.c
文件 5590 2010-11-02 11:59 block.h
文件 459 2010-11-02 11:59 main.c
文件 119 2010-11-02 11:59 Makefile
文件 19086 2010-11-24 22:57 test
- 上一篇:中文分词-C语言编写正向和反向最大匹配算法
- 下一篇:烟雾传感器代码
相关资源
- 基于MFC的TCP调试助手源码95706
- 国际象棋的qt源代码
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- 基于mfc的多线程文件传输
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 利用C++哈希表的方法实现电话号码查
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 移木块游戏,可以自编自玩,vc6.0编写
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- C++纯文字DOS超小RPG游戏
- 个人日常财务管理系统(C语言)
- MFC数字钟(基于VC6.0)
- c语言电子商务系统
评论
共有 条评论