⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmshejimap.cs

📁 一个用java设计的推箱子的程序。很不错的。呵呵
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace PushBox
{
    public partial class frmSheJiMap : Form
    {
        [DllImport("kernel32")]
        private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);

        public frmSheJiMap()
        {
            InitializeComponent();
        }
        private System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
        private PictureBox ActiveBox = new PictureBox();
        private void DiBiao()
        {
            for (int i = 0; i < 225; i++)
            {
                PictureBox p = new PictureBox();
                if (int.Parse((i / 15).ToString()) != 0 && (i - int.Parse((i / 15).ToString()) * 15) != 0 && int.Parse((i / 15).ToString()) != 14 && (i - int.Parse((i / 15).ToString()) * 15) != 14)
                {
                    p.Click += new EventHandler(p_Click);
                    p.MouseHover += new EventHandler(p_MouseHover);
                    p.MouseLeave += new EventHandler(p_MouseLeave);
                    p.Cursor = Cursors.Hand;
                }
                else
                {
                    p.Image = tsbWall.Image;
                }
                p.BackColor = Color.Black;
                p.SizeMode = PictureBoxSizeMode.StretchImage;
                p.Size = new Size(30, 30);
                p.Top = int.Parse((i / 15).ToString()) * 30;
                p.Left = (i - int.Parse((i / 15).ToString()) * 15) * 30;
                p.Visible = true;
                p.Parent = panel1;
                myArrayList.Add(p);
            }
        }
        private void frmSheJiMap_Load(object sender, EventArgs e)
        {
            this.Size = new Size(456,521);
            this.Top = 0;
            tsbLu_Click(tsbLu, null);
            DiBiao();
        }

        private void tsbLu_Click(object sender, EventArgs e)
        {
            tsbLu.Checked = false;
            tsbAim.Checked = false;
            tsbBox.Checked = false;
            tsbWall.Checked = false;
            tsbPeople.Checked = false;
            tsbNull.Checked = false;
            ((ToolStripButton)sender).Checked = true;
            ActiveBox.Image = ((ToolStripButton)sender).Image;
        }

        private void p_Click(object sender, EventArgs e)
        {
            if (tsbPeople.Checked)
            {
                int peopleCount = 0;
                for (int i = 0; i < 225; i++)
                {
                    if (((PictureBox)myArrayList[i]).Image == tsbPeople.Image)
                        peopleCount++;
                    if (peopleCount > 0)
                    {
                        MessageBox.Show("一关中只可有一个小人出现!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                        return;
                    }
                }
            }
            ((PictureBox)sender).Image = ActiveBox.Image;
        }

        private void p_MouseLeave(object sender, EventArgs e)
        {
            ((PictureBox)sender).BackColor = Color.Black;
        }

        private void p_MouseHover(object sender, EventArgs e)
        {
            ((PictureBox)sender).BackColor = Color.Blue;
        }

        private void tsbNull_Click(object sender, EventArgs e)
        {
            tsbLu.Checked = false;
            tsbAim.Checked = false;
            tsbBox.Checked = false;
            tsbWall.Checked = false;
            tsbPeople.Checked = false;
            tsbNull.Checked = true;
            ActiveBox.Image = null;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认要取消以上所有设计吗?", "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
            for (int i = 0; i < 225; i++)
            {
                if (int.Parse((i / 15).ToString()) != 0 && (i - int.Parse((i / 15).ToString()) * 15) != 0 && int.Parse((i / 15).ToString()) != 14 && (i - int.Parse((i / 15).ToString()) * 15) != 14)
                    ((PictureBox)myArrayList[i]).Image = null;
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            int FileCount = 0;
            while (true)
            {
                FileCount++;
                if (!File.Exists(Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap"))
                    break;
            }
            for (int i = 0; i < 225; i++)
            {
                if (((PictureBox)myArrayList[i]).Image==tsbLu.Image)
                {
                    WritePrivateProfileString("Game", "PBox" + i.ToString(), "Lu", Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap");
                }
                if (((PictureBox)myArrayList[i]).Image == tsbAim.Image)
                {
                    WritePrivateProfileString("Game", "PBox" + i.ToString(), "Aim", Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap");
                }
                if (((PictureBox)myArrayList[i]).Image == tsbWall.Image)
                {
                    WritePrivateProfileString("Game", "PBox" + i.ToString(), "Wall", Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap");
                }
                if (((PictureBox)myArrayList[i]).Image == tsbPeople.Image)
                {
                    WritePrivateProfileString("Game", "PBox" + i.ToString(), "People", Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap");
                }
                if (((PictureBox)myArrayList[i]).Image == tsbBox.Image)
                {
                    WritePrivateProfileString("Game", "PBox" + i.ToString(), "Box", Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap");
                }
                if (((PictureBox)myArrayList[i]).Image == null)
                {
                    WritePrivateProfileString("Game", "PBox" + i.ToString(), "null", Application.StartupPath + "\\Level\\" + "Level" + FileCount.ToString() + ".hmap");
                }
            }
            MessageBox.Show("已成功保存为第【★-" + FileCount.ToString() + "-★】关!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            for (int i = 0; i < 225; i++)
            {
                if (int.Parse((i / 15).ToString()) != 0 && (i - int.Parse((i / 15).ToString()) * 15) != 0 && int.Parse((i / 15).ToString()) != 14 && (i - int.Parse((i / 15).ToString()) * 15) != 14)
                    ((PictureBox)myArrayList[i]).Image = null;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -