“黑白棋”技术文档

“黑白棋”技术文档

 

功能:

       实现一般黑白棋的功能,实现两人对战。

 

黑白棋盘结构:

         采用数组结构,数组由0 1 2三种状态组成,其中“0”表示没有棋子, 1”表示黑子, 而“0”表示白子。 

 

运行过程:“黑白棋”技术文档_第1张图片

 

运行文件:          blackWhite.cpp

 

运行环境:          Turbo C++ 3.0

 

宏定义:

 

字段

描述

TRUE

1

表示真的情况

FALSE

0

表示假的情况

UP

0x4800

键盘箭头 

DOWN

0x5000

键盘箭头 

LEFT

0x4b00

键盘箭头 

RIGHT

0x4d00

键盘箭头 

ESC

0x011b

键盘箭头  ESC

ENTER

0x1c0d

键盘箭头  Enter 

 

 数据类型

全局变量的说明:

 

函数名

类型

描述

gridState

Int[][]

存储8×8的棋盘的状况

scoreBlack

Int[]

存储黑棋的分数

scoreWhite

Int[]

存储白棋的分数

keyboard

Int

键盘的相应存储

 

原型:

 

 int gridState[8][8] = {0},  scoreBlack[2] = {0},  scoreWhite[2] = {0},  keyboard;

 

接口函数列表:

 

void PrintChessBoard(void);

void FillColorAgain(int coordinateX, int coordinateY);

void PlayTheResult(void);

void Minitance(void);

void SetTheFirstColor(int operation);

void FillColorAgain(int coordinateX, int coordinateY);

void PriChange(int coordinateX, int coordinateY);

void TranScore(void);

void PrintScore(int playnum);

void PlayTheResult(void);

 

 

接口函数说明:

1 PrintChessBoard

1.1    功能说明:打印棋盘和LOG以及操作说明

1.2    前置条件:调用initgraph图形函数初始化(以下涉及图形操作的均需要,以下将省略,但是也是前置条件)

1.3    函数原型:

void PrintChessBoard(void);

1.4    参数说明:

void

1.5    返回值说明:

void

1.6      使用举例(算法描述):

 

void PrintChessBoard(void)

{    int clienti;

    setbkcolor();

    setcolor();

    //打印框架

    setcolor(YELLOW);

    //打印线

    line();

    //Tip:

    outtextxy();

    //以实填充

    setfillstyle();

    //画出标志圆

    fillellipse();

}

2 Minitance

2.1功能说明:进入对战无穷循环

2.2前置条件:调用PrintChessBoard画战区

2.3函数原型:

                        void Minitance(void)

2.4参数说明:

             void

2.5返回值说明:

                void

2.6使用举例:

 

void Minitance(void)

