c语言五子棋代码,

c语言五子棋代码,,第1张

package day17.gobang

import java.util.Arrays

public class GoBangGame {

public static final char BLANK='*'

public static final char BLACK='@'

public static final char WHITE='O'

public static final int MAX = 16

private static final int COUNT = 5

//棋盘

private char[][] board

public GoBangGame() {

}

//开始游戏

public void start() {

board = new char[MAX][MAX]

//把二维数组蚂洞都填充‘*’

for(char[] ary: board){

Arrays.fill(ary, BLANK)

}

}

public char[][] getChessBoard(){

return board

}

public void addBlack(int x, int y) throws ChessExistException{

//@

//char blank = '*'

//System.out.println( x +"," + y + ":" + board[y][x] + "," + BLANK)

if(board[y][x] == BLANK){// x, y 位置上必须是空的才可以添棋子

board[y][x] = BLACK

return

}

throw new ChessExistException("已经有棋子了!")

}

public void addWhite(int x, int y)

throws ChessExistException{

if(board[y][x] == BLANK){// x, y 位置上必须是空的才可以添棋子

board[y][x] = WHITE

return

}

throw new ChessExistException("已经有棋子了!")

}

//chess 棋子:'@'/'O'

public boolean winOnY(char chess, int x, int y){

//先找到y方向第一个不是 blank的棋子

int top = y

while(true){

if(y==0 || board[y-1][x]!=chess){

//如果y已经是闷厅枯棋盘的边缘, 或者的前一个不是chess

//就不再继续查找了

break

}

y--

top = y

}

//向回统计所有chess的个数,如果是COUNT个就赢了

int count = 0

y = top

while(true){

if(y==MAX || board[y][x]!=chess){

//如果找到头 或者 下一个子不是chess 就不再继续统计了

break

}

count++

y++

}

return count==COUNT

}

//chess 棋子:'@'/'O'

public boolean winOnX(char chess, int x, int y){

//先找到x方向第一个不是 blank的棋子

int top = x

while(true){

if(x==0 || board[y][x-1]!=chess){

//如果x已经是棋盘的边缘, 或者的前一伏空个不是chess

//就不再继续查找了

break

}

x--

top = x

}

//向回统计所有chess的个数,如果是COUNT个就赢了

int count = 0

x = top

while(true){

if(x==MAX || board[y][x]!=chess){

//如果找到头 或者 下一个子不是chess 就不再继续统计了

break

}

count++

x++

}

return count==COUNT

}

//chess 棋子:'@'/'O'

public boolean winOnXY(char chess, int x, int y){

//先找MAX向第一个不是 blank的棋子

int top = y

int left = x

while(true){

if(x==0 || y==0 || board[y-1][x-1]!=chess){

//如果x已经是棋盘的边缘, 或者的前一个不是chess

//就不再继续查找了

break

}

x--

y--

top = y

left=x

}

//向回统计所有chess的个数,如果是COUNT个就赢了

int count = 0

x = left

y = top

while(true){

if(x==MAX || y==MAX || board[y][x]!=chess){

//如果找到头 或者 下一个子不是chess 就不再继续统计了

break

}

count++

x++

y++

}

return count==COUNT

}

//chess 棋子:'@'/'O'

public boolean winOnYX(char chess, int x, int y){

//先找到x方向第一个不是 blank的棋子

int top = y

int left = x

while(true){

if(x==MAX-1 || y==0 || board[y-1][x+1]!=chess){

//如果x已经是棋盘的边缘, 或者的前一个不是chess

//就不再继续查找了

break

}

x++

y--

top = y

left=x

}

//向回统计所有chess的个数,如果是COUNT个就赢了

int count = 0

x = left

y = top

while(true){

if(x==0 || y==MAX || board[y][x]!=chess){

//如果找到头 或者 下一个子不是chess 就不再继续统计了

break

}

count++

x--

y++

}

return count==COUNT

}

public boolean whiteIsWin(int x, int y) {

//在任何一个方向上赢了,都算赢

return winOnY(WHITE, x, y) ||

winOnX(WHITE, x, y) ||

winOnXY(WHITE, x, y) ||

winOnYX(WHITE, x, y)

}

public boolean blackIsWin(int x, int y) {

return winOnY(BLACK, x, y) ||

winOnX(BLACK, x, y) ||

winOnXY(BLACK, x, y) ||

winOnYX(BLACK, x, y)

}

}

接上面中国象棋代码:

