C# 连连看 游戏 连线 代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Timers;
namespace LLKAN
{
class Game
{
///
/// 游戏是否正在进行
///
public bool Playflag;
public bool CanPlay;
public bool PlayWin;
public const int Row = 12;
public const int Column = 17;
public GamePic[,] GamePicList = new GamePic[Row, Column];
private GamePath MyPath = new GamePath();
public Game()
{
this.CanPlay =false;
this.PlayWin = false;
}
///
/// 游戏开始
///
public void GameStart(int pn)
{
// 游戏开始,产生随机图片
stdFunc PubstdFunc = new stdFunc();
int[] PicNumber = new int[Row * Column];
//int pn;
PicNumber = PubstdFunc.GetRandomPic(pn, (Row - 2) * (Column - 2));
for (int i = 1; i<=Row-2; i++)
{
for (int j = 1; j <= Column-2; j++)
{
GamePic MyPic = new GamePic(j * 45, i * 41, PicNumber[(i-1) * (Column-2) + (j-1)], 1);
GamePicList[i, j] = MyPic;
}
//产生第一行
for (int i = 0; i < Column; i++)
{
GamePic MyPic = new GamePic(i * 45, 0,0, 2);
GamePicList[0, i] = MyPic;
}
//最后一行
for (int i = 0; i < Column; i++)
{
GamePic MyPic = new GamePic(i * 45, (Row-1)*41, 0, 2);
GamePicList[Row-1, i] = MyPic;
}
//第一列
for (int i = 0; i < Row; i++)
{
GamePic MyPic = new GamePic(0, i * 41, 0, 2);
GamePicList[i, 0] = MyPic;
}
//最一列
for (int i = 0; i < Row; i++)
{
GamePic MyPic = new GamePic((Column-1)*45, i * 41, 0, 2);
GamePicList[i, Column-1] = MyPic;
}
Playflag = true;
CanPlay = true;
}
///
/// 检查游戏状况
///
public void CheckPlay()
{
if (GameWin())
{
PlayWin = true;
return;
}
}
///
/// 得到两点之间的交叉点
///
public GamePath GetGamePath
{
{
return MyPath;
}
}
public void DrawLine(Graphics g, Color DrawColor)
{
Point PL,PH;
stdFunc MystdFunc = new stdFunc();
for (int i = 0; i < MyPath.GetPathList.Count; i+=2)
{
PL = new Point(
GamePicList[MyPath.GetPathList[i].X,MyPath.GetPathList[i].Y].X,
GamePicList[MyPath.GetPathList[i].X,MyPath.GetPathList[i].Y].Y);
PH = new Point(
GamePicList[MyPath.GetPathList[i + 1].X, MyPath.GetPathList[i + 1].Y].X,
GamePicList[MyPath.GetPathList[i + 1].X, MyPath.GetPathList[i + 1].Y].Y);
MystdFunc.DrawLine(g, PL, PH, 5, DrawColor);
}
}
///
/// 检查两个图标是否可以消
///
/// 第一个图标的座标
/// 第二个图标的座标
///
public bool CheckPath(Point P1, Point P2,bool AddPath)
{
MyPath.Clear();
if (P1 == P2) return false;
// 开始搜索路径
// 1 检查水平
if (P1.X == P2.X)
{
if (CheckHorizontal(P1, P2, AddPath))
return true;
}
MyPath.Clear();
// 2 检查垂直
if (P1.Y == P2.Y)
{
if (CheckV ertical(P1, P2, AddPath))