easyx五子棋

大一下作的五子棋(老师要求),说要基于qt,但我还没学就用easyx做了,具体我已经打包,链接在最下面。

源.cpp
#define __CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include"play.h"
#include"za.h"

using namespace std;
int main() {

	play p;
	p.bgm();
	p.player();

}

play.cpp

#include"za.h"
#include<graphics.h>
#include <Windows.h>	
#include<mmsystem.h>
#pragma comment(lib,"WINMM.LIB")
using namespace std;

int x_axis;
int y_axis;
int step = 1;
int num_step;
char s[5];
MOUSEMSG m;
chessboard cb;
void play::bgm() {
	mciSendString("open bgm.mp3", NULL, 0, NULL);
	mciSendString("play bgm.mp3", NULL, 0, NULL);
}
void luozi() {


	/*mciSendString("open 20220423_154258805.wav", NULL, 0, NULL);*/
	mciSendString("play 123.mp3", NULL, 0, NULL);

}

int play::player()
{
	
	cb.initchessboard();
	cb.printchessboard();
	while (step <= 255)
	{
		if (step % 2 == 1)
		{
			setfillcolor(BLACK);
			fillcircle(637, 434, RADIUS);
			m = GetMouseMsg();
			switch (m.uMsg)
			{
			case WM_LBUTTONDOWN:
				x_axis = (int)((double)m.x / CELLSIZE + 0.5);
				y_axis = (int)((double)m.y / CELLSIZE + 0.5);

				if (cb.board[y_axis][x_axis] == ' ' && y_axis >= 0 && y_axis < 15 && x_axis >= 0 && x_axis < 15)
				{
					cb.board[y_axis][x_axis] = 'b';
					luozi();

					fillcircle(x_axis * CELLSIZE, y_axis * CELLSIZE, RADIUS);
					/*cout << cb.board[y_axis][x_axis] << endl;*/
					if (judge(y_axis, x_axis) == 1) {
						MessageBoxA(0, "黑棋胜利!", "游戏结束", MB_OK);
						return 1;
					}
					step++;
				}
				break;

			}
		}
		else
		{
			setfillcolor(WHITE);
			fillcircle(637, 434, RADIUS);
			m = GetMouseMsg();
			switch (m.uMsg)
			{
			case WM_LBUTTONDOWN:
				x_axis = (int)((double)m.x / CELLSIZE + 0.5);
				y_axis = (int)((double)m.y / CELLSIZE + 0.5);

				if (cb.board[y_axis][x_axis] == ' ' && y_axis >= 0 && y_axis < 15 && x_axis >= 0 && x_axis < 15)
				{
					cb.board[y_axis][x_axis] = 'w';

					fillcircle(x_axis * CELLSIZE, y_axis * CELLSIZE, RADIUS);
					luozi();

					if (judge(y_axis, x_axis) == 1) {
						MessageBoxA(0, "白棋胜利!", "游戏结束", MB_OK | MB_TOPMOST);
						return 1;
					}
					step++;
				}
				break;
			}
		}
	}
	MessageBoxA(0, "平局!", "游戏结束", 3);
	
	return 0;
}
int  play::judge(int x, int y)
{
	char c = 'c';

	int num = 0;
	for (int i = 0; i < MSIZE; i++)
	{
		/*cout << cb.board[x][y] << endl;*/
		if (cb.board[i][y] == cb.board[x][y])
		{
			for (int j = 1; j < 5; j++)
			{
				if (cb.board[i + j][y] == cb.board[x][y]) {
					num++;

				}
				else {
					num = 0;
				}


			}

		}

		if (num == 4) {
			return 1;
		}

	}

	for (int i = 0; i < MSIZE; i++)
	{
		if (cb.board[x][i] == cb.board[x][y])
		{
			for (int j = 1; j < 5; j++)
			{
				if (cb.board[x][i + j] == cb.board[x][y])
				{
					num++;
				}
				else
				{
					num = 0;
				}
			}
		}

		if (num == 4) {
			return 1;
		}

	}


	for (int i = 0; i < MSIZE; i++) {
		for (int j = 0; j < MSIZE; j++) {

			if (i + 4 < 15 && j + 4 < 15 && cb.board[i + 1][j + 1] == cb.board[x][y] && cb.board[i + 2][j + 2] == cb.board[x][y]
				&& cb.board[i + 3][j + 3] == cb.board[x][y] && cb.board[i + 4][j + 4] == cb.board[x][y] && cb.board[i + 5][j + 5] == cb.board[x][y])
			{

				return 1;
			}

			//斜左下判断
			if (i + 4 < 15 && j - 4 < 15 && cb.board[i + 1][j - 1] == cb.board[x][y] && cb.board[i + 2][j - 2] == cb.board[x][y]
				&& cb.board[i + 3][j - 3] == cb.board[x][y] && cb.board[i + 4][j - 4] == cb.board[x][y] && cb.board[i + 5][j - 5] == cb.board[x][y])
			{

				return 1;
			}
		}
	}
	return 0;
}


chessboard.cpp

#include"chessboard.h"
//#include<easyx.h>
#include<graphics.h>
void chessboard::initchessboard()
{
	for (int i = 0; i < MSIZE; i++) {
		for (int j = 0; j < MSIZE; j++) {
			board[i][j] = ' ';
		}
	}
}

void chessboard::printchessboard()
{
	initgraph(720, 600);
	IMAGE img;
	loadimage(&img, "beijing.png", 720, 600);
	putimage(0, 0, &img);	





}

chessboard.h

#pragma once

#define MSIZE 15
using namespace std;
class chessboard {
public:
	char board[MSIZE][MSIZE];
	void initchessboard();
	void printchessboard();

};


play.h

#pragma once
#include <iostream>
using namespace std;
class play {
public:
	int player();
	int judge(int x, int y);
	void bgm();

};


za.h

#pragma once
#include "chessboard.h"
#include"play.h"
#include<easyx.h>
#include<iostream>
#include<conio.h>
#define board_hight 560
#define board_width 560
#define CELLSIZE (board_width/(MSIZE-1))
#define RADIUS CELLSIZE/2
//#define MSIZE 15

http://链接:https://pan.baidu.com/s/1-gluYTcXbV-XIZMqK7Lgdw?pwd=8888 提取码:8888 --来自百度网盘超级会员V4的分享icon-default.png?t=M3K6http://链接:https://pan.baidu.com/s/1-gluYTcXbV-XIZMqK7Lgdw?pwd=8888 提取码:8888 --来自百度网盘超级会员V4的分享

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值