[原创]游戏color linz

作者在 2007-02-15 00:22:00 发布以下内容

/*==============================================================================
 SK-CHINA 2006-2007 COLOR LINE BY S.K
==============================================================================*/
/*==============================================================================
 预处理部分
==============================================================================*/

#define NEO_temp_dir_unused
#define BOARD_COLOR 7

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "neo.h"

/*==============================================================================
 全局变量部分
==============================================================================*/

char chesscolor[9][9]; /* 定义棋盘棋子颜色 */
char chessboard[9][9]; /* 定义棋盘空位 */
long grade; /* 分数 */

/*==============================================================================
 函数部分
==============================================================================*/
/*==============================================================================
 检查棋盘是否已满 满返回1,不满返回0.
==============================================================================*/

int boardfull(void) {
  int i,t; /* 临时计数 */
  for(i=0;i<9;i++)
    for(t=0;t<9;t++) if(chessboard[t]==1) return 0;
  return 1;
}

/*==============================================================================
 随机生成棋子.
==============================================================================*/

void buildchess(void) {
  int x,y;
  do {
    x=rand()%9;
    y=rand()%9;
  }while(chesscolor[y][x]!=0);
  chesscolor[y][x]=rand()%7+1;
  chessboard[y][x]=0;
  delchess(y,x);
}

/*==============================================================================
 绘制整个棋盘(包括棋子).
==============================================================================*/

void drawboard(void) {
  int i,t; /* 临时计数 */
  for(i=20;i<420;i+=40) hline(20,i,380,BOARD_COLOR);
  for(i=20;i<420;i+=40) vline(i,20,380,BOARD_COLOR);
  for(i=0;i<9;i++)
    for(t=0;t<9;t++)
      circlefill(t*40+40,i*40+40,12,chesscolor[t]);
}

/*==============================================================================
 判断位于第x行,y列的棋子是否能移动到第to_x行,to_y列,可以返回1,否则返回0.
==============================================================================*/

int canmove(int x,int y,int to_x,int to_y) {
  if(x==to_x && y==to_y) return 1;
  chessboard[x][y]=0;
  if(chessboard[x+1][y] && x<8)
    if(canmove(x+1,y,to_x,to_y)) {
      chessboard[x][y]=1;
      return 1;
    }
  if(chessboard[x-1][y] && x>0)
    if(canmove(x-1,y,to_x,to_y)) {
      chessboard[x][y]=1;
      return 1;
    }
  if(chessboard[x][y+1] && y<8)
    if(canmove(x,y+1,to_x,to_y)) {
      chessboard[x][y]=1;
      return 1;
    }
  if(chessboard[x][y-1] && y>0)
    if(canmove(x,y-1,to_x,to_y)) {
      chessboard[x][y]=1;
      return 1;
    }
  chessboard[x][y]=1;
  return 0;
}

/*==============================================================================
 判断新增棋子后是否可以消去棋子,可以则消去并返回1,否则返回0.
====================================================================

原创作品 | 阅读 4146 次
文章评论,共1条
卧龙孔明(作者)
2007-02-27 01:05
1
编译所需neo库请到
http://sunkai.b.lunqun.com/read-htm-tid-100274.html
下载
游客请输入验证码