if( check_turn == 12)    //相的走法规范

       { if((x == check_x &厅晌&y == check_y))

            {temp = turn temp1 = turn1 turn = 'O' turn1 = 'N' num--

              printf("三思而后行\n")printf("还是你的回合")Sleep(500)

             }

         else if( x >= 15 &&(abs(y - check_y) == 8 &&abs(x - check_x) == 4))

             {if((x == 22 &&(y == 11 || y == 27))||(x == 18 &&

                ( y == 3 || y == 19 || y == 35)) ||(x == 14 &&(y == 11|| y ==27)))

                    { if( map[(x+check_x)/2][(y+check_y)/2] == '+')                                                  check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

                      else {printf("棋子卡住,不可执行")Sleep(500)}  }

                     else {printf("不合法下法\n")Sleep(500)}

                  }

                else {printf("不合法的下法\n")Sleep(500)}

              }

       if( check_turn == 13)    //士的走法规范

          { if((x == check_x &&y == check_y))

              {temp = turn temp1 = turn1 turn = 'O' turn1 = 'N' num--

               printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

    else if( abs(x - check_x)== 2 &&abs( y - check_y) == 4 &&((x==22 &&(y == 15

        || y == 23)) || ( x == 20 &&y == 19) || ( x == 18 &&( y == 15 || y == 23))))                      {check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)}

     else { printf("不合法的下法\n")Sleep(500)}   }

     if( check_turn == 14)    //将的走法规范

         { if((x == check_x &&y == check_y))

              { temp = turn temp1 = turn1 turn = 'O' turn1 = 'N' num--

                 printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

else if( ((abs(x - check_x)== 2 &&abs( y - check_y) == 0 )|| (abs(x - check_x)== 0

  &&abs( y - check_y) == 4)) &&x >= 18 &&x <= 22 &&y >= 15 &&y <= 23 )

        { check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)}

           else { printf("不合法的下法\n")Sleep(500)}   }

