资源简介

基于STM32F4(原子探索者)的五子棋对战平台,可以实现触摸下子、人机对战、人人对战、帮助、悔棋、开关音量的功能,别的平台或板子可以参考移植,博客及视频https://blog.csdn.net/a568713197/article/details/80461127

资源截图

代码片段和文件信息

#include “game.h“
#include “touch.h“
#include “led.h“
#include 
#include “text.h“
#include “delay.h“
#include “rng.h“
#include “usart.h“
#include “exit.h“
#include “beep.h“


//定义棋盘起始坐标
#define CHESSBOARD_START_X 7
#define CHESSBOARD_START_Y 42
#define CHESSBOARD_END_X 232
#define CHESSBOARD_END_Y 267

//棋盘大小
#define CHESSBOARD_SIZE (CHESSBOARD_END_X-CHESSBOARD_START_X)
//网格大小
#define CHESSGRID_SIZE (CHESSBOARD_SIZE / 15)
//棋盘颜色
#define CHESSBOARD_COLOR BROWN

char g_Chess[16][16]; //存放棋子缓存
int  g_ChessNum; //棋子数量
int  g_SameChessNum; //相连的相同的棋子数
int  g_SpaceFlag = 0; //空位标志
char g_Mode=0; //五子棋模式
u8 voice=0;

//绘制棋盘
//15x15
static void DrawChessBoard(void)
{
int i;
//填充棋盘背景色
LCD_Fill(CHESSBOARD_START_X-5 CHESSBOARD_START_Y-5 
CHESSBOARD_END_X+5 CHESSBOARD_END_Y+5 CHESSBOARD_COLOR);
POINT_COLOR = BLACK;
//绘制边框线
LCD_DrawRectangle(CHESSBOARD_START_X-3 CHESSBOARD_START_Y-3
  CHESSBOARD_END_X+3 CHESSBOARD_END_Y+3);
LCD_DrawRectangle(CHESSBOARD_START_X-4 CHESSBOARD_START_Y-4
  CHESSBOARD_END_X+4 CHESSBOARD_END_Y+4);
LCD_DrawRectangle(CHESSBOARD_START_X CHESSBOARD_START_Y 
  CHESSBOARD_END_X CHESSBOARD_END_Y);

POINT_COLOR = BLACK;
//绘制垂直线
for (i = 1; i < 15; i++)
{
LCD_DrawLine(CHESSBOARD_START_X
 CHESSBOARD_START_Y + (CHESSGRID_SIZE*i)
 CHESSBOARD_END_X
 CHESSBOARD_START_Y + (CHESSGRID_SIZE*i));
}

//绘制水平线
for (i = 1; i < 15; i++)
{
LCD_DrawLine(CHESSBOARD_START_X + (CHESSGRID_SIZE*i)
 CHESSBOARD_START_Y
 CHESSBOARD_START_X + (CHESSGRID_SIZE*i)
 CHESSBOARD_END_Y);
}
}

//绘制棋子
//xy:棋子坐标(0~15)
static void DrawChess(int x int y int num char sta)
{
uint16_t ChessColor;
uint16_t xChess;
uint16_t yChess;

if (x>15 || x<0 || y>15 || y<0)return; //超范围了
//判断是下棋还是复盘
if (sta)
{
if (g_Chess[x][y]!=0)return; //已有棋子
}

//判断棋子颜色
(num%2==0) ? (ChessColor=BLACK) : (ChessColor=WHITE);

//计算棋子坐标
xChess = CHESSBOARD_START_X + (x*CHESSGRID_SIZE);
yChess = CHESSBOARD_START_Y + (y*CHESSGRID_SIZE);

LcdDrawCircleA(xChess 
   yChess 
   CHESSGRID_SIZE/2-1 
   ChessColor 
   1);
if(voice==1)          //判断声音是否打开 若打开 每次下子蜂鸣器响100ms
BEEP_Run(100);
delay_ms(10);
if (sta == 0) return;
g_ChessNum++;
g_Chess[x][y] = g_ChessNum;
}