{

    int operation = 0, coordinateX, coordinateY, sum, clienti, clientj, temp, tempi, tempj, state1, state2, state3, state4, state5, state6, state7, state8;/* coordinateX, coordinateY 为坐标,sum是当前的棋子数目,其他为临时变量 */

    //在中央打印一个初始的战斗状况

    while(TRUE)

    {temp{设置为当前鼠标所在的颜色值}/* get the first coordinate       */

         while(TRUE)

         {

             PrintScore(1)PrintScore(2);/* 打印分数                  */

             SetTheFirstColor(operation);/* 设置初始的的颜色 */

             fillellipse(coordinateX, coordinateY, 10, 10);/* 在初始位置放置 */

             keyboard = bioskey(0);/* 响应键盘 */

             if (keyboard == ESC)

                            break;
    else if (keyboard == ENTER)/* enter the ENTER to confirm          */

             {   state1 = state2 = state3 = state4 = state5 = state6 = state7 = state8  = 0;

               /* if operation  is white                                                                                           */

              if((coordinateY != 85) && (gridState[(coordinateX - 115) / 30][(coordinateY - 115) / 30] != 1) &&   (gridState[(coordinateX-115) / 30][(coordinateY - 115) / 30] != 2))/* (115, 115)为初始位置 */

                    {/*judge the vailable of the rule                                */

//判断是不是复核放入棋子,在许多情况没有吃掉对手棋子的时候,是不允许放入棋子的

/* 假如state 状态成立那么就允许执行下一步,3 表示符合情况的状态 */

 if (state1 == 3 || state2 == 3 || state3 == 3 || state4 == 3 || state5 == 3 || state6 == 3 || state7 == 3 || state8 == 3)

                       {

                            if ( operation % 2 == 0)

                                     gridState[(coordinateX-115) / 30][(coordinateY-115) / 30] = 1;/* 为黑棋 */

                            else

                                     gridState[(coordinateX-115) / 30][(coordinateY-115) / 30] = 2;/* 为白棋 */

                       /* the change of the screen  moving the circle            */

                       PriChange(coordinateX, coordinateY);/* 打印变化 */

                       TranScore();/* the tran of the score                      */

                       break;/* get to next step                                 */

                       }

                   else

                            continue;/* continue when failed                          */

         }

         /* judge the keyboard */

         //对键盘中的上下左右进行移动操作

    if (keyboard == ESC)

                   break;

    //处理sum量,处理sum的量

      PlayTheResult();/* get the result to the screen                */

         operation++;

         if (operation == 11)/* when operation achieve the 11 then to 1     */

             operation = 1;

    }/* END: while(TRUE)                                               */

}

 

  

3  Display_Student

3.1功能说明:显示所有的学生信息

3.2前置条件:链表中存在学生的信息

3.3函数原型:

        void DisplayStudent(LinkList lstudent)

3.4参数说明:

             lstudent一个student结构体的链表。

3.5返回值说明:无

3.6使用举例:

void DisplayStudent(LinkList lstudent)
{
       while(lstudent->next)
       {
              printf("
学号/t姓名/t性别/t年龄/t学历/t数学/t语文/t计算机/n");
              printf("%4d/t", lstudent->next->number);
              printf("%7s ", lstudent->next->name);
              if(lstudent->next->sex == ’m’)
              {
                     printf("
/t");
              }
              else
              {
                     printf("
/t");
              }
              printf("%4d/t", lstudent->next->age);
              if(lstudent->next->sage == 0)
              {
                     printf("bachelor");
              }
              else if(lstudent->next->sage == 1)
              {
                     printf("master  ");
              }
              else
              {
                     printf("doctor  ");
              }
              printf("%4.1f/t", lstudent->next->achieve.math);
              printf("%4.1f/t", lstudent->next->achieve.chinese);
              printf("%4.1f/t", lstudent->next->achieve.computer);
              printf("/n");
 
              lstudent = lstudent->next;
       }
}

 

  

4  InsertStudent

4.1功能说明:插入一个学生信息

4.2前置条件:无

4.3函数原型:

        bool InsertStudent(LinkList &lstudent)

4.4参数说明:

        lstudent一个student结构体的结点,为引用类型。

4.5返回值说明:如果函数成功调用返回TRUE。如果不成功返回FALSE,并且显示错误原因

4.6使用举例:

bool InsertStudent(LinkList &lstudent)
{
       LinkList p;
       
       CreateStudent(p);
       
       p->next = lstudent->next;
       lstudent->next = p;
       return TRUE;
}

 

  

5  DeleteStudent

5.1功能说明:删除一个学生信息,不能删除第一个记录

5.2前置条件:无

5.3函数原型:

       bool DeleteStudent(LinkList &lstudent)

5.4参数说明:

lstudent一个student结构体的结点,为引用类型。

5.5返回值说明:如果函数成功调用返回TRUE。如果不成功返回FALSE,并且显示错误原因

5.6使用举例:

bool DeleteStudent(LinkList &lstudent)
{
       LinkList p, q;//
定义临时表指针
       int num;//
要删除的学生的学号
 
       printf("
请输入要删除的学生的学号:");
       scanf("%d", &num);
       
       p = lstudent;
       while(p->number != num)
       {
              p = p->next;
       }
       
       q = p->next;
       p->next = q->next;
       free(q);
       return TRUE;
}

 

 

文档说明备注:

       [//]   : 表示一段算法,或简单的功能说明。

         [/**/ ] : 注释说明部分。

你可能感兴趣的:(C/C++Learning,Notes,keyboard,存储,文档,图形,算法,c++)