如何在代码块的头文件中包含conio2.h文件? [英] How include your conio2.h file in header in code blocks?
问题描述
我下载了你的源代码,当我尝试编译它时,它给了我关于conio2h没有这样的文件或目录的错误。我有所有文件包括conio2,h在我运行主文件的同一文件夹中。我不是找到任何解决方案,任何帮助将不胜感激。
下面给出的
是我的代码:
/ *
Tic Tac Toe游戏 - tictacto .c
作者:Shine Jacob(enot)
电邮:enot06@gmail.com
这是一个简单的Tic Tac Toe游戏。我使用的conio2.h不是C标准的一部分,而是默认情况下在Dev-C ++中不可用。您可以从http://conio.sourceforge.net/下载
,或者如果您希望在
Turbo C ++ IDE中编译该程序,那么用conio替换conio2.h .h。
如果您发现错误或有任何疑问,请告诉我。
我还附上了libconio.a和conio2.h
享受!
* /
#include< stdio.h>
#include< conio2.h>
#define UPARROW 72
#define DOWNARROW 80
#define LEFTARROW 75
#define RIGHTARROW 77
#define ENTER 13
#define退出'q'
int _x,_ y; //跟踪正在绘制的Tic Tac Toe框架的位置
//显示Tic Tac Toe框架的功能
void showframe(int posx,int posy)
{
int hr = 196,vr = 179; //这些是显示行的ascii字符
int crossbr = 197; //另一个ascii角色
int x = posx,y = posy;
int i,j;
gotoxy(35,4); cprintf(TIC TAC TOE);
gotoxy(35,5); for(i = 0; i< 11; i ++)cprintf(%c,223);
for(i = 0; i< 2; i ++)
{
for(j = 1; j< = 11; j ++)
{
gotoxy(x,y);
printf(%c,hr);
x ++;
}
x = posx; y + = 2;
}
x = posx + 3; y = posy-1;
for(i = 0; i< 2; i ++)
{
for(j = 1; j< = 5; j ++)
{
gotoxy(x,y);
printf(%c,vr);
y ++;
}
x + = 4; y = posy-1 ;
}
x = posx + 3; y =诗句;
gotoxy(x,y);
printf(%c,crossbr);
X = POSX + 7; y =诗句;
gotoxy(x,y);
printf(%c,crossbr);
X = POSX + 3; y = posy + 2;
gotoxy(x,y);
printf(%c,crossbr);
x = posx + 7; y = posy + 2;
gotoxy(x,y);
printf(%c,crossbr);
}
//将随机值填入数组的功能
void fillrandom (char arr [3] [3])
{
int i = 0,j = 0;
char ch ='A' ;
for(i = 0; i< 3; i ++)
{for(j = 0; j< 3; j ++)
{arr [i] [j] = ch; CH ++; }
}
}
//在指定框中显示角色的功能
void showbox(char ch,int box)
{
开关(方框)
{
案例1:gotoxy(_x + 1,_y-1);的printf( %C,CH);打破; //第一个盒子
案例2:gotoxy(_x + 5,_y-1);的printf( %C,CH);打破; //第二个盒子
案例3:gotoxy(_x + 9,_y-1);的printf( %C,CH);打破; //第3个盒子
案例4:gotoxy(_x + 1,_y + 1);的printf( %C,CH);打破; //第四个盒子
案例5:gotoxy(_x + 5,_y + 1);的printf( %C,CH);打破; //第五盒
案例6:gotoxy(_x + 9,_y + 1);的printf( %C,CH);打破; //第6个方框
案例7:gotoxy(_x + 1,_y + 3);的printf( %C,CH);打破; //第7个方框
案例8:gotoxy(_x + 5,_y + 3);的printf( %C,CH);打破; //第8个方框
案例9:gotoxy(_x + 9,_y + 3);的printf( %C,CH);打破; //第9盒
}
}
//将指定字符插入数组的函数
void putintobox(char arr [3] [3],char ch,int box)
{
开关(盒子)
{
案例1:if(arr [0] [0]! ='X'&& arr [0] [0]!='O')
{arr [0] [0] = ch;
showbox( ch,1);
}
休息;
案例2:if(arr [0] [ 1]!='X'&& arr [0] [1]!='O')
{arr [0] [1] = ch;
showbox(ch,2);
}
休息;
案例3:if(arr [arr] 0] [2]!='X'&& arr [0] [2]!='O')
{arr [0] [2] = ch;
showbox(ch,3);
}
休息;
案例4:如果(arr [1] [0]!='X'&&am p; arr [1] [0]!='O')
{arr [1] [0] = ch;
showbox(ch,4);
}
休息;
案例5:if(arr [1] [1]!='X '&& arr [1] [1]!='O')
{arr [1] [1] = ch;
showbox(ch,5);
}
休息;
案例6:if(arr [1] [2]!='X'& ;& arr [1] [2]!='O')
{arr [1] [2] = ch;
showbox(ch,6);
}
休息;
案例7:if(arr [2] [0]!=' X'&& arr [2] [0]!='O')
{arr [2] [0] = ch;
showbox(ch, 7);
}
休息;
案例8:if(arr [2] [1] !='X'&& arr [2] [1]!='O')
{arr [2] [1] = ch;
showbox (ch,8);
}
休息;
案例9:if(arr [2] [2]!='X'&& arr [2] [2]!='O')
{arr [2] [2] = ch;
showbox(ch,9);
}
休息;
} //开关结束
}
//在指定的框上显示游标的功能
//使用位置检查坐标
void gotobox(int box)
{
开关(方框)
{
案例1:gotoxy(_x + 1,_y-1 );休息;
案例2:gotoxy(_x + 5,_y-1);休息;
案例3:gotoxy(_x + 9,_y-1);休息;
案例4:gotoxy(_x + 1,_y + 1);休息;
案例5:gotoxy(_x + 5,_y + 1);打破; //第五盒
案例6:gotoxy(_x + 9,_y + 1);打破; //第6个方框
案例7:gotoxy(_x + 1,_y + 3);打破; //第7个方框
案例8:gotoxy(_x + 5,_y + 3);打破; //第8个方框
案例9:gotoxy(_x + 9,_y + 3);休息;
}
}
//处理导航的函数
int navigate(char arr [3] [3],int box,int player,int key)
{
开关(键)
{
case UPARROW:if((box!= 1)||(box!= 2)||(方框! = 3))
{box- = 3; if(box< 1)box = 1; gotobox(盒); }
休息;
case DOWNARROW:if((box!= 7)||(box!= 8)||(box != 9))
{box + = 3; if(box> 9)box = 9; gotobox(盒); }
休息;
case LEFTARROW:if((box!= 1)||(box!= 4)||(box != 7))
{box--; if(box< 1)box = 1; gotobox(盒); }
休息;
案例RIGHTARROW:if((box!= 3)||(box!= 6)||(box != 9))
{box ++; if(box> 9)box = 9; gotobox(盒); }
休息;
案例ENTER:if(player == 0)
putintobox(arr,'哦',盒子);
否则如果(玩家== 1)
putintobox(arr,'X',盒子);
休息;
} //开关(钥匙)结束
退货箱;
}
int checkforwin(char arr [3] [3])
{
int w = 0;
/ * 0,0 0,1 0,2
1,0 1,1 1,2
2, 0 2,1 2,2
* /
//行
if((arr [0] [0] == arr [ 0] [1])&&(arr [0] [1] == arr [0] [2]))w = 1;
else if((arr [1] [ 0] == arr [1] [1])&&(arr [1] [1] == arr [1] [2]))w = 1;
else if( (arr [2] [0] == arr [2] [1])&&(arr [2] [1] == arr [2] [2]))w = 1;
// coloums
if if((arr [0] [0] == arr [1] [0])&&(arr [ 1] [0] == arr [2] [0]))w = 1;
else if((arr [0] [1] == arr [1] [1])&& (arr [1] [1] == arr [2] [1]))w = 1;
if if((arr [0] [2] == arr [1] [2 ])&&(arr [1] [2] == arr [2] [2]))w = 1;
//对角线
else if((arr [0] [0] == arr [1] [1])&&(arr [1] [1] == arr [2] [2])) w = 1;
if if((arr [0] [2] == arr [1] [1])&&(arr [1] [1] == arr [2 ] [0]))w = 1;
返回w;
}
int boxesleft(char a [3] [3])
{
int i,j,boxesleft = 9;
for(i = 0; i< 3; i ++)
{for(j = 0; j< 3; j ++)
{if((a [i] [j] =='X')||(a [i] [j] =='O'))
boxesleft - ;
}
}
返回boxesleft;
} < br $>
int main()
{
char arr [3] [ 3];
char player [3] [30],O_OR_X [2],ch;
int x,y,turn,chance,enter,box,win,退出,赢家;
int movefinish ed = 0;
O_OR_X [0] ='O'; O_OR_X [1] ='X';
do {
textbackground(7);文本颜色(0); //设置指定的背景和textcolor
clrscr(); //清除屏幕 - 在conio.h中定义(conio2.h)
_x = 35; _y = 12;
x = _x; y = _y;
showframe(x,y); //画出Tic Tac Toe的框架
showbox('O',1); //在方框1中显示O
showbox('X',2); //在方框2中显示X
showbox('O',3); //在方框3中显示O
showbox('X',4); //在方框4中显示X
showbox('O',5); //在方框5中显示O
showbox('X',6); //在方框6中显示X
showbox('O',7); //在方框7中显示O
showbox('X',8); //在方框8中显示X
showbox('O',9); //在方框9中显示O
gotoxy(2,18);
printf(欢迎来到Tic Tac Toe);
printf(\ n规则很简单。使用箭头键[%c%c%c%c]导航到框并按Enter键。,30,31,17,16);
printf(\ n如果你试图覆盖一个盒子,那么你的机会将被传递。);
fillrandom(arr); //将随机字符填充到数组中
printf(\ n Player 1,输入你的名字:);得到(播放器[0]); //获取player1的名字
printf(玩家2,输入你的名字:);得到(播放器[1]); //获取player2的名字
printf(\ n%s,你得到了O%s,你得到了X,玩家[0],播放器[1]);
printf(\ n让我们开始(按任意键)); getch();
turn = 0; //计算总回合数
chance = 0; //检查是谁的机会
enter = 0; //用于跟踪Enter是否被按下的变量
box = 1; //跟踪当前的箱号
win = 0; //检查是否有人赢了
quit = 0; //检查玩家是否要退出
winner = 10; //看看谁是冠军
clrscr( );
showframe(x,y);
while((!win))
{< br $>
gotoxy(2,20);
printf(%s(%c),它是你的机会。,玩家[机会],O_OR_X [机会]);
while(!enter&&!quit)
{
if(kbhit())
{
ch = getch();
开关(ch)
{
case UPARROW:box = navigate(arr,box,chance,UPARROW);
break ;
case DOWNARROW:box = navigate(arr,box,chance,DOWNARROW);
break;
case LEFTARROW:box = navigate( arr,box,chance,LEFTARROW);
break;
case RIGHTARROW:box = navigate(arr,box,chance,RIGHTARROW);
休息;
案ENTER:box = navigate(arr,box,chance,ENTER);
enter = 1;休息;
案例退出:退出= 1;休息;
} //开关结束(ch)
} //结束if(kbhit())
} //结束时间
if(quit)break; //退出程序
if(chance == 0)
{putintobox(arr,box,'O'); box = 1; } // player1
else if(chance == 1)
{putintobox(arr,box,'X'); box = 1; } // player2
if((win = checkforwin(arr))== 1)
获胜者=机会;
if(机会== 1)机会= 0;
其他机会= 1;
输入= 0;
变成++;
if(!boxesleft(arr))
movefinished = 1;
//如果是平局
if((!win)&&(turns == 9)& &(move完成))
休息;
} //结束时间(赢)
if(win)
{gotoxy(22,22);
textbackground(4); textcolor(15);
if(winner == 0)
cprintf(祝贺%s,你赢了比赛!,玩家[0]);
其他
cprintf(祝贺%s,你赢了比赛!,玩家[1]) ;
}
否则如果(退出)
{
gotoxy(10,22);
textbackground(4); textcolor(15);
cprintf(好的,让我们再玩一次。稍后再见。按任意键退出。\ n \\ nn);
getch();
返回1;
}
else if((!win)&&(turns == 9)& ;&(movefinished))
{gotoxy(22,22);
printf(没有人赢。它是平局。);
}
printf(\ n \ n你想再玩一次吗?(是/否):); ch = getch();
} while(ch =='Y'|| ch =='y'); // playagain
返回0;
}
I downloaded your source code and when i try to compile this ,it give me error about conio2h no such file or directory.I have the all files included conio2,h in same folder as i run the main file.I am not found any solution of this,Any help would be appreciate.
given below is my code:
/*
Tic Tac Toe game - tictacto.c
Author : Shine Jacob(enot)
Email : enot06@gmail.com
This is a simple Tic Tac Toe game. I have used conio2.h that is not a part of
the C standard and not available in Dev-C++ by default. You can download it
from http://conio.sourceforge.net/ or if you wish to compile this program in
Turbo C++ IDE then replace conio2.h with conio.h.
Please let me know if you find and error or if you have any questions.
I have also attached libconio.a and conio2.h
Enjoy!
*/
#include <stdio.h>
#include <conio2.h>
#define UPARROW 72
#define DOWNARROW 80
#define LEFTARROW 75
#define RIGHTARROW 77
#define ENTER 13
#define QUIT 'q'
int _x,_y; //To track the position of the Tic Tac Toe frame being drawn
//Function to show the Tic Tac Toe Frame
void showframe(int posx, int posy)
{
int hr=196, vr=179; // These are ascii character which display the lines
int crossbr=197; // Another ascii character
int x=posx, y=posy;
int i,j;
gotoxy(35,4); cprintf("TIC TAC TOE");
gotoxy(35,5); for(i=0;i<11;i++) cprintf("%c",223);
for(i=0;i<2;i++)
{
for(j=1;j<=11;j++)
{
gotoxy(x,y);
printf("%c",hr);
x++;
}
x=posx; y+=2;
}
x=posx+3; y=posy-1;
for(i=0;i<2;i++)
{
for(j=1;j<=5;j++)
{
gotoxy(x,y);
printf("%c",vr);
y++;
}
x+=4;y=posy-1;
}
x=posx+3; y=posy;
gotoxy(x,y);
printf("%c",crossbr);
x=posx+7; y=posy;
gotoxy(x,y);
printf("%c",crossbr);
x=posx+3; y=posy+2;
gotoxy(x,y);
printf("%c",crossbr);
x=posx+7; y=posy+2;
gotoxy(x,y);
printf("%c",crossbr);
}
//Function to fill random values into the array
void fillrandom(char arr[3][3])
{
int i=0,j=0;
char ch='A';
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{ arr[i][j] = ch; ch++; }
}
}
//Function to show the character in the specified box
void showbox(char ch, int box)
{
switch(box)
{
case 1 : gotoxy(_x+1,_y-1); printf("%c",ch); break; //1st box
case 2 : gotoxy(_x+5,_y-1); printf("%c",ch); break; //2nd box
case 3 : gotoxy(_x+9,_y-1); printf("%c",ch); break; //3rd box
case 4 : gotoxy(_x+1,_y+1); printf("%c",ch); break; //4th box
case 5 : gotoxy(_x+5,_y+1); printf("%c",ch); break; //5th box
case 6 : gotoxy(_x+9,_y+1); printf("%c",ch); break; //6th box
case 7 : gotoxy(_x+1,_y+3); printf("%c",ch); break; //7th box
case 8 : gotoxy(_x+5,_y+3); printf("%c",ch); break; //8th box
case 9 : gotoxy(_x+9,_y+3); printf("%c",ch); break; //9th box
}
}
//Function to insert the specified character into the array
void putintobox(char arr[3][3], char ch, int box)
{
switch(box)
{
case 1 : if(arr[0][0] != 'X' && arr[0][0]!= 'O')
{ arr[0][0] = ch;
showbox(ch,1);
}
break;
case 2 : if(arr[0][1] != 'X' && arr[0][1]!= 'O')
{ arr[0][1] = ch;
showbox(ch,2);
}
break;
case 3 : if(arr[0][2] != 'X' && arr[0][2]!= 'O')
{ arr[0][2] = ch;
showbox(ch,3);
}
break;
case 4 : if(arr[1][0] != 'X' && arr[1][0]!= 'O')
{ arr[1][0] = ch;
showbox(ch,4);
}
break;
case 5 : if(arr[1][1] != 'X' && arr[1][1]!= 'O')
{ arr[1][1] = ch;
showbox(ch,5);
}
break;
case 6 : if(arr[1][2] != 'X' && arr[1][2]!= 'O')
{ arr[1][2] = ch;
showbox(ch,6);
}
break;
case 7 : if(arr[2][0] != 'X' && arr[2][0]!= 'O')
{ arr[2][0] = ch;
showbox(ch,7);
}
break;
case 8 : if(arr[2][1] != 'X' && arr[2][1]!= 'O')
{ arr[2][1] = ch;
showbox(ch,8);
}
break;
case 9 : if(arr[2][2] != 'X' && arr[2][2]!= 'O')
{ arr[2][2] = ch;
showbox(ch,9);
}
break;
}//end of switch
}
//Function to show the curson on the box specified
//uses the position to check the coordinates
void gotobox(int box)
{
switch(box)
{
case 1 : gotoxy(_x+1,_y-1); break;
case 2 : gotoxy(_x+5,_y-1); break;
case 3 : gotoxy(_x+9,_y-1); break;
case 4 : gotoxy(_x+1,_y+1); break;
case 5 : gotoxy(_x+5,_y+1); break; //5th box
case 6 : gotoxy(_x+9,_y+1); break; //6th box
case 7 : gotoxy(_x+1,_y+3); break; //7th box
case 8 : gotoxy(_x+5,_y+3); break; //8th box
case 9 : gotoxy(_x+9,_y+3); break;
}
}
//Function to handle the navigation
int navigate(char arr[3][3], int box, int player, int key)
{
switch(key)
{
case UPARROW : if( (box!=1) || (box!=2) || (box!=3) )
{ box-=3; if(box<1) box = 1; gotobox(box); }
break;
case DOWNARROW : if( (box!=7) || (box!=8) || (box!=9) )
{ box+=3; if(box>9) box = 9; gotobox(box); }
break;
case LEFTARROW : if( (box!=1) || (box!=4) || (box!=7) )
{ box--; if(box<1) box = 1; gotobox(box); }
break;
case RIGHTARROW : if( (box!=3) || (box!=6) || (box!=9) )
{ box++; if(box>9) box = 9; gotobox(box); }
break;
case ENTER : if(player == 0)
putintobox(arr,'O',box);
else if(player == 1)
putintobox(arr,'X',box);
break;
}//end of switch(key)
return box;
}
int checkforwin(char arr[3][3])
{
int w=0;
/* 0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2
*/
//rows
if((arr[0][0] == arr[0][1]) && (arr[0][1] == arr[0][2])) w = 1;
else if((arr[1][0] == arr[1][1]) && (arr[1][1] == arr[1][2])) w = 1;
else if((arr[2][0] == arr[2][1]) && (arr[2][1] == arr[2][2])) w = 1;
//coloums
else if((arr[0][0] == arr[1][0]) && (arr[1][0] == arr[2][0])) w = 1;
else if((arr[0][1] == arr[1][1]) && (arr[1][1] == arr[2][1])) w = 1;
else if((arr[0][2] == arr[1][2]) && (arr[1][2] == arr[2][2])) w = 1;
//diagonal
else if((arr[0][0] == arr[1][1]) && (arr[1][1] == arr[2][2])) w = 1;
else if((arr[0][2] == arr[1][1]) && (arr[1][1] == arr[2][0])) w = 1;
return w;
}
int boxesleft(char a[3][3])
{
int i,j,boxesleft=9;
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{ if((a[i][j] == 'X') ||(a[i][j] == 'O'))
boxesleft--;
}
}
return boxesleft;
}
int main()
{
char arr[3][3];
char player[3][30],O_OR_X[2],ch;
int x,y,turns,chance,enter,box,win,quit,winner;
int movesfinished = 0;
O_OR_X[0] = 'O'; O_OR_X[1] = 'X';
do{
textbackground(7); textcolor(0); //Set the specified background and textcolor
clrscr(); //Clears the screen - defined in conio.h(conio2.h)
_x = 35; _y = 12;
x = _x; y = _y;
showframe(x,y); //Draws the frame of Tic Tac Toe
showbox('O',1); //Displays O in box 1
showbox('X',2); //Displays X in box 2
showbox('O',3); //Displays O in box 3
showbox('X',4); //Displays X in box 4
showbox('O',5); //Displays O in box 5
showbox('X',6); //Displays X in box 6
showbox('O',7); //Displays O in box 7
showbox('X',8); //Displays X in box 8
showbox('O',9); //Displays O in box 9
gotoxy(2,18);
printf("Welcome to Tic Tac Toe");
printf("\n Rules are simple. Navigate to the box with arrow keys [%c %c %c %c] and hit enter.",30,31,17,16);
printf("\n If you try to overwrite a box, then your chance will be passed on.");
fillrandom(arr); //Filling random character to the array
printf("\n Player 1, enter your name: "); gets(player[0]); //Get player1's name
printf(" Player 2, enter your name: "); gets(player[1]); //Get player2's name
printf("\n %s, you have been given O %s, you have been given X",player[0],player[1]);
printf("\n Lets begin ( press any key )"); getch();
turns = 0; //to count the total number of turns
chance = 0; //to check whose chance is it
enter = 0; //variable to track if Enter was pressed
box = 1; //Track the current box number
win = 0; //Check if someone won
quit = 0; //Check if player wants to quit
winner = 10; //To see who is the winner
clrscr();
showframe(x,y);
while((!win))
{
gotoxy(2,20);
printf("%s(%c), its your chance. ",player[chance],O_OR_X[chance]);
while(!enter && !quit)
{
if(kbhit())
{
ch = getch();
switch(ch)
{
case UPARROW : box=navigate(arr,box,chance,UPARROW);
break;
case DOWNARROW : box=navigate(arr,box,chance,DOWNARROW);
break;
case LEFTARROW : box=navigate(arr,box,chance,LEFTARROW);
break;
case RIGHTARROW : box=navigate(arr,box,chance,RIGHTARROW);
break;
case ENTER : box=navigate(arr,box,chance,ENTER);
enter=1; break;
case QUIT : quit = 1; break;
}//end of switch(ch)
}//end of if(kbhit())
}//end of while
if(quit) break; //Quits the program
if(chance == 0)
{ putintobox(arr,box,'O'); box = 1; } //player1
else if(chance == 1)
{ putintobox(arr,box,'X'); box = 1; } //player2
if( (win = checkforwin(arr)) == 1)
winner = chance;
if(chance == 1) chance = 0;
else chance = 1;
enter = 0;
turns++;
if(!boxesleft(arr))
movesfinished = 1;
//If its a draw
if((!win) && (turns==9) && (movesfinished))
break;
}//end of while(win)
if(win)
{ gotoxy(22,22);
textbackground(4); textcolor(15);
if(winner == 0)
cprintf(" Congratulations %s, you win the game! ",player[0]);
else
cprintf(" Congratulations %s, you win the game! ",player[1]);
}
else if(quit)
{
gotoxy(10,22);
textbackground(4); textcolor(15);
cprintf(" Ok, lets play again sometime. See you later. Press any key to exit.\n\n");
getch();
return 1;
}
else if((!win) && (turns==9) && (movesfinished))
{ gotoxy(22,22);
printf("No one wins. Its a draw.");
}
printf("\n\n Do you want to play again? (Y/N): "); ch = getch();
}while(ch=='Y' || ch=='y'); //playagain
return 0;
}
推荐答案
在文件顶部插入
insert at the top of your files
#include "conio2.h"
文件应该在你的项目目录或项目搜索路径中(包括)
也许你只是错过了一个。
The file should be in your project directory or project search path (include)
Maybe you only missed a "."
这篇关于如何在代码块的头文件中包含conio2.h文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!