if( check_turn == 15)       //炮的走法规范

 滚伏液    { if((x == check_x &&y == check_y))

        {  temp = turn 大物temp1 = turn1 turn = 'O' turn1 = 'N' num--

           printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

       else if( y == check_y )

            { int check_pao = 0

              if( x >check_x)

                 { for(j = check_x + 2j<= x j = j+ 2)

                    { if(map[j][y] == '+' ) else  check_pao++}

                  if(check_pao == 1&&temp == '+')   // 直线行走但不可吃棋子                                 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

                else if( check_pao == 2 &&temp != '+')  //跳跃吃棋                                                 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

               else { printf("不合法的下法\n")Sleep(500)}  }

            else { for(j = check_x - 2j>= xj = j - 2)

             { if(map[j][y] == '+' ) else { check_pao++} }

                if(check_pao == 1&&temp == '+')   //直线行走但不可吃棋子                                  check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

                 else if( check_pao == 2 &&temp != '+')   //跳跃吃棋                                            check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

              else { printf("不合法的下法\n")Sleep(500)}  }

             }

           else if( x == check_x )

             { int check_pao = 0

                if( y >check_y)

                   { for(j = check_y + 4j<= y j = j+4)

                      { if(map[x][j] == '+' ) else    check_pao++}

                   if(check_pao == 1&&temp == '+')  //直线行走但不可吃棋子                                   check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

                 else if( check_pao == 2 &&temp != '+')   //跳跃吃棋                                                 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

                 else { printf("不合法的下法\n")Sleep(500)}  }

              else {for(j = check_y - 4j>= yj = j - 4)

                  {if(map[x][j] == '+' ) else  check_pao++}

                     if(check_pao == 1&&temp == '+')  //直线行走但不可吃棋子                                  check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

               else if( check_pao == 2 &&temp != '+')   //跳跃吃棋                                                    check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

               else { printf("不合法的下法\n")Sleep(500)}  }

            }

          else { printf("不合法的下法\n")Sleep(500)}

         }

       if( check_turn == 16)    //卒的走法规范

          { if ( x >= 14)

          { if((x == check_x &&y == check_y))

              {  temp = turn temp1 = turn1 turn = 'O' turn1 = 'N' num--

                 printf("三思而后行\n")printf("还是你的回合") Sleep(500)  }

    else if( x == check_x - 2 &&y == check_y)                                                     check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

  else { printf("不合法的下法\n")Sleep(500)}

}

else{ if((x == check_x &&y == check_y))

  {  temp = turn temp1 = turn1 turn = 'O' turn1 = 'N' num--

    printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

else if((x - check_x == 0 &&abs(y-check_y) ==4) ||( x - check_x == -2

        &&abs(y-check_y) == 0))                                           check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

else { printf("不合法的下法\n")Sleep(500)}   }

  }

}

else  { if( check_turn == 20)  //车的走法规范 (帅方)

  { if((x == check_x &&y == check_y))

     {  temp = turn temp1 = turn1turn = 'O'turn1 = 'N' num--

        printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

else if( y == check_y )

     { if( x >check_x)

       { for(j = check_x + 2j <xj = j + 2)

         { if(map[j][y] == '+')else {printf("不合法的下法\n")Sleep(500)break} }

  if( j >= x) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

  }

if( x <check_x)

    { for(j = check_x - 2j >xj = j - 2)

       { if(map[j][y] == '+')else { printf("不合法的下法\n")Sleep(500)break} }

if( j <= x) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

}

}

else if(  x == check_x  )

   { if( y >check_y)

     { for(j = check_y + 4j <yj = j + 4)

      { if(map[x][j] == '+')else { printf("不合法的下法\n")Sleep(500)break} }

   if( j >= y) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

  }

if( y <check_y)

   { for(j = check_y - 4j >yj = j - 4)

     { if(map[x][j] == '+')else { printf("不合法的下法\n")Sleep(500)break} }

if( j <= y) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

  }

}

else { printf("不合法的下法\n")Sleep(500)}

}

if( check_turn == 21)    //马的走法规范

   { if((x == check_x &&y == check_y))

     { temp = turntemp1 = turn1turn = 'O'turn1 = 'N'num--

        printf("三思而后行\n")printf("还是你的回合")Sleep(500)}

  else if( (abs( x - check_x) == 2&&abs( y - check_y) == 8)&&

        map[check_x][(y+check_y)/2] =='+')

      { check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)}

else if( (abs( x - check_x) == 4&&abs( y - check_y) == 4)&&

      map[(x + check_x)/2][check_y] == '+' )

   { check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)}

else { printf("不合法的下法\n")Sleep(500)}  }

  if( check_turn == 22)    //相的走法规范

   { if((x == check_x &&y == check_y))

      { temp = turntemp1 = turn1turn = 'O'turn1 = 'N'num--

         printf("三思而后行\n")printf("还是你的回合")Sleep(500)}

     else if( x <= 12 &&(abs(y - check_y) == 8 &&abs(x - check_x) == 4))

     { if((x == 4 &&(y == 11 || y == 27))||(x == 8 &&( y == 3 || y == 19 || y == 35))

       ||(x == 12 &&(y == 11|| y ==27)))

       {  if( map[(x+check_x)/2][(y+check_y)/2] == '+')                                                   check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

   else { printf("棋子卡住,不可执行")Sleep(500)}  }

else {printf("不合法的下法\n")Sleep(500)}

}

else { printf("不合法的下法\n")Sleep(500)}  }

if( check_turn == 23)    //士的走法规范

  { if((x == check_x &&y == check_y))

     { temp = turntemp1 = turn1turn = 'O'turn1 = 'N'num--

         printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

   else if( abs(x - check_x)== 2 &&abs( y - check_y) == 4 &&((x==4 &&

(y == 15 || y == 23)) || ( x == 6 &&y == 19) || ( x == 8 &&( y == 15 || y == 23))))

     { check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)}

     else { printf("不合法的下法\n")Sleep(500)}  }

  if( check_turn == 24)    //将的走法规范

   { if((x == check_x &&y == check_y))

      { temp = turntemp1 = turn1turn = 'O'turn1 = 'N'num--

         printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

   else if( ((abs(x - check_x)== 2 &&abs( y - check_y) == 0 )|| (abs(x - check_x)== 0   &&abs( y - check_y) == 4)) &&x >= 4 &&x <= 8 &&y >= 15 &&y <= 23 )

   { check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)}

  else {printf("不合法的下法\n")Sleep(500)}  }

  if( check_turn == 25)    //炮的走法规范

     { if((x == check_x &&y == check_y))

         { temp = turn temp1 = turn1turn = 'O'turn1 = 'N'num--

             printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

      else if( y == check_y )

          { int check_pao = 0

            if( x >check_x)

              { for(j = check_x + 2j<= x j = j+ 2)

                { if(map[j][y] == '+' ) else      check_pao++}

                 if(check_pao == 1&&temp == '+')   //直线行走但不可吃棋子                                 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

     else if( check_pao == 2 &&temp != '+')   //跳跃吃棋                                                       check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

     else { printf("不合法的下法\n")Sleep(500)}  }

     else { for(j = check_x - 2j>= xj = j - 2)

        { if(map[j][y] == '+' ) else { check_pao++} }

            if(check_pao == 1&&temp== '+')   //直线行走但不可吃棋子                                   check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

       else if( check_pao == 2 &&temp != '+')   //跳跃吃棋                                                      check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

    else { printf("不合法的下法\n")Sleep(500)}  }

  }

else if( x == check_x )

    { int check_pao = 0

         if( y >check_y)

            { for(j = check_y + 4j<= y j = j+4)

                { if(map[x][j] == '+' ) else check_pao++}

           if(check_pao == 1&&temp == '+')   //直线行走但不可吃棋                                              check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

         else if( check_pao == 2 &&temp != '+')   //跳跃吃棋                                                 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

         else { printf("不合法的下法\n")Sleep(500)}  }

     else { for(j = check_y - 4 j>= yj = j - 4)

         { if(map[x][j] == '+' ) else  check_pao++}

            if(check_pao ==1&&temp == '+')   //直线行走但不可吃棋子                                     check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

     else if( check_pao == 2&&temp != '+')  //跳跃吃棋                                                       check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

      else { printf("不合法的下法\n")Sleep(500)}  }

    }

  else { printf("不合法的下法\n")Sleep(500)}

   }

   if( check_turn == 26)  //卒的走法规范

      { if( x <= 12)

        { if((x == check_x &&y == check_y))

          { temp = turntemp1 = turn1turn = 'O'turn1 = 'N'num--

             printf("三思而后行\n")printf("还是你的回合")Sleep(500)}

    else if( x == check_x + 2 &&y == check_y)                                               check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

  else { printf("不合法的下法\n")Sleep(500)}  }

  else{ if((x == check_x &&y == check_y))

     { temp = turntemp1 = turn1turn = 'O'turn1 = 'N'num--

        printf("三思而后行\n")printf("还是你的回合")Sleep(500)  }

  else if((x - check_x == 0 &&abs(y-check_y) ==4) ||( x - check_x == 2

      &&abs(y-check_y) == 0))                                                       check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map)

else { printf("不合法的下法\n")Sleep(500)}   }

   }

  }

}

}

