★★★高分悬赏★★★用C语言编简单的五子棋(答案好的追加100分) 100

实习结束后老师让我们编个简单的五子棋,老师也不考虑下我们的水平,算法也不告诉我们,就让我们编哪个C高手帮我下给我个五子棋的代码,不要太复杂的,越简单越好,要求能判断输赢就... 实习结束后老师让我们编个简单的五子棋,
老师也不考虑下我们的水平,
算法也不告诉我们,就让我们编

哪个C高手帮我下
给我个五子棋的代码,
不要太复杂的,越简单越好,要求能判断输赢就可以,画面越简单越好,
看上去上初学着做的就可以

很急
求大家帮帮忙
好的答案我就给200分
展开
 我来答
萌哒牛
2007-10-01 · TA获得超过1910个赞
知道小有建树答主
回答量:1100
采纳率:0%
帮助的人:119万
展开全部
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
/**********************************************************/
/* 定义符号常量 */
/*定义画棋盘所需的制表符*/
#define CROSSRU 0xbf /*右上角点*/
#define CROSSLU 0xda /*左上角点*/
#define CROSSLD 0xc0 /*左下角点*/
#define CROSSRD 0xd9 /*右下角点*/
#define CROSSL 0xc3 /*左边*/
#define CROSSR 0xb4 /*右边*/
#define CROSSU 0xc2 /*上边*/
#define CROSSD 0xc1 /*下边*/
#define CROSS 0xc5 /*十字交叉点*/
/*定义棋盘左上角点在屏幕上的位置*/
#define MAPXOFT 5
#define MAPYOFT 2
/*定义1号玩家的操作键键码*/
#define PLAY1UP 0x1157/*上移--'W'*/
#define PLAY1DOWN 0x1f53/*下移--'S'*/
#define PLAY1LEFT 0x1e41/*左移--'A'*/
#define PLAY1RIGHT 0x2044/*右移--'D'*/
#define PLAY1DO 0x3920/*落子--空格键*/
/*定义2号玩家的操作键键码*/
#define PLAY2UP 0x4800/*上移--方向键up*/
#define PLAY2DOWN 0x5000/*下移--方向键down*/
#define PLAY2LEFT 0x4b00/*左移--方向键left*/
#define PLAY2RIGHT 0x4d00/*右移--方向键right*/
#define PLAY2DO 0x1c0d/*落子--回车键Enter*/
/*若想在游戏中途退出, 可按 Esc 键*/
#define ESCAPE 0x011b
/*定义棋盘上交叉点的状态, 即该点有无棋子 */
/*若有棋子, 还应能指出是哪个玩家的棋子 */
#define CHESSNULL 0 /*没有棋子*/
#define CHESS1 'O'/*一号玩家的棋子*/
#define CHESS2 'X'/*二号玩家的棋子*/
/*定义按键类别*/
#define KEYEXIT 0/*退出键*/
#define KEYFALLCHESS 1/*落子键*/
#define KEYMOVECURSOR 2/*光标移动键*/
#define KEYINVALID 3/*无效键*/
/*定义符号常量: 真, 假 --- 真为1, 假为0 */
#define TRUE 1
#define FALSE 0
/**********************************************************/
/* 定义数据结构 */
/*棋盘交叉点坐标的数据结构*/
struct point
{
int x,y;
};
/**********************************************************/
/*自定义函数原型说明 */
void Init(void);
int GetKey(void);
int CheckKey(int press);
int ChangeOrder(void);
int ChessGo(int Order,struct point Cursor);
void DoError(void);
void DoOK(void);
void DoWin(int Order);
void MoveCursor(int Order,int press);
void DrawCross(int x,int y);
void DrawMap(void);
int JudgeWin(int Order,struct point Cursor);
int JudgeWinLine(int Order,struct point Cursor,int direction);
void ShowOrderMsg(int Order);
void EndGame(void);
/**********************************************************/
/**********************************************************/
/* 定义全局变量 */
int gPlayOrder; /*指示当前行棋方 */
struct point gCursor; /*光标在棋盘上的位置 */
char gChessBoard[19][19];/*用于记录棋盘上各点的状态*/
/**********************************************************/
/**********************************************************/
/*主函数*/
void main()
{
int press;
int bOutWhile=FALSE;/*退出循环标志*/
Init();/*初始化图象,数据*/
while(1)
{
press=GetKey();/*获取用户的按键值*/
switch(CheckKey(press))/*判断按键类别*/
{
/*是退出键*/
case KEYEXIT:
clrscr();/*清屏*/
bOutWhile = TRUE;
break;
/*是落子键*/
case KEYFALLCHESS:
if(ChessGo(gPlayOrder,gCursor)==FALSE)/*走棋*/
DoError();/*落子错误*/
else
{
DoOK();/*落子正确*/
/*如果当前行棋方赢棋*/
if(JudgeWin(gPlayOrder,gCursor)==TRUE)
{
DoWin(gPlayOrder);
bOutWhile = TRUE;/*退出循环标志置为真*/
}
/*否则*/
else
/*交换行棋方*/
ChangeOrder();
}
break;
/*是光标移动键*/
case KEYMOVECURSOR:
MoveCursor(gPlayOrder,press);
break;
/*是无效键*/
case KEYINVALID:
break;
}
if(bOutWhile==TRUE)
break;
}
/*游戏结束*/
EndGame();
}
/**********************************************************/
/*界面初始化,数据初始化*/
void Init(void)
{
int i,j;
char *Msg[]=
{
"Player1 key:",
" UP----w",
" DOWN--s",
" LEFT--a",
" RIGHT-d",
" DO----space",
"",
"Player2 key:",
" UP----up",
" DOWN--down",
" LEFT--left",
" RIGHT-right",
" DO----ENTER",
"",
"exit game:",
" ESC",
NULL,
};
/*先手方为1号玩家*/
gPlayOrder = CHESS1;
/*棋盘数据清零, 即棋盘上各点开始的时候都没有棋子*/
for(i=0;i<19;i++)
for(j=0;j<19;j++)
gChessBoard[i][j]=CHESSNULL;
/*光标初始位置*/
gCursor.x=gCursor.y=0;
/*画棋盘*/
textmode(C40);
DrawMap();
/*显示操作键说明*/
i=0;
textcolor(BROWN);
while(Msg[i]!=NULL)
{
gotoxy(25,3+i);
cputs(Msg[i]);
i++;
}
/*显示当前行棋方*/
ShowOrderMsg(gPlayOrder);
/*光标移至棋盘的左上角点处*/
gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}
/*画棋盘*/
void DrawMap(void)
{
int i,j;
clrscr();
for(i=0;i<19;i++)
for(j=0;j<19;j++)
DrawCross(i,j);
}
/*画棋盘上的交叉点*/
void DrawCross(int x,int y)
{
gotoxy(x+MAPXOFT,y+MAPYOFT);
/*交叉点上是一号玩家的棋子*/
if(gChessBoard[x][y]==CHESS1)
{
textcolor(LIGHTBLUE);
putch(CHESS1);
return;
}
/*交叉点上是二号玩家的棋子*/
if(gChessBoard[x][y]==CHESS2)
{
textcolor(LIGHTBLUE);
putch(CHESS2);
return;
}
textcolor(GREEN);
/*左上角交叉点*/
if(x==0&&y==0)
{
putch(CROSSLU);
return;
}
/*左下角交叉点*/
if(x==0&&y==18)
{
putch(CROSSLD);
return;
}
/*右上角交叉点*/
if(x==18&&y==0)
{
putch(CROSSRU);
return;
}
/*右下角交叉点*/
if(x==18&&y==18)
{
putch(CROSSRD);
return;
}
/*左边界交叉点*/
if(x==0)
{
putch(CROSSL);
return;
}
/*右边界交叉点*/
if(x==18)
{
putch(CROSSR);
return;
}
/*上边界交叉点*/
if(y==0)
{
putch(CROSSU);
return;
}
/*下边界交叉点*/
if(y==18)
{
putch(CROSSD);
return;
}
/*棋盘中间的交叉点*/
putch(CROSS);
}
/*交换行棋方*/
int ChangeOrder(void)
{
if(gPlayOrder==CHESS1)
gPlayOrder=CHESS2;
else
gPlayOrder=CHESS1;
return(gPlayOrder);
}
/*获取按键值*/
int GetKey(void)
{
char lowbyte;
int press;
while (bioskey(1) == 0)
;/*如果用户没有按键,空循环*/
press=bioskey(0);
lowbyte=press&0xff;
press=press&0xff00 + toupper(lowbyte);
return(press);
}
/*落子错误处理*/
void DoError(void)
{
sound(1200);
delay(50);
nosound();
}
/*赢棋处理*/
void DoWin(int Order)
{
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
sound(1500);delay(100);
sound(0); delay(50);
sound(800); delay(100);
sound(0); delay(50);
nosound();
textcolor(RED+BLINK);
gotoxy(25,20);
if(Order==CHESS1)
cputs("PLAYER1 WIN!");
else
cputs("PLAYER2 WIN!");
gotoxy(25,21);
cputs(" \\<^+^>/");
getch();
}
/*走棋*/
int ChessGo(int Order,struct point Cursor)
{
/*判断交叉点上有无棋子*/
if(gChessBoard[Cursor.x][Cursor.y]==CHESSNULL)
{
/*若没有棋子, 则可以落子*/
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
textcolor(LIGHTBLUE);
putch(Order);
gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
gChessBoard[Cursor.x][Cursor.y]=Order;
return TRUE;
}
else
return FALSE;
}
/*判断当前行棋方落子后是否赢棋*/
int JudgeWin(int Order,struct point Cursor)
{
int i;
for(i=0;i<4;i++)
/*判断在指定方向上是否有连续5个行棋方的棋子*/
if(JudgeWinLine(Order,Cursor,i))
return TRUE;
return FALSE;
}
/*判断在指定方向上是否有连续5个行棋方的棋子*/
int JudgeWinLine(int Order,struct point Cursor,int direction)
{
int i;
struct point pos,dpos;
const int testnum = 5;
int count;
switch(direction)
{
case 0:/*在水平方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y;
dpos.x=1;
dpos.y=0;
break;
case 1:/*在垂直方向*/
pos.x=Cursor.x;
pos.y=Cursor.y-(testnum-1);
dpos.x=0;
dpos.y=1;
break;
case 2:/*在左下至右上的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y+(testnum-1);
dpos.x=1;
dpos.y=-1;
break;
case 3:/*在左上至右下的斜方向*/
pos.x=Cursor.x-(testnum-1);
pos.y=Cursor.y-(testnum-1);
dpos.x=1;
dpos.y=1;
break;
}
count=0;
for(i=0;i<testnum*2+1;i++)
{
if(pos.x>=0&&pos.x<=18&&pos.y>=0&&pos.y<=18)
{
if(gChessBoard[pos.x][pos.y]==Order)
{
count++;
if(count>=testnum)
return TRUE;
}
else
count=0;
}
pos.x+=dpos.x;
pos.y+=dpos.y;
}
return FALSE;
}
/*移动光标*/
void MoveCursor(int Order,int press)
{
switch(press)
{
case PLAY1UP:
if(Order==CHESS1&&gCursor.y>0)
gCursor.y--;
break;
case PLAY1DOWN:
if(Order==CHESS1&&gCursor.y<18)
gCursor.y++;
break;
case PLAY1LEFT:
if(Order==CHESS1&&gCursor.x>0)
gCursor.x--;
break;
case PLAY1RIGHT:
if(Order==CHESS1&&gCursor.x<18)
gCursor.x++;
break;
case PLAY2UP:
if(Order==CHESS2&&gCursor.y>0)
gCursor.y--;
break;
case PLAY2DOWN:
if(Order==CHESS2&&gCursor.y<18)
gCursor.y++;
break;
case PLAY2LEFT:
if(Order==CHESS2&&gCursor.x>0)
gCursor.x--;
break;
case PLAY2RIGHT:
if(Order==CHESS2&&gCursor.x<18)
gCursor.x++;
break;
}
gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}
/*游戏结束处理*/
void EndGame(void)
{
textmode(C80);
}
/*显示当前行棋方*/
void ShowOrderMsg(int Order)
{
gotoxy(6,MAPYOFT+20);
textcolor(LIGHTRED);
if(Order==CHESS1)
cputs("Player1 go!");
else
cputs("Player2 go!");
gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}
/*落子正确处理*/
void DoOK(void)
{
sound(500);
delay(70);
sound(600);
delay(50);
sound(1000);
delay(100);
nosound();
}
/*检查用户的按键类别*/
int CheckKey(int press)
{
if(press==ESCAPE)
return KEYEXIT;/*是退出键*/
else
if
( ( press==PLAY1DO && gPlayOrder==CHESS1) ||
( press==PLAY2DO && gPlayOrder==CHESS2)
)
return KEYFALLCHESS;/*是落子键*/
else
if
( press==PLAY1UP || press==PLAY1DOWN ||
press==PLAY1LEFT || press==PLAY1RIGHT ||
press==PLAY2UP || press==PLAY2DOWN ||
press==PLAY2LEFT || press==PLAY2RIGHT
)
return KEYMOVECURSOR;/*是光标移动键*/
else
return KEYINVALID;/*按键无效*/
}
是是香17
2007-09-22 · TA获得超过1017个赞
知道大有可为答主
回答量:2326
采纳率:0%
帮助的人:0
展开全部
#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#define KEY_UP 0x48
#define KEY_LEFT 0x4B
#define KEY_RIGHT 0x4D
#define KEY_DOWN 0x50
#define XIAZI 32

