大大們
下面是一個貪吃蛇的遊戲
但是我沒辦法在TURBO C運轉(學習上)
麻煩大大幫個忙
要怎麼改才可以在TURBO C上執行
謝謝
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <windows.h>
#define UP 'i'//105
#define DOWN 'k'//107
#define LEFT 'j'//106
#define RIGHT 'l'//108
#define ESC 27
#define SIZE 15
int head_X=SIZE>>1,head_Y=SIZE>>1;//貪食蛇的起始位置
int food_X,food_Y;//食物的位置
enum SnakeState {None,Food,Body};
struct _snake
{
unsigned char state;//None=空白;Food=食物;Body=蛇的身體
struct _snake* nex;
}snake[SIZE][SIZE],*tail,*head;
void gotoxy(const int,const int);
void SetCursorVisible(BOOL,DWORD);
void insertAtHead(const int,const int);
void removeAtTail();
void createFood();
void border();
int main()
{
int key,direction=RIGHT;
int lose=0,i,j;
//初始化snake陣列
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE;j++)
{
snake
[j].state=None;
snake[j].nex=NULL;
}
}
//初始化貪食蛇
snake[head_X][head_Y].state=Body;
head=&snake[head_X][head_Y];
tail=&snake[head_X][head_Y];
gotoxy(head_X+1,head_Y+1);printf("█");
createFood();
border();
SetCursorVisible(FALSE,100);
//遊戲內容開始
do
{
Sleep(100);//程式間隔時間
if(kbhit())//檢驗是否有按下鍵盤
{
if((key=getch())==ESC) break;
if((key&1) ^ (direction&1)) direction=key;
}
switch(direction)
{
case UP:
head_Y = head_Y<1 ? SIZE-1 : head_Y-1;
break;
case DOWN:
head_Y = (head_Y+1)%SIZE;
break;
case LEFT:
head_X = head_X<1 ? SIZE-1 : head_X-1;
break;
case RIGHT:
head_X = (head_X+1)%SIZE;
}
//蛇的移動
if(snake[head_X][head_Y].state<Body)
{
insertAtHead(head_X,head_Y);
if(head_X!=food_X || head_Y!=food_Y)
removeAtTail();
else
createFood();
}
else lose=1;
/ [ 瀏覽完整內容請先註冊或登入會員。]