C++之简单五子棋的语言设计实现

算法思路在上一篇[C++之简单五子棋的设计思路](http://blog.csdn.net/black_kyatu/article/details/79293392)中描述的较为清晰了。接下来则是设计数据类型和语言实现部分。

类及类的实现

#ifndef RENJU_H
#define RENJU_H
#include <iostream>
#include <windows.h>
#include <string>
#define hor 7
#define ver 4
using namespace std;


//用于记录坐标
struct  position
{
	int x;
	int y;
	position()
	{
		x = 0;
		y = 0;
	}
	position(int a,int b)
	{
		x = a;
		y = b;
	}
};


//用于记录棋子颜色和节点状态
enum state
{
	blank=0,black=1,white=2


};


//用于存储棋局分析信息:未完赛,犯规,平局,黑方胜,白方胜
enum result
{
	go_on,error,draw,black_win,white_win
};


// 设置光标
void setpos(COORD a)   
{
	HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}


// 设置光标
void setpos(int i, int j)
{
	COORD pos = { i, j };
	setpos(pos);
}


//绘图函数,用于在指定坐标输出指定字符
inline void gps(int x,int y,char c)
{
	setpos(y,x);
	cout<<c;
}


//绘图函数,用于在指定坐标输出整数
inline void  gps(int x,int y,int i)
{
	setpos(y,x);
	if(i>=10)
		cout<<i;
	else
		cout<<0<<i;
}


//绘图函数,用于在指定坐标输出字符串
inline void  gps(int x,int y,string s)
{
	setpos(y,x);
	cout<<s;
}


//绘图函数,用于在给定坐标打印棋盘中的一格
void tab(int x,int y,state str)
{
	string s;
	switch (str)
	{
	case blank:
		s="  ";	
		break;
	case black:
		s="黑";
		break;
	case white:
		s="白";
		break;
	default:
		break;
	}
	setpos(y,x);
	cout<<" ------ ";
	setpos(y,x+1);
	cout<<"|      |";
	setpos(y,x+2);
	cout<<"|  "<<s<<"  |";
	setpos(y,x+3);
	cout<<"|      |";
	setpos(y,x+4);
	cout<<" ------ ";
}


//查找最大值
int MAX(const int *a,int n)
{
	int max = a[0];
	for(int i =1; i < n ;i++)
	{
		if(a[i] > max)
			max = a[i];
	}
	return max;
}


//检测是否符合胜利条件


//棋子类
class chess
{
public:
	inline chess(int x=0,int y=0,state c=blank)
	{ point.x=x,point.y=y;
		color=c;
	};
	inline chess(chess &ch) 
	{ point=ch.drop_point();
		color=ch.get_
  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值