资源简介
不到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语言编写正向和反向最大匹配算法
- 下一篇:烟雾传感器代码
相关资源
- TM4C123中文手册
- 单片机C语言实战开发108例
- stm32 AD7506
- stc-isp-15xx-v6.86G
- Linux那些事儿之我是USB core
- STC8G1K08A红外遥控点灯
- C语言的嵌入式汇编基本使用.docx(2页
- stm32f103c8t6开发板原理图+pcb
- Arduino 敲琴MIDI电子琴 程序报告.docx
- CAN实验
- LCD驱动芯片ST7701SI SPI接口底层驱动配
- 显示屏操作(stm32f103c8t6(SAN))
- USB CAN Tool 源代码(LabVIEW 2011环境)
- Proteus 8.6仿真STM32F103C6
- atmega128 串口通讯(RS485.c)
- C语言嵌入式Modbus协议栈,支持主站和
- stm32 +w5500 裸机 远程升级 自动dns pi
- 永磁同步电机的FOC控制算法
- arduino I2C设备扫描并串口返回地址(
- Proteus仿真:LCD液晶屏显示.rar
- STM32 PCB封装库 全系列 全网不好找
- 基于STM32F407的W5500 tcpserver(官网例程
- 步进电机调速原理.c
- tm1650+stm32f103源码(board_tm1650.c)
- 颜色识别形状识别STM103嵌入式代码
- 基于STM32的音频信号采样与FFT分析
- 汽车电子编程规范(Unlock-MISRA C 2012)
- cheat engine 7.2源码
- 基于STM32F103C8T6主控板使用BH1750检测光
- cubeMX设计实现stm32f407上的CAN及485的通
评论
共有 条评论