fang.c
来自「redboy for gba 是BPNS为GBA编写的一个小软件。软件的邹形是B」· C语言 代码 · 共 571 行 · 第 1/2 页
C
571 行
box_display(j,i,stat[i][j]);
for (i=11;i<15;i++)
for (j=0;j<4;j++)
box_display(i,j,0);
}
void fanggame()
{
u8 stat[20][11];
int i,j,k;
u8 temp,done=0;
u8 speed=0,setspeed=0;
u8 down,dis,top,times;
u8 clear[4],is_new=0;
u8 flg;
u8 ischg=0;
u16 lines=0;
u32 score=0;
u32 wait,fast=45;
u32 time_sv=TM_CN;
u32 count,begin=0;
struct fang_loc sets[17][4]={{{1,1},{2,1},{1,2},{2,2}},{{1,0},{0,0},{2,0},{3,0}},
{{2,1},{1,1},{2,0},{3,1}},{{1,1},{1,0},{2,0},{1,2}},{{2,1},{2,0},{1,0},{2,2}},
{{1,1},{1,0},{2,1},{2,2}},{{2,1},{2,0},{1,1},{1,2}},{{1,1},{1,0},{1,2},{1,3}},
{{2,1},{2,0},{1,1},{2,2}},{{1,2},{0,2},{0,1},{2,2}},{{1,1},{0,1},{0,2},{2,1}},
{{2,1},{3,1},{2,2},{1,2}},{{1,1},{0,1},{1,2},{2,2}},{{1,1},{2,0},{1,2},{2,3}},
{{1,0},{0,1},{2,1},{1,2}},{{2,2},{0,2},{1,2},{3,1}},{{1,1},{2,1},{1,2},{2,2}}};
struct fang_loc next[4],now[4],pref[4],old[4];
u8 goal[4]={1,3,7,15};
char mes[40];
char say[100]="GAME OVER!\n";
fang_mes sav;
wait=KeyDelayCnt;
KeyDelayCnt=110;
TM_CN=0;
CS_OpenVBlank();
CS_SetIntrFunc(V_BLANK_INTR_FLAG,fang_timer);
fang_game_sv(&sav,2);//取得存档
if (sav.ctype>4) sav.ctype=0;
if (sav.flag=='S' && arlt("系统提示:","发现游戏存档,继续存档游戏吗?\n [A:YES] [B:NO]"))//有存档
{
fang_sv_to_dat(stat,sav.dat);//数据转化
lines=sav.lines;
score=sav.score;
map_save(sav.now,now);
map_save(sav.next,next);
lines=sav.lines;
speed=lines/50;
fast=65-(speed%16)*4;
}
else
{
for (i=0;i<20;i++)
for (j=0;j<11;j++)
stat[i][j]=0;
temp=rnd(13);
for (i=0;i<4;i++)
{
next[i].xp=sets[temp][i].xp;
next[i].yp=sets[temp][i].yp;
}
temp=rnd(13);
for (i=0;i<4;i++)
{
now[i].xp=sets[temp][i].xp+4;
now[i].yp=sets[temp][i].yp;
}
}//初始化数据并生成初始方块
Q_box(70,10,170,150,RGB(24,15,13));
r_box(70,10,170,150,RGB(30,30,30),0);
//Q_box(72,12,168,27,RGB(24,15,13));
cwrite(74,14,RGB(30,30,30),"俄罗斯方块");
cwrite(138,60,RGB(30,30,30),"分数");
show_num(140,75,score,5);
cwrite(138,85,RGB(30,30,30),"消行");
show_num(140,100,lines,5);
cwrite(138,110,RGB(30,30,30),"速度");
show_num(140,125,speed,5);
r_line(71,27,169,27,RGB(30,30,30),1);
fang_chang_color(sav.ctype,stat);
map_save(now,pref);
map_display(now,1);
map_save(next,old);
show_next(next,1);
//TM_CN=0;
while (TRUE)
{
count=TM_CN;
if (count>=begin+fast)
{
begin=TM_CN;
map_save(now,pref);
map_down(now,1);
done=1;
}
down=0;
top=19;
for (i=0;i<4;i++)
{
top=(top<pref[i].yp?top:pref[i].yp);
down=(down>pref[i].yp?down:pref[i].yp);
if (stat[now[i].yp][now[i].xp]||now[i].yp>19) done=2;
}
if (done==2) goto next;
is_new=0;
readkey();
if(CS_IsKeyDown(KEY_LEFT)||CS_IsKeyHold(KEY_LEFT))
{
done=1;
map_left(now);
}
else if(CS_IsKeyDown(KEY_RIGHT)||CS_IsKeyHold(KEY_RIGHT))
{
done=1;
map_right(now);
}
else if(CS_IsKeyDown(KEY_R))
{
sav.ctype=(sav.ctype+1)%5;
fang_chang_color(sav.ctype,stat);
show_next(next,1);
map_display(now,1);
ischg=1;
}
else if(CS_IsKeyDown(KEY_B))
{
flg=arlt("退出俄罗斯方块","您的游戏尚未结束,要存档并退出吗?\n[A:存档 B:继续 R:强退]");
if (flg==1)
{
fang_dat_to_sv(stat,sav.dat);//数据转化
sav.score=score;
sav.lines=lines;
sav.flag='S';
map_save(now,sav.now);
map_save(next,sav.next);
fang_game_sv(&sav,1);//保存数据
KeyDelayCnt=wait;
CS_CloseVBlank();
TM_CN=time_sv+TM_CN/60;
myobj_new_str("<REDBOY FOR GBA",1);
return;
}
else if (flg==2)
{
if (ischg) fang_game_sv(&sav,1);
KeyDelayCnt=wait;
CS_CloseVBlank();
TM_CN=time_sv+TM_CN/60;
myobj_new_str("<REDBOY FOR GBA",1);
return;
}
}
else if(CS_IsKeyDown(KEY_A)||CS_IsKeyDown(KEY_UP)||CS_IsKeyHold(KEY_A) || CS_IsKeyHold(KEY_UP))
{
done=1;
map_turn(now);
}
else if(CS_IsKeyDown(KEY_DOWN))
{
done=1;
map_qdown(now,stat);
show_map_qdown(pref,now[1].yp-pref[1].yp);
}
else if(CS_IsKeyDown(KEY_L))
{
arlt("俄罗斯方块操作说明","←→ 移动;↑A 翻转;↓键 下落;B键 退出。");
}
while (done)
{
for (i=0;i<4;i++)
if (stat[now[i].yp][now[i].xp])
{
done=0;
map_save(pref,now);
break;
}
if (done)
{
map_display(pref,0);
map_save(now,pref);
map_display(now,1);
done=0;
}
}
next: if (done==2)
{
temp=rnd(12+(speed>15?4:0));
for (i=0;i<4;i++)
{
stat[pref[i].yp][pref[i].xp]=1;
stat[pref[i].yp][10]++;
if (stat[0][10])
{
fang_newobj("GAME OVER!");
fang_gameover();
num_to_str(sav.hi_score,mes);
if (score>sav.hi_score)
{
//sav.hi_score=score;
sav.hi_score=score;
str_cat(say,"您破了最高记录");
str_cat(say,mes);
str_cat(say,"分了,玩的不错呀!");
fang_game_sv(&sav,1);
}
else
{
str_cat(say,"多多努力呀.\n最高记录:");
str_cat(say,mes);
str_cat(say,"分");
}
arlt("游戏结束",say);
KeyDelayCnt=wait;
CS_CloseVBlank();
TM_CN=time_sv+TM_CN/60;
if (ischg) fang_game_sv(&sav,1);
myobj_new_str("<REDBOY FOR GBA",1);
return;
}
now[i].xp=next[i].xp+4;
now[i].yp=next[i].yp;
next[i].xp=sets[temp][i].xp;
next[i].yp=sets[temp][i].yp;
}
map_save(now,pref);
map_display(now,1);
is_new=1;
show_next(old,0);
show_next(next,1);
map_save(next,old);
done=0;
dis=0;
for (i=down;i>=top;i--) if (stat[i][10]==10)
{clear[dis]=i;dis++;}
if (dis)
{
if (dis>2) fang_newobj("WELL DONE!");
else fang_newobj("GOOD!");
fang_clear_line(clear,dis);
score+=goal[dis-1];
lines+=dis;
speed=lines/50;
//if (speed>15) speed=0;
fast=65-(speed%16)*4;
show_num(140,75,score,5);
show_num(140,100,lines,5);
show_num(140,125,speed%16,5);
j=down;
for(i=down;i>=top;i--)
{
if (stat[i][10]==10) continue;
if (i!=j)
{
for (k=0;k<10;k++)
{
stat[j][k]=stat[i][k];
box_display(k,j,stat[j][k]);
}
stat[j][10]=stat[i][10];
}
j--;
}
for (i=top-1;i>=0;i--)
{
if (!stat[i+dis][10]) break;
for (k=0;k<10;k++)
{
stat[i+dis][k]=stat[i][k];
box_display(k,i+dis,stat[i+dis][k]);
}
stat[i+dis][10]=stat[i][10];
}
for (j=i+dis;j>i;j--)
{
for (k=0;k<10;k++)
{
stat[j][k]=0;
box_display(k,j,0);
}
stat[j][10]=0;
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?