#include <graphics.h> //图形库头文件
#include <stdio.h>
#include <mmsystem.h> //
#pragma comment(lib,"winmm.lib") //加载静态库--下一行
IMAGE mm;
void initGame(); //初始图像窗口
void playChess(); //下棋
int judge(int a, int b); //判断胜负
int flag = 0; //标记轮到谁下棋
int board[20][20] = { 0 }; //0表示没有下棋的状态
int main() //主函数窗口
{
initGame();
playChess();
while (1); //防止闪屏
return 0;
}
void initGame()
{
initgraph(600, 500);
loadimage(&mm, "1.jpg", 600, 500);
putimage(0, 0, &mm);
mciSendString("open D:\\vs project\\趣味五子棋\\趣味五子棋1.mp3 alias music ",0, 0, 0);
//MCIERROR mciError;
/* buf[50];
mciError = mciSendString("open D:\\vs project\\趣味五子棋\\趣味五子棋\\3.mp3 alias music ", buf, strlen(buf), NULL);
if (mciError)
{
HWND hwnd;
hwnd = GetHWnd();
mciGetErrorString(mciError, buf, strlen(buf));
MessageBox(hwnd, "打开音乐文件出错,请考虑以下选择","五子棋", MB_OK);
return;
}*/
mciSendString("play music repeat",NULL, 0, NULL);
//绘制棋盘
setlinecolor(BLACK);
for (int i = 1; i < 20; i++)
{
line(0, i * 25, 500, i * 25);
line(i * 25, 0, i * 25, 500);
}
setlinestyle(PS_SOLID, 2); //设置线条为实线,宽度为2
line(500, 0, 500, 500);
outtextxy(512, 60, "luoshiyong:黑棋");
outtextxy(512, 100, "daijunyi:白棋");
}
void playChess()
{
int x = 0, y = 0;
int a = 0, b = 0;
MOUSEMSG m; //定义鼠标消息
HWND hwnd;
hwnd = GetHWnd(); //设置窗口句柄
while (1)
{
m = GetMouseMsg(); //获取鼠标信息
//求距离绝对值
for (int i = 1; i < 20; i++)
{
for (int j = 1; j < 20; j++)
{
if (abs(m.x - i * 25) < 12 && abs(m.y - j * 25) < 12)
{
a = i;
b = j;
x = i * 25;
y = j * 25;
}
}
}
if (m.uMsg == WM_LBUTTONDOWN) //L左 button 按钮 down下
{
if (board[a][b] != 0)
{
MessageBox(hwnd, "别任性", "五子棋", MB_OK);
continue;
}
if (flag % 2 == 0)
{
setfillcolor(BLACK);
solidcircle(x, y, 10);
board[a][b] = 1;
}
else
{
setfillcolor(WHITE);
solidcircle(x, y, 10);
board[a][b] = 2;
}
flag++;
}
if (judge(a, b))
{
if (1 == flag % 2)
{
MessageBox(hwnd,"玩家1胜利", "游戏结束", MB_OK);
return;
}
else
{
MessageBox(hwnd, "玩家2胜利", "游戏结束", MB_OK);
return;
}
}
}
}
#include <stdio.h>
#include <mmsystem.h> //
#pragma comment(lib,"winmm.lib") //加载静态库--下一行
IMAGE mm;
void initGame(); //初始图像窗口
void playChess(); //下棋
int judge(int a, int b); //判断胜负
int flag = 0; //标记轮到谁下棋
int board[20][20] = { 0 }; //0表示没有下棋的状态
int main() //主函数窗口
{
initGame();
playChess();
while (1); //防止闪屏
return 0;
}
void initGame()
{
initgraph(600, 500);
loadimage(&mm, "1.jpg", 600, 500);
putimage(0, 0, &mm);
mciSendString("open D:\\vs project\\趣味五子棋\\趣味五子棋1.mp3 alias music ",0, 0, 0);
//MCIERROR mciError;
/* buf[50];
mciError = mciSendString("open D:\\vs project\\趣味五子棋\\趣味五子棋\\3.mp3 alias music ", buf, strlen(buf), NULL);
if (mciError)
{
HWND hwnd;
hwnd = GetHWnd();
mciGetErrorString(mciError, buf, strlen(buf));
MessageBox(hwnd, "打开音乐文件出错,请考虑以下选择","五子棋", MB_OK);
return;
}*/
mciSendString("play music repeat",NULL, 0, NULL);
//绘制棋盘
setlinecolor(BLACK);
for (int i = 1; i < 20; i++)
{
line(0, i * 25, 500, i * 25);
line(i * 25, 0, i * 25, 500);
}
setlinestyle(PS_SOLID, 2); //设置线条为实线,宽度为2
line(500, 0, 500, 500);
outtextxy(512, 60, "luoshiyong:黑棋");
outtextxy(512, 100, "daijunyi:白棋");
}
void playChess()
{
int x = 0, y = 0;
int a = 0, b = 0;
MOUSEMSG m; //定义鼠标消息
HWND hwnd;
hwnd = GetHWnd(); //设置窗口句柄
while (1)
{
m = GetMouseMsg(); //获取鼠标信息
//求距离绝对值
for (int i = 1; i < 20; i++)
{
for (int j = 1; j < 20; j++)
{
if (abs(m.x - i * 25) < 12 && abs(m.y - j * 25) < 12)
{
a = i;
b = j;
x = i * 25;
y = j * 25;
}
}
}
if (m.uMsg == WM_LBUTTONDOWN) //L左 button 按钮 down下
{
if (board[a][b] != 0)
{
MessageBox(hwnd, "别任性", "五子棋", MB_OK);
continue;
}
if (flag % 2 == 0)
{
setfillcolor(BLACK);
solidcircle(x, y, 10);
board[a][b] = 1;
}
else
{
setfillcolor(WHITE);
solidcircle(x, y, 10);
board[a][b] = 2;
}
flag++;
}
if (judge(a, b))
{
if (1 == flag % 2)
{
MessageBox(hwnd,"玩家1胜利", "游戏结束", MB_OK);
return;
}
else
{
MessageBox(hwnd, "玩家2胜利", "游戏结束", MB_OK);
return;
}
}
}
}