int x=320,y=230;
int who=2;
int zuobiao[10][10];
int xi=5,yi=5;
int ifover=1;
char player1[20],player2[20];
void initgr(void) /* BGI³õʼ»¯ */
{
int gd=DETECT,gm=0; /* ºÍgd=VGA,gm=VGAHIÊÇͬÑùЧ¹û */
registerbgidriver(EGAVGA_driver);/* ×¢²áBGIÇý¶¯ºó¿ÉÒÔ²»ÐèÒª.BGIÎļþµÄÖ§³ÖÔËÐÐ */
initgraph(&gd,&gm,"");
}
void drawmat(char *mat,int matsize,int x,int y,int color)
/*ÒÀ´Î£º×ÖÄ£Ö¸Õë¡¢µãÕó´óС¡¢Æðʼ×ø±ê(x,y)¡¢ÑÕÉ«*/
{int i,j,k,n;
n=(matsize-1)/8+1;
for(j=0;j<matsize;j++)
for(i=0;i<n;i++)
for(k=0;k<8;k++)
if(mat[j*n+i]&(0x80>>k)) /*²âÊÔΪ1µÄλÔòÏÔʾ*/
putpixel(x+i*8+k,y+j,color);
}
char wu24[]={
/* ÒÔÏÂÊÇ 'Îå' µÄ 24µãÕóËÎÌå ×ÖÄ££¬72 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x1F,0xFF,0xE0,0x00,
0x30,0x00,0x00,0x30,0x00,0x00,0x20,0x00,
0x00,0x20,0x00,0x00,0x20,0x00,0x00,0x20,
0x40,0x0F,0xFF,0xE0,0x00,0x60,0x40,0x00,
0x60,0x40,0x00,0x40,0x40,0x00,0x40,0x40,
0x00,0x40,0x40,0x00,0x40,0xC0,0x00,0xC0,
0xC0,0x00,0xC0,0xC0,0x00,0xC0,0xC4,0x7F,
0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,

};
char zi24[]={
/* ÒÔÏÂÊÇ '×Ó' µÄ 24µãÕóËÎÌå ×ÖÄ££¬72 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x0F,0xFF,0xF0,0x00,0x00,0x60,0x00,
0x00,0x80,0x00,0x01,0x00,0x00,0x16,0x00,
0x00,0x18,0x00,0x00,0x08,0x00,0x00,0x08,
0x0C,0x7F,0xFF,0xFE,0x00,0x08,0x00,0x00,
0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,
0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,
0x00,0x00,0x08,0x00,0x00,0x18,0x00,0x00,
0xF8,0x00,0x00,0x30,0x00,0x00,0x00,0x00,

};
char qi24[]={
/* ÒÔÏÂÊÇ 'Æå' µÄ 24µãÕóËÎÌå ×ÖÄ££¬72 byte */
0x00,0x00,0x00,0x04,0x00,0x00,0x06,0x0C,
0x30,0x04,0x08,0x20,0x04,0x08,0x20,0x04,
0x08,0x2C,0x04,0xFF,0xF0,0x3F,0xC8,0x20,
0x04,0x08,0x20,0x04,0x0F,0xE0,0x0F,0x08,
0x20,0x0D,0x88,0x20,0x0C,0x88,0x20,0x14,
0x8F,0xE0,0x14,0x08,0x20,0x24,0x08,0x24,
0x24,0xF7,0xD8,0x44,0x00,0x00,0x04,0x0C,
0x60,0x04,0x18,0x30,0x04,0x30,0x1C,0x04,
0x60,0x0C,0x04,0x80,0x04,0x00,0x00,0x00,

};
void welcome(){
int i,j;
initgr(); /* BGI³õʼ»¯ */
outtextxy(10,10,"welcome to use v1.0");
outtextxy(200,30,"welcome");
setcolor(GREEN);
setbkcolor(DARKGRAY);
drawmat(wu24,24,150,125,YELLOW);
drawmat(zi24,24,180,125,YELLOW);
drawmat(qi24,24,210,125,YELLOW);
rectangle(149,125,235,150);
outtextxy(250,110,"player1");
outtextxy(320,110,"player2");
circle(280,140,20);
circle(350,140,20);

floodfill(280,130,GREEN);
setfillstyle(1,BLUE);
floodfill(350,130,GREEN);
moveto(230,260);
outtext("intruction");
outtextxy(180,275,"1.press up to up");
outtextxy(180,285,"2.press lift to lift");
outtextxy(180,295,"3.press dowm to dowm");
outtextxy(180,305,"4.press right to right");
outtextxy(180,315,"5.press space to input and esc to exit");

outtextxy(180,325,"6.player1 use the white");
outtextxy(180,335,"7.player2 use the blue");
/***********draw line*******************/

rectangle(130,20,500,460);

getch(); /* ÔÝͣһϣ¬¿´¿´Ç°Ãæ»æͼ´úÂëµÄÔËÐнá¹û */
}
void qipan(){
int i,j;

cleardevice();
setcolor(BROWN);
setbkcolor(DARKGRAY);
setviewport(50,50,700,550,1);

for(i=120;i<520;i=i+50){
for(j=30;j<430;j=j+50){ /* »­Ò»¸ö8*8µÄÆåÅÌ */
rectangle(i,j,i+50,j+50);

}
}

}
void xiazi(){

int temp=BROWN;

switch(getch()){
case 27:
exit(0);
break;
case KEY_DOWN: /*ÅжϷ½ÏòÏÂ*/
if(y!=430){
if(zuobiao[xi][yi]==1)
{ temp=BLUE;}
if(zuobiao[xi][yi]==2)
{temp=WHITE; }

setcolor(temp);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
y=y+50;
yi=yi+1;
setcolor(GREEN);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
}

break;
case KEY_UP: /*ÅжϼüÅÌÏòÉÏ*/
if(y!=30){
if(zuobiao[xi][yi]==1)
{ temp=BLUE;}
if(zuobiao[xi][yi]==2)
{temp=WHITE; }

setcolor(temp);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
y=y-50;
yi=yi-1;
setcolor(GREEN);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
}

break; /*ÅжϼüÅÌÏò×ó*/
case KEY_LEFT:
if(x!=120){
if(zuobiao[xi][yi]==1)
{ temp=BLUE;}
if(zuobiao[xi][yi]==2)
{temp=WHITE; }

setcolor(temp);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
x=x-50;
xi=xi-1;
setcolor(GREEN);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
}
break;
case KEY_RIGHT: /*ÅжϼüÅÌÏòÓÒ*/
if(x!=520){
if(zuobiao[xi][yi]==1)
{ temp=BLUE;}
if(zuobiao[xi][yi]==2)
{temp=WHITE; }

setcolor(temp);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
x=x+50;
xi=xi+1;
setcolor(GREEN);
line(x,y-10,x,y+10);
line(x-10,y,x+10,y);
}

break;
case XIAZI:
if(zuobiao[xi][yi]==0){ /**/
/*ÅжÏË­ÏÂ×Ó*/
if(who==1){
who=who+1;
setcolor(BLUE);
circle(x,y,18);
setfillstyle(1,BLUE); /*»­Ò»¸ö°ë¾¶Îª18µÄlanÉ«µÄµã*/
floodfill(x,y,BLUE);
zuobiao[xi][yi]=1;
ifwin();
break;
}
if(who==2){
who=who-1;
setcolor(WHITE);
circle(x,y,18);
setfillstyle(1,WHITE); /*»­Ò»¸ö°ë¾¶Îª18µÄlvÉ«µÄµã*/
floodfill(x,y,WHITE);
zuobiao[xi][yi]=2;
ifwin();
break;
}
}
else
break;

}

}

