-1
私は以下の簡単なスネークゲームを作った。すべてが..私は、ユーザーが私が現在使用していません。1.ユーザーが再び再生するように促す
を入力して、再びゲームをプレイすることを可能にする機能を実装しようとしていますがしばらく...ゲーム
ためのループただし、ここでは正常に動作します問題は、プログラムは1を入力すると再起動しますが、 の文字(tx、jxなど)がまったく生成されず、ゲームは単にバックグラウンドで無限にループします(終了時にprintfジュジュ.... ")、のprintf(" バックグラウンドで印刷された「ripperoniは)
のヘルプは大歓迎です!
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "display.h"
#include "move.h"
#include "place.h"
#define MAX 799
#define DEAD 0
#define TRUE 1
#define FALSE 0
int main()
{
//initialize variables
struct pos { //positions
int fx[MAX];
int fy[MAX];
int tx;
int ty;
int jx;
int jy;
} pos;
struct score { //scores
int move;
int F;
int J;
} score;
int d,q,i,k,f,followc;
int p;
char *z="Number of Jujus collectd ";
char *y="The number of followers ";
do {
score.F=score.J = score.move = 0;
i=k=f=followc=0;
draw_map();
place(&pos.tx,&pos.ty);
sleep(1);
draw_symbol(pos.tx, pos.ty, 'S');
place(&pos.jx, &pos.jy);
display_score(score.move);
debug_wds(5,z);
debug_wds(8,y);
debug_num(6,score.J);
debug_num(9,score.F);
while(d!=DEAD && q != 'q' && q != 'Q')
{
pos.fx[i]=pos.tx; //store timmy's position in follower
pos.fy[i]=pos.ty; //store timmy's position in follower
draw_symbol(pos.jx, pos.jy, '$');
display_score(score.move);
debug_wds(5,z);
debug_num(6,score.J);
debug_wds(8,y);
debug_num(9,score.F);
q = move(&pos.tx, &pos.ty); //move timmy
score.move++;
draw_symbol(pos.tx,pos.ty,'S'); //update timmy's position
if((pos.tx ==pos.jx)&&(pos.ty == pos.jy)) //if timmy collects a juju
{
score.J++; //update juju score
score.F++; //update follower score
display_score(score.move);
place(&pos.jx,&pos.jy);
followc++; //update follower count
}
for (f=0,k=i+1-followc; f<followc; f++,k++) //check to see if timmy is same position as followers
{
if(pos.tx==pos.fx[k]&&pos.ty==pos.fy[k])
{
d=DEAD;
}
draw_symbol(pos.fx[k],pos.fy[k],'O'); //draw followers
}
i++;
}
clear_screen();
printf("Number of Jujus = %d\n", score.J);
printf("Ripperoni... You really need to update your server(s)..*___*\n");
printf("Enter 1 to keep playing\n");
scanf("%d",&p);
} while(p==1);
}
あなたの問題は、コンソール入力はラインバッファ型であるということです、そしてあなたのscanf()の呼び出しが復帰して行全体を消費していませんすぐに。SO - search "scanf infinite loop"に多数の複製があります。 – Clifford