//清除棋子
//xy:棋子坐标(0~14)
static void ClearChess(int x int y)
{
uint16_t ChessColor;
uint16_t xChess;
uint16_t yChess;

if (x>14 || x<0 || y>14 || y<0)return; //超范围了
if (g_Chess[x][y]!=0)return; //已有棋子

ChessColor = CHESSBOARD_COLOR;

//计算棋子坐标
xChess = CHESSBOARD_START_X+ (x*CHESSGRID_SIZE);
yChess = CHESSBOARD_START_Y + (y*CHESSGRID_SIZE);

LcdDrawCircleA(xChess 
   yChess 
   CHESSGRID_SIZE/2-1 
   ChessColor 
   1);
POINT_COLOR=BLACK;
LCD_DrawLine(xChess-8yChessxChess+8yChess);
LCD_DrawLine(xChessyChess-8xChessyChess+8

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      22169  2018-04-28 21:44  五子棋对战系统V1.1\APP\game.c

     文件        153  2018-04-28 21:35  五子棋对战系统V1.1\APP\game.h

     文件       3248  2014-01-15 00:31  五子棋对战系统V1.1\FATFS\doc\css_e.css

     文件       3661  2014-01-15 00:31  五子棋对战系统V1.1\FATFS\doc\css_j.css

     文件       1063  2013-09-18 21:47  五子棋对战系统V1.1\FATFS\doc\img\app1.c

     文件       1597  2013-10-18 21:41  五子棋对战系统V1.1\FATFS\doc\img\app2.c

     文件       3811  2014-01-13 20:56  五子棋对战系统V1.1\FATFS\doc\img\app3.c

     文件      10365  2014-01-07 15:10  五子棋对战系统V1.1\FATFS\doc\img\app4.c

     文件       1414  2011-09-02 22:10  五子棋对战系统V1.1\FATFS\doc\img\f1.png

     文件       1458  2007-02-10 03:12  五子棋对战系统V1.1\FATFS\doc\img\f2.png

     文件       1039  2007-02-10 03:12  五子棋对战系统V1.1\FATFS\doc\img\f3.png

     文件       2335  2008-01-05 20:27  五子棋对战系统V1.1\FATFS\doc\img\f4.png

     文件       2479  2008-01-05 20:27  五子棋对战系统V1.1\FATFS\doc\img\f5.png

     文件       1436  2010-08-21 10:13  五子棋对战系统V1.1\FATFS\doc\img\f6.png

     文件      11388  2013-05-12 12:31  五子棋对战系统V1.1\FATFS\doc\img\f7.png

     文件      11421  2014-02-19 22:38  五子棋对战系统V1.1\FATFS\doc\img\funcs.png

     文件       2401  2009-03-20 21:57  五子棋对战系统V1.1\FATFS\doc\img\layers.png

     文件       2379  2009-06-13 21:48  五子棋对战系统V1.1\FATFS\doc\img\layers3.png

     文件       7932  2013-12-27 12:20  五子棋对战系统V1.1\FATFS\doc\img\modules.png

     文件      19068  2008-10-18 19:31  五子棋对战系统V1.1\FATFS\doc\img\rwtest.png

     文件       8153  2010-09-13 10:55  五子棋对战系统V1.1\FATFS\doc\img\rwtest2.png

     文件       3011  2009-06-15 00:03  五子棋对战系统V1.1\FATFS\doc\img\rwtest3.png

     文件       5352  2014-01-15 00:31  五子棋对战系统V1.1\FATFS\doc\updates.txt

     文件       3722  2014-08-29 15:13  五子棋对战系统V1.1\FATFS\exfuns\exfuns.c

     文件       1564  2014-08-29 15:13  五子棋对战系统V1.1\FATFS\exfuns\exfuns.h

     文件       7722  2014-08-29 15:14  五子棋对战系统V1.1\FATFS\exfuns\fattester.c

     文件       1225  2014-05-15 17:20  五子棋对战系统V1.1\FATFS\exfuns\fattester.h

     文件       5018  2014-08-27 21:29  五子棋对战系统V1.1\FATFS\exfuns\mycc936.c

     文件       8488  2014-05-19 00:56  五子棋对战系统V1.1\FATFS\src\00readme.txt

     文件       6617  2014-08-29 15:00  五子棋对战系统V1.1\FATFS\src\diskio.c

............此处省略291个文件信息

评论

共有 条评论