void over(){
cleardevice();
circle(100,100,50);
circle(75,70,10);
circle(120,70,10);
putpixel(75,70,GREEN);
putpixel(120,70,GREEN);
setcolor(GREEN);
line(80,110,115,100);
moveto(200,200);
printf(" game over");
if(who==1){
printf(" %s win",player1);
}
else
printf(" %s win",player2);
getch();

}
/*ÅжÏÊÇ·ñʤÀû*/
int ifwin(){
int i=0;
int num=1;
for(i=1;i<10;i++){
if(xi+i<=10||yi+i<=10){
if(zuobiao[xi][yi]==zuobiao[xi+i][yi+i])
num=num+1;

}
if(xi-i>=1||yi-i>=1){
if(zuobiao[xi][yi]==zuobiao[xi-i][yi-i]) /*ÅжÏÊÇ·ñ5×ÓÁ¬ÔÚÒ»Æð*/
num=num+1;

}
}
if(num==5){
over();
ifover=0;
return;
}
num=1;
for(i=1;i<10;i++){
if(xi+i<=10){
if(zuobiao[xi][yi]==zuobiao[xi+i][yi])
num=num+1;

}
if(xi-i>=1){
if(zuobiao[xi][yi]==zuobiao[xi-i][yi])
num=num+1;

}
}
if(num==5){
over();ifover=0;return;
}

num=1;
for(i=1;i<10;i++){
if(yi+i<=10){
if(zuobiao[xi][yi]==zuobiao[xi][yi+i])
num=num+1;

}
if(yi-i>=1){
if(zuobiao[xi][yi]==zuobiao[xi][yi-i])
num=num+1;

}
}
if(num==5){
over();ifover=0; return;
}
num=1;
for(i=1;i<10;i++){
if(xi+i<=10||yi-i>=1){
if(zuobiao[xi][yi]==zuobiao[xi+i][yi-i])
num=num+1;

}
if(xi-i>=1||yi+i<=10){
if(zuobiao[xi][yi]==zuobiao[xi-i][yi+i])
num=num+1;

}
}
if(num==5){
over();ifover=0; return;
}
}
void player(){
int i;
printf("verson 1.0");
window(10,5,70,20); /*»­Ò»¸ö·½¿ò±³¾°ÑÕÉ«ÊÇÂÌÉ«*/
textcolor(BLACK);
textbackground(LIGHTGRAY);
clrscr();
gotoxy(15,4);
cputs("Input your name");
gotoxy(15,7);
cputs("player1:");
gotoxy(15,9);
cputs("player2:");
gotoxy(24,7);
scanf("%s",player1);
gotoxy(24,9);
scanf("%s",player2);
}
void main(){
int i,j;
player();
welcome(); /*µ÷Óû¶Ó­½çÃæ*/

while(1){

for(i=0;i<10;i++){
for(j=0;j<10;j++){
zuobiao[i][j]=0;
}
}
ifover=1;
clrscr();
qipan(); /*µ÷ÓóöÆåÅ̵ÄͼÏó*/

moveto(x,y);
setcolor(GREEN);
line(x,y-10,x,y+10); /*Ê×Ïȹ涨³ö¸Õ¿ªÊ¼¹â±êµÄλÖÃ*/
line(x-10,y,x+10,y);
do{
if(who==2)
{
setcolor(RED);
rectangle(120,6,270,18);
setfillstyle(1,YELLOW); /*ÅжϸÃÄĸöÓû§ÏÂ×Ó*/
floodfill(121,9,RED);
setcolor(GREEN);
outtextxy(125,8,player1);
}
else
{setcolor(RED);
rectangle(120,6,270,18);
setfillstyle(1,YELLOW);
floodfill(121,9,RED);
setcolor(GREEN);
outtextxy(125,8,player2);
}
xiazi(); /*ÅжϼüÅ̵ÄÊäÈëÇé¿ö*/

}while(ifover);
}
}