system("cls")

if( if_return) return

for(i = 0i <27i++)puts(map[i])

}

Sleep(5000)

}

int main( )

{ while(1)

    { xiangqi( )

      printf("\n  重来,请按键.\n")

      getch( )

    }

  return 0

}

这是我从知道上找到的:

#include<stdio.h>

#include<stdlib.h>

#include<graphics.h>

#include<bios.h>

#include<conio.h>

#define LEFT 0x4b00

#define RIGHT 0x4d00

#define DOWN 0x5000

#define UP 0x4800

#define ESC 0x011b

#define SPACE 0x3920

#define BILI 20

#define JZ 4

#define JS 3

#define N 19

int box[N][N]

int step_x,step_y

int key

int flag=1

void draw_box()

void draw_cicle(int x,int y,int color)

void change()

void judgewho(int x,int y)

void judgekey()

int judgeresult(int x,int y)

void attentoin()

void attention()

{

char ch

window(1,1,80,25)

textbackground(LIGHTBLUE)

textcolor(YELLOW)

clrscr()

gotoxy(15,2)

printf("游戏 *** 作规则:")

gotoxy(15,4)

printf("Play Rules:")

gotoxy(15,6)

printf("1、按左右上下方向键移动棋子")

gotoxy(15,8)

printf("烂友手1. Press Left,Right,Up,Down Key to move Piece")

gotoxy(15,10)

printf("2、按空格确定落棋子")

gotoxy(15,12)

printf("2. Press Space to place the Piece"饥嫌)

gotoxy(15,14)

printf("3、禁止告誉在棋盘外按空格")

gotoxy(15,16)

printf("3. DO NOT press Space outside of the chessboard")

gotoxy(15,18)

printf("你是否接受上述的游戏规则(Y/N)")

gotoxy(15,20)

printf("Do you accept the above Playing Rules? [Y/N]:")

while(1)

{

gotoxy(60,20)

ch=getche()

if(ch=='Y'||ch=='y')

break

else if(ch=='N'||ch=='n')

{

window(1,1,80,25)

textbackground(BLACK)

textcolor(LIGHTGRAY)

clrscr()

exit(0)

}

gotoxy(51,12)

printf(" ")

}

}

void draw_box()

{

int x1,x2,y1,y2

setbkcolor(LIGHTBLUE)

setcolor(YELLOW)

gotoxy(7,2)

printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.")

for(x1=1,y1=1,y2=18x1<=18x1++)

line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI)

for(x1=1,y1=1,x2=18y1<=18y1++)

line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI)

for(x1=1x1<=18x1++)

for(y1=1y1<=18y1++)

box[x1][y1]=0

}

void draw_circle(int x,int y,int color)

