日期:2014-05-18  浏览次数:20815 次

扫雷-----C#窗体
 

using System;

using System.Collections.Generic;

using System.Text;

using System.Drawing;

using System.Windows;

using System.Windows.Forms;

namespace winmine

{

    public class Map

    {

        public static int Time = 0;

        public static bool GameOver = false;

        public static bool IsSuccess = false;

        public static int UserMineCount = 0;

        public static int Width = 17 * 10;

        public static int Height = 17 * 10;

        public static int BlockWidth = 16;

        public static int MineNumber = 10;

        public static int RowCount = 9;

        public static int ColumnCount = 9;

        public static int MainMarked = 0;

        public static int BlockOpen = 0;

        public static List<BlockData> BlockDataList = new List<BlockData>();

        static Map()

        {

            Init();

        }

        public static void Init()

        {

            GameOver = false;

            Time = 0;

            Height = RowCount * BlockWidth;

            Width = ColumnCount * BlockWidth;

        }

        static void OpenUnit(BlockData bd)

        {

            if (!bd.IsMine)

            {

                if (bd.State == BlockState.Open || bd.State == BlockState.UserMine)

                {

                    return;

                }

                bd.State = BlockState.Open;

                BlockGraphics.DrawBlock(bd);

                BlockOpen++;

                if (bd.MineCount == 0)

                {

                    foreach (BlockData bd1 in bd.BlockList)

                    {

                        OpenUnit(bd1);

                    }

                }

            }

 

        }

        public static void Showall()

        {

            foreach (BlockData bd in Map.BlockDataList)

            {

                if (bd.State == BlockState.Closed)

                {

                    bd.State = BlockState.Open;

                }

 

            }

        }

        public static void DrawBlocks()

        {

            if (!Map.GameOver)

                foreach (BlockData bd in Map.BlockDataList)

                {

                    BlockGraphics.DrawBlock(bd);

                }

            else

            {

                foreach (BlockData bd in Map.BlockDataList)

                {

                    if (!bd.IsMine && bd.State == BlockState.UserMine)

                    {

                        BlockGraphics.DrawBlock(bd.x, bd.y, BlockGraphics.MineBlastMap);

                    }

                    else if (bd.IsMine)

                    {

                        BlockGraphics.DrawBlock(bd.x, bd.y, BlockGraphics.MineMap);

                    }

                    else

                    {

                        BlockGraphics.DrawBlock(bd);

                    }

                }

            }

        }

        public static bool IsSuccessful()

        {

            if (Map.UserMineCount == 0)

            {

                int i = 0;

                for (i = 0; i < Map.BlockDataList.Count; i++)

                {

                    if (!Map.BlockDataList[i].IsMine && Map.BlockDataList[i].State == BlockState.UserMine)

                    {

                        break;

                    }

 

                }

                if (i < Map.BlockDataList.Count)

                {

                    return false;

                }

                else

                {

                    return true;

                }

            }

            else

            {

                return false;

            }

        }

        public static void SingleClick(int x, int y)

        {

            BlockData bd = GetBlock(x, y);

            if (GameOver)

            {

                return;

            }

            if (bd != null && bd.IsMine)

            {

 

                GameOver = t