参考资料: http://post.baidu.com/f?kz=109233471

本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
奇侠000
2007-09-22
知道答主
回答量:15
采纳率:0%
帮助的人:0
展开全部
#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#define KEY_UP 0x48
#define KEY_LEFT 0x4B
#define KEY_RIGHT 0x4D
#define KEY_DOWN 0x50
#define XIAZI 32

int x=320,y=230;
int who=2;
int zuobiao[10][10];
int xi=5,yi=5;
int ifover=1;
char player1[20],player2[20];
void initgr(void) /* BGI³õʼ»¯ */
{
int gd=DETECT,gm=0; /* ºÍgd=VGA,gm=VGAHIÊÇͬÑùЧ¹û */
registerbgidriver(EGAVGA_driver);/* ×¢²áBGIÇý¶¯ºó¿ÉÒÔ²»ÐèÒª.BGIÎļþµÄÖ§³ÖÔËÐÐ */
initgraph(&gd,&gm,"");
}
void drawmat(char *mat,int matsize,int x,int y,int color)
/*ÒÀ´Î£º×ÖÄ£Ö¸Õë¡¢µãÕó´óС¡¢Æðʼ×ø±ê(x,y)¡¢ÑÕÉ«*/
{int i,j,k,n;
n=(matsize-1)/8+1;
for(j=0;j<matsize;j++)
for(i=0;i<n;i++)
for(k=0;k<8;k++)
if(mat[j*n+i]&(0x80>>k)) /*²âÊÔΪ1µÄλÔòÏÔʾ*/
putpixel(x+i*8+k,y+j,color);
}
char wu24[]={
/* ÒÔÏÂÊÇ 'Îå' µÄ 24µãÕóËÎÌå ×ÖÄ££¬72 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x1F,0xFF,0xE0,0x00,
0x30,0x00,0x00,0x30,0x00,0x00,0x20,0x00,
0x00,0x20,0x00,0x00,0x20,0x00,0x00,0x20,
0x40,0x0F,0xFF,0xE0,0x00,0x60,0x40,0x00,
0x60,0x40,0x00,0x40,0x40,0x00,0x40,0x40,
0x00,0x40,0x40,0x00,0x40,0xC0,0x00,0xC0,
0xC0,0x00,0xC0,0xC0,0x00,0xC0,0xC4,0x7F,
0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,

};
char zi24[]={
/* ÒÔÏÂÊÇ '×Ó' µÄ 24µãÕóËÎÌå ×ÖÄ££¬72 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x0F,0xFF,0xF0,0x00,0x00,0x60,0x00,
0x00,0x80,0x00,0x01,0x00,0x00,0x16,0x00,
0x00,0x18,0x00,0x00,0x08,0x00,0x00,0x08,
0x0C,0x7F,0xFF,0xFE,0x00,0x08,0x00,0x00,
0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,
0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,
0x00,0x00,0x08,0x00,0x00,0x18,0x00,0x00,
0xF8,0x00,0x00,0x30,0x00,0x00,0x00,0x00,

};
char qi24[]={
/* ÒÔÏÂÊÇ 'Æå' µÄ 24µãÕóËÎÌå ×ÖÄ££¬72 byte */
0x00,0x00,0x00,0x04,0x00,0x00,0x06,0x0C,
0x30,0x04,0x08,0x20,0x04,0x08,0x20,0x04,
0x08,0x2C,0x04,0xFF,0xF0,0x3F,0xC8,0x20,
0x04,0x08,0x20,0x04,0x0F,0xE0,0x0F,0x08,
0x20,0x0D,0x88,0x20,0x0C,0x88,0x20,0x14,
0x8F,0xE0,0x14,0x08,0x20,0x24,0x08,0x24,
0x24,0xF7,0xD8,0x44,0x00,0x00,0x04,0x0C,
0x60,0x04,0x18,0x30,0x04,0x30,0x1C,0x04,

作者: 小黑波 2006-6-25 01:48 回复此发言

--------------------------------------------------------------------------------

2 ◆◆◆五子棋◆◆◆
0x60,0x0C,0x04,0x80,0x04,0x00,0x00,0x00,

};
void welcome(){
int i,j;
initgr(); /* BGI³õʼ»¯ */
outtextxy(10,10,"welcome to use v1.0");
outtextxy(200,30,"welcome");
setcolor(GREEN);
setbkcolor(DARKGRAY);
drawmat(wu24,24,150,125,YELLOW);
drawmat(zi24,24,180,125,YELLOW);
drawmat(qi24,24,210,125,YELLOW);
rectangle(149,125,235,150);
outtextxy(250,110,"player1");
outtextxy(320,110,"player2");
circle(280,140,20);
circle(350,140,20);

floodfill(280,130,GREEN);
setfillstyle(1,BLUE);
floodfill(350,130,GREEN);
moveto(230,260);
outtext("intruction");
outtextxy(180,275,"1.press up to up");
outtextxy(180,285,"2.press lift to lift");
outtextxy(180,295,"3.press dowm to dowm");
outtextxy(180,305,"4.press right to right");
outtextxy(180,315,"5.press space to input and esc to exit");

outtextxy(180,325,"6.player1 use the white");
outtextxy(180,335,"7.player2 use the blue");
/***********draw line*******************/

rectangle(130,20,500,460);

getch(); /* ÔÝͣһϣ¬¿´¿´Ç°Ãæ»æͼ´úÂëµÄÔËÐнá¹û */
}
void qipan(){
int i,j;

cleardevice();
setcolor(BROWN);
setbkcolor(DARKGRAY);
setviewport(50,50,700,550,1);

for(i=120;i<520;i=i+50){
for(j=30;j<430;j=j+50){ /* »­Ò»¸ö8*8µÄÆåÅÌ */
rectangle(i,j,i+50,j+50);

}
}

}
void xiazi(){

int temp=BROWN;

switch(getch()){
case 27:
exit(0);
break;
case KEY_DOWN: /*ÅжϷ½ÏòÏÂ*/
if(y!=430){
if(zuobiao[xi][yi]==1)
{ temp=BLUE;}
if(zuobiao[xi][yi]==2)
{temp=WHITE; }
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
过气程序员
2007-09-26
知道答主
回答量:7
采纳率:0%
帮助的人:0
展开全部
我曾经做过一个,比较复杂,如果你要的话可以发给你
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友6452b3628
2007-09-22 · TA获得超过1.7万个赞
知道大有可为答主
回答量:4881
采纳率:0%
帮助的人:5301万
展开全部
去百度贴吧,C语言吧找,那里有现成的。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式