{

setcolor(color)

setlinestyle(SOLID_LINE,0,1)

x=(x+JZ)*BILI

y=(y+JS)*BILI

circle(x,y,8)

}

void judgekey()

{

int i

int j

switch(key)

{

case LEFT :

if(step_x-1<0)

break

else

{

for(i=step_x-1,j=step_yi>=1i--)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(i<1)break

step_x=i

judgewho(step_x,step_y)

break

}

case RIGHT :

if(step_x+1>18)

break

else

{

for(i=step_x+1,j=step_yi<=18i++)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(i>18)break

step_x=i

judgewho(step_x,step_y)

break

}

case DOWN :

if((step_y+1)>18)

break

else

{

for(i=step_x,j=step_y+1j<=18j++)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(j>18)break

step_y=j

judgewho(step_x,step_y)

break

}

case UP :

if((step_y-1)<0)

break

else

{

for(i=step_x,j=step_y-1j>=1j--)

if(box[i][j]==0)

{

draw_circle(step_x,step_y,LIGHTBLUE)

break

}

if(j<1)break

step_y=j

judgewho(step_x,step_y)

break

}

case ESC :

break

case SPACE :

if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)

{

if(box[step_x][step_y]==0)

{

box[step_x][step_y]=flag

if(judgeresult(step_x,step_y)==1)

{

sound(1000)

delay(1000)

nosound()

gotoxy(30,4)

if(flag==1)

{

setbkcolor(BLUE)

cleardevice()

setviewport(100,100,540,380,1)

/*定义一个图形窗口*/

setfillstyle(1,2)

/*绿色以实填充*/

setcolor(YELLOW)

rectangle(0,0,439,279)

floodfill(50,50,14)

setcolor(12)

settextstyle(1,0,5)

/*三重笔划字体, 水平放?5倍*/

outtextxy(20,20,"The White Win !")

setcolor(15)

settextstyle(3,0,5)

/*无衬笔划字体, 水平放大5倍*/

outtextxy(120,120,"The White Win !")

setcolor(14)

settextstyle(2,0,8)

getch()

closegraph()

exit(0)

}

if(flag==2)

{

setbkcolor(BLUE)

cleardevice()

setviewport(100,100,540,380,1)

/*定义一个图形窗口*/

setfillstyle(1,2)

/*绿色以实填充*/

setcolor(YELLOW)

rectangle(0,0,439,279)

floodfill(50,50,14)

setcolor(12)

settextstyle(1,0,8)

/*三重笔划字体, 水平放大8倍*/

outtextxy(20,20,"The Red Win !")

setcolor(15)

settextstyle(3,0,5)

/*无衬笔划字体, 水平放大5倍*/

outtextxy(120,120,"The Red Win !")

setcolor(14)

settextstyle(2,0,8)

getch()

closegraph()

exit(0)

}

}

change()

break

}

}

else

break

}

}

void change()

{

if(flag==1)

flag=2

else

flag=1

}

void judgewho(int x,int y)

{

if(flag==1)

draw_circle(x,y,15)

if(flag==2)

draw_circle(x,y,4)

}

int judgeresult(int x,int y)

{

int j,k,n1,n2

while(1)

{

n1=0

n2=0

/*水平向左数*/

for(j=x,k=yj>=1j--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*水平向右数*/

for(j=x,k=yj<=18j++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

/*垂直向上数*/

n1=0

n2=0

for(j=x,k=yk>=1k--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*垂直向下数*/

for(j=x,k=yk<=18k++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

/*向左上方数*/

n1=0

n2=0

for(j=x,k=yj>=1,k>=1j--,k--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*向右下方数*/

for(j=x,k=yj<=18,k<=18j++,k++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

/*向右上方数*/

n1=0

n2=0

for(j=x,k=yj<=18,k>=1j++,k--)

{

if(box[j][k]==flag)

n1++

else

break

}

/*向左下方数*/

for(j=x,k=yj>=1,k<=18j--,k++)

{

if(box[j][k]==flag)

n2++

else

break

}

if(n1+n2-1>=5)

{

return(1)

break

}

return(0)

break

}

}

void main()

{

int gdriver=VGA,gmode=VGAHI

clrscr()

attention()

initgraph(&gdriver,&gmode,"c:\\tc")

/* setwritemode(XOR_PUT)*/

flag=1

draw_box()

do

{

step_x=0

step_y=0

/*draw_circle(step_x,step_y,8)*/

judgewho(step_x-1,step_y-1)

do

{

while(bioskey(1)==0)

key=bioskey(0)

judgekey()

}

while(key!=SPACE&&key!=ESC)

}

while(key!=ESC)

closegraph()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12491689.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存