• 大小: 118KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: 其他
  • 标签: c#Winfom  

资源简介

开发工具:VS2013,开发环境:.net4.0 局域网内采用UDP通信技术实现五子棋对战游戏。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 五子棋
{
    public class ChessBoard
    {
        public delegate void UpdateRemoteChessBoard(int flag int x int y);//更新对方棋盘
        public UpdateRemoteChessBoard UpdateRemoteChessBoardDelegate;

        public delegate void InformRemoteResult();//通知对方已输
        public InformRemoteResult InformRemoteResultDelegate;

        PictureBox picChessboard;
        const int BOARDSIZE = 15;
        const int BOARDLENGTH = 800;
        int[] chessMap = new int[BOARDSIZE BOARDSIZE];
        bool isPut = false ;//轮到对方走棋

        private int myFlag;//自己棋的类型
        Point pCurrent=new Point (-1-1);//保存当前下棋的位置

        public int MyFlag
        {
            set
            {
                myFlag = value;
                if (myFlag == 1)//白棋默认先走
                {
                    this.isPut = true;
                }
            }
        }
        public ChessBoard(PictureBox picBoard)
        {
            this.picChessboard = picBoard;
        }

        //初始化全局变量
        public void InitialChess()
        {
            for (int i = 0; i < BOARDSIZE; i++)
            {
                for (int j = 0; j < BOARDSIZE; j++)
                {
                    chessMap[i j] = 0;
                }
            }
            this.picChessboard.Invalidate();
        }
        //绘制棋盘
        public  void DrawBoard(Graphics g)
        {
            Pen p = new Pen(Brushes.Black 3.0f);
            //  p.Width = 2f;
            //横线
            for (int i = 0; i < BOARDSIZE; i++)
            {
                g.DrawLine(p new Point(0 (i + 1) * 50) new Point(BOARDLENGTH (i + 1) * 50));
            }
            //竖线
            for (int i = 0; i < BOARDSIZE; i++)
            {
                g.DrawLine(p new Point((i + 1) * 50 0) new Point((i + 1) * 50 BOARDLENGTH));
            }
        }

        //绘制棋子
        public void DrawChess(Graphics g)
        {

            for (int i = 0; i < BOARDSIZE; i++)
            {
                for (int j = 0; j < BOARDSIZE; j++)
                {
                    if (chessMap[i j] == 1)
                    {
                        g.DrawImage(Properties.Resources.whitechess new Point(50 * (i + 1) - 20 50 * (j + 1) - 20));
                    }
                    if (chessMap[i j] == 2)
                    {
                        g.DrawImage(Properties.Resources.blackchess new Point(50 * (i + 1) - 20 50 * (j + 1) - 20));
                    }
                }
            }
            if (pCurrent.X !=-1)
            {
                //绘制最后落下棋子上的红色标注
                g.FillEllipse(Brushes.Red new Rectangle((pCurrent.X + 1) * 50-5 (pCurrent.Y + 1) * 50-5 10 10));
            }
        }
        /// 
        /// 下棋
        /// 

        /// 

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

     文件       2398  2015-12-27 15:06  五子棋\五子棋\bin\Debug\img\background.png

     文件       4571  2015-12-27 18:53  五子棋\五子棋\bin\Debug\img\blackchess.png

     文件       4708  2015-12-27 15:58  五子棋\五子棋\bin\Debug\img\whitechess.png

     文件      33792  2016-01-03 11:08  五子棋\五子棋\bin\Debug\五子棋.exe

     文件      50688  2016-01-03 11:08  五子棋\五子棋\bin\Debug\五子棋.pdb

     文件      22704  2016-01-03 11:14  五子棋\五子棋\bin\Debug\五子棋.vshost.exe

     文件        490  2015-07-10 19:01  五子棋\五子棋\bin\Debug\五子棋.vshost.exe.manifest

     文件      10744  2016-01-03 11:08  五子棋\五子棋\ChessBoard.cs

     文件       7179  2016-01-03 10:29  五子棋\五子棋\FrmMain.cs

     文件      11708  2015-12-29 19:49  五子棋\五子棋\FrmMain.Designer.cs

     文件       5817  2015-12-29 19:49  五子棋\五子棋\FrmMain.resx

     文件       1231  2015-12-27 20:15  五子棋\五子棋\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6250  2015-12-27 19:55  五子棋\五子棋\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       5120  2015-12-27 15:10  五子棋\五子棋\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        612  2016-01-03 11:14  五子棋\五子棋\obj\Debug\五子棋.csproj.FileListAbsolute.txt

     文件       1054  2015-12-29 19:49  五子棋\五子棋\obj\Debug\五子棋.csproj.GenerateResource.Cache

     文件       1341  2015-12-27 15:44  五子棋\五子棋\obj\Debug\五子棋.csprojResolveAssemblyReference.cache

     文件      33792  2016-01-03 11:08  五子棋\五子棋\obj\Debug\五子棋.exe

     文件        180  2015-12-29 19:49  五子棋\五子棋\obj\Debug\五子棋.FrmMain.resources

     文件      50688  2016-01-03 11:08  五子棋\五子棋\obj\Debug\五子棋.pdb

     文件      12509  2015-12-27 20:13  五子棋\五子棋\obj\Debug\五子棋.Properties.Resources.resources

     文件        472  2015-12-27 19:10  五子棋\五子棋\Program.cs

     文件       1342  2015-12-27 15:06  五子棋\五子棋\Properties\AssemblyInfo.cs

     文件       3992  2015-12-27 15:10  五子棋\五子棋\Properties\Resources.Designer.cs

     文件       6719  2015-12-27 15:10  五子棋\五子棋\Properties\Resources.resx

     文件       1096  2015-12-27 15:06  五子棋\五子棋\Properties\Settings.Designer.cs

     文件        249  2015-12-27 15:06  五子棋\五子棋\Properties\Settings.settings

     文件       4399  2016-01-03 10:29  五子棋\五子棋\ReceiveUDP.cs

     文件        708  2015-12-28 16:23  五子棋\五子棋\SendUDP.cs

     文件       3960  2015-12-27 20:13  五子棋\五子棋\五子棋.csproj

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

评论

共有 条评论

相关资源