• 大小: 14KB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: 其他
  • 标签: linux  五子棋  

资源简介

完成品,很诡异的电脑,一般人都下不赢。是在linux下面用GCC直接编译,在终端执行的。

资源截图

代码片段和文件信息

#include 
#include 
#include “curses.h“
#include “zifu.h“

#define CURRENT_ATTRIBUTE C_ATTR(g_style g_fore_colorg_back_color)

#define WHITE 1 //棋子颜色
#define BLACK 0

#define LEFTBORDER 44 //棋盘左边界
#define RIGHTBORDER 108 //棋盘右边界
#define MIDDLE (int)(RIGHTBORDER+LEFTBORDER)/2 //棋盘列数的中点

int div[][2]={{-1-1}{-10}{-11}{01}{11}{10}{1-1}{0-1}}; //方向向量

WINDOW* g_win = NULL;

int g_style = A_BOLD;

/******************************************************************/
/************************功能函数实现******************************/
/******************************************************************/

/*init_graphics***************************************/
/*
函数原型:bool init_graphics(void)
函数功能:初始化屏幕(配置当前地域、进入curses模式、设置输入、启用彩色机制并初始化颜色、隐藏鼠标、初始化背景色并绘制背景)
函数参数:无
函数返回值:false:初始化屏幕失败
      true:初始化屏幕成功
用到自定义函数:clear_screen
*/
bool init_graphics(void) //初始化屏幕函数
{
setlocale(LC_ALL ““);

     g_win=initscr();     
if(g_win==NULL)
{
printf(“call initscr() failed!\n“);
return false;
}
cbreak(); //cbreak()模式开启后,除delete或ctrl等仍被视为特殊字元外一切字元立刻被读取。nocbreak是关闭
noecho(); //用来控制输入的字元是否显示在终端上,系统预设是开启。echo是开启

//keypad(g_winTRUE);        //启用curses库中对键盘特殊键的定义

    if(has_colors())         //has_colors函数检测你的屏幕的颜色显示能力
 {
int ijk;
       start_color();      //要启动彩色机制,必须先调用start_color()函数
for(i=0 k=0; i {
for(j=0; j {
init_pair(++k i j);     //初始化所有颜色
}
}
 }

    curs_set(0);                              //隐藏鼠标
    clear_screen(0 0 COLS LINES);          //绘制背景
    wrefresh(g_win);                          //刷新缓冲区
    return true;

}
/*init_graphics***************************************/


/*exit_graphics***************************************/
/*
函数原型:void exit_graphics(void)
函数功能:退出curses图形界面
函数参数:无
函数返回值:无
用到自定义函数:无
*/
void exit_graphics(void)
{
endwin();
}
/*exit_graphics***************************************/

/*set_attribute***************************************/
/*
函数原型:void set_attribute(void)
函数功能:设置字体
函数参数:无
函数返回值:无
用到自定义函数:无
*/
void set_attribute(void)
{
wattrset(g_win CURRENT_ATTRIBUTE);
}
/*set_attribute***************************************/

/*clear_screen****************************************/
/*
函数原型:void clear_screen(void)
函数功能:清屏函数
函数参数:起始位置坐标(xy)清屏区域长度w清屏区域高度h
函数返回值:无
用到自定义函数:无
*/
void clear_screen(int x int y int w int h)
{
int ij;
for(i=x;i for(j=y;j {
wmove(g_winji);
waddch(g_win‘ ‘);
}
wrefresh(g_win);
}
/*clear_screen***************************************/

/*read_key*******************************************/
/*
函数原型:int read_key(void)
函数功能:读取字符,将键盘按键转换为对应ASICII码
函数参数:无
函数返回值:按键所对应的ASICII码
用到自定义函数:无
*/
int read_key(void)
{
int flags;
int ch;
ch=getc(stdin);
if(ch==27)
{
flags=fcntl(STDIN_FILENO F_GETFL 0);// fcntl():stdin_fileno代表要设置的文件。F_GETFL取得文件描述词状态旗标,来自open()中的flag。
fcntl(STDIN_FILENO F_SETFL flags|O

评论

共有 条评论