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

📄 mapeditor.cs

📁 gamecode 很不错的小游戏源代码
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Net;
using System.Threading;
using System.Runtime.CompilerServices;

namespace MapEditor
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class FormMain : System.Windows.Forms.Form
	{
		#region 自定义的成员
		private MapState[,] recoverMapInfo;
		/// <summary>
		/// 银行,商店,或工厂建筑的标志符(与该处的路的方向垂直)(不写入文件,动态加载)
		/// </summary>
		public const int ShowNumber = 49;
		/// <summary>
		/// 大建筑(96 * 96)的占位符(不写入文件,动态加载)
		/// </summary>
		public const int TakeUP = 50;
		/// <summary>
		/// 环境大建筑的占位符(写入BLO文件)
		/// </summary>
		public const int CoverBloNumber = 100;
		/// <summary>
		/// 玩家上限(包括人和电脑)
		/// </summary>
		public const int PlayerMaxNumber = 4;
		/// <summary>
		/// 可设置的经验上限
		/// </summary>
		public const int MaxExp = 50000;
		/// <summary>
		/// 可设置的金钱上限
		/// </summary>
		public const int MaxMoney = 5000000;

		/// <summary>
		/// 客户端监听线程
		/// </summary>
		private Thread threadConnect;
		/// <summary>
		/// 主机通信信道(占用端口8088)
		/// </summary>
		private TcpServerChannel server;
		/// <summary>
		/// 客户端通信信道(任意大于1024的端口)
		/// </summary>
		private TcpClientChannel client;
		/// <summary>
		/// 当前的主机IP地址
		/// </summary>
		private string strServerIPAddress;
		/// <summary>
		/// 当前的连接状态
		/// </summary>
		private string strCurrentState;
		/// <summary>
		/// 连接输入对话框
		/// </summary>
		private MapEditor.FormInputServerIP formInputServerIP;

		/// <summary>
		/// this.panelMap的画图类,负责在当前窗口中画图
		/// </summary>
		private Graphics g;
		/// <summary>
		/// 当前文件是否保存的状态
		/// </summary>
		private bool ifSaved;
		/// <summary>
		/// 记录地图信息的 64 * 48 的二维数组
		/// </summary>
		private MapState[,] map;

		/// <summary>
		/// 鼠标是否按下按下
		/// </summary>
		private bool isDown;
		/// <summary>
		/// 鼠标是否进行拖动操作
		/// </summary>
		private bool isDraging;
		/// <summary>
		/// 当前鼠标在panelMap上的坐标([0,64))
		/// </summary>
		private int downX;
		/// <summary>
		/// 当前鼠标在panelMap上的坐标([0,48))
		/// </summary>
		private int downY;

		/// <summary>
		/// 玩家信息的一维数组,长度为:FormMain.PlayerMaxNumber
		/// </summary>
		private Player[] playerState;
		/// <summary>
		/// 当前人物的ID
		/// </summary>
		private int currentPlayerIndex;
		/// <summary>
		/// tablePage3中的控件是否可用
		/// </summary>
		private bool ifEnabled;
		#endregion

		private System.Windows.Forms.MainMenu mainMenu;
		private System.Windows.Forms.Panel panelMap;
		private System.Windows.Forms.Panel panelPics;
		private System.Windows.Forms.MenuItem menuFile;
		private System.Windows.Forms.MenuItem menuNew;
		private System.Windows.Forms.MenuItem menuOpen;
		private System.Windows.Forms.MenuItem menuSave;
		private System.Windows.Forms.MenuItem menuClose;
		private System.Windows.Forms.SaveFileDialog saveFileDialog;
		private System.Windows.Forms.OpenFileDialog openFileDialog;
		private System.Windows.Forms.ContextMenu contextMenu;
		private System.Windows.Forms.MenuItem menuRefresh;
		private System.Windows.Forms.MenuItem menuConnection;
		private System.Windows.Forms.MenuItem menuNewHost;
		private System.Windows.Forms.MenuItem menuConnectOtherHost;
		private System.Windows.Forms.MenuItem menuCancelConnection;
		private System.Windows.Forms.ImageList imageListSmall;
		private System.Windows.Forms.ImageList imageListBig;
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPageSmall;
		private System.Windows.Forms.GroupBox grpBoxSurrandings;
		private MapEditor.DragSource dragSource20;
		private MapEditor.DragSource dragSource21;
		private MapEditor.DragSource dragSource22;
		private MapEditor.DragSource dragSource23;
		private MapEditor.DragSource dragSource24;
		private MapEditor.DragSource dragSource25;
		private MapEditor.DragSource dragSource26;
		private MapEditor.DragSource dragSource27;
		private MapEditor.DragSource dragSource19;
		private System.Windows.Forms.GroupBox grpBoxLuck;
		private MapEditor.DragSource dragSource17;
		private MapEditor.DragSource dragSource18;
		private System.Windows.Forms.GroupBox grpBoxRandom;
		private MapEditor.DragSource dragSource14;
		private MapEditor.DragSource dragSource15;
		private MapEditor.DragSource dragSource16;
		private System.Windows.Forms.GroupBox grpBoxBuidings;
		private MapEditor.DragSource dragSource6;
		private MapEditor.DragSource dragSource7;
		private MapEditor.DragSource dragSource8;
		private MapEditor.DragSource dragSource9;
		private MapEditor.DragSource dragSource10;
		private MapEditor.DragSource dragSource11;
		private MapEditor.DragSource dragSource12;
		private MapEditor.DragSource dragSource13;
		private System.Windows.Forms.GroupBox grpBoxRoads;
		private MapEditor.DragSource dragSource1;
		private MapEditor.DragSource dragSource2;
		private MapEditor.DragSource dragSource3;
		private MapEditor.DragSource dragSource4;
		private MapEditor.DragSource dragSource5;
		private System.Windows.Forms.TabPage tabPageBig;
		private System.Windows.Forms.GroupBox grpBoxBig;
		private MapEditor.DragSource dragSource28;
		private MapEditor.DragSource dragSource29;
		private MapEditor.DragSource dragSource30;
		private MapEditor.DragSource dragSource31;
		private MapEditor.DragSource dragSource32;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.Panel panelRoadsIn;
		private System.Windows.Forms.Panel panelBuildingsIn;
		private System.Windows.Forms.Panel panelRandomIn;
		private System.Windows.Forms.Panel panelLuckIn;
		private System.Windows.Forms.Panel panelSurrandingsIn;
		private System.Windows.Forms.TabPage tabPagePlayer;
		private System.Windows.Forms.GroupBox grpBoxPlayerPic;
		private System.Windows.Forms.GroupBox grpBoxPlayerAttribute;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.Label labName;
		private System.Windows.Forms.Label labExp;
		private System.Windows.Forms.TextBox txtExp;
		private System.Windows.Forms.TextBox txtMoney;
		private System.Windows.Forms.Label labMoney;
		private System.Windows.Forms.ImageList imageListPlayer;
		private MapEditor.DragSource dragSource33;
		private MapEditor.DragSource dragSource34;
		private MapEditor.DragSource dragSource35;
		private MapEditor.DragSource dragSource36;
		private System.Windows.Forms.RadioButton radBtnComputer;
		private System.Windows.Forms.RadioButton radBtnPlayer;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Panel panelBigIn;
		private System.Windows.Forms.Panel panelPlayerIn;
		private MapEditor.DragSource dragSource37;
		private MapEditor.DragSource dragSource38;
		private MapEditor.DragSource dragSource39;
		private MapEditor.DragSource dragSource40;
		private MapEditor.DragSource dragSource41;
		private MapEditor.DragSource dragSource42;
		private MapEditor.DragSource dragSource43;
		private MapEditor.DragSource dragSource44;
		private MapEditor.DragSource dragSource45;
		private MapEditor.DragSource dragSource46;
		private MapEditor.DragSource dragSource47;
		private MapEditor.DragSource dragSource48;
		private MapEditor.DragSource dragSource49;
		private MapEditor.DragSource dragSource50;
		private MapEditor.DragSource dragSource51;
		private MapEditor.DragSource dragSource52;
		private MapEditor.DragSource dragSource53;
		private MapEditor.DragSource dragSource54;
		private MapEditor.DragSource dragSource55;
		private MapEditor.DragSource dragSource56;
		private MapEditor.DragSource dragSource57;
		private MapEditor.DragSource dragSource58;
		private MapEditor.DragSource dragSource59;
		private MapEditor.DragSource dragSource60;
		private MapEditor.DragSource dragSource61;
		private MapEditor.DragSource dragSource62;
		private MapEditor.DragSource dragSource63;
		private MapEditor.DragSource dragSource64;
		private MapEditor.DragSource dragSource65;
		private MapEditor.DragSource dragSource66;
		private MapEditor.DragSource dragSource67;
		private MapEditor.DragSource dragSource68;
		private MapEditor.DragSource dragSource69;
		private MapEditor.DragSource dragSource70;
		private MapEditor.DragSource dragSource71;
		private System.Windows.Forms.ToolTip toolTip;
		private System.ComponentModel.IContainer components;

		public FormMain()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			this.recoverMapInfo = new MapState[64,48];
			for(int i = 0;i < 64;i++)
			{
				for(int j = 0;j < 48;j++)
				{
					this.recoverMapInfo[i,j].fileIndex = 0;
					this.recoverMapInfo[i,j].imageIndex = 5;
				}
			}
			//设置说明符
			this.toolTip.SetToolTip(this.dragSource19,"默认背景");
			this.toolTip.SetToolTip(this.dragSource6,"银行");
			this.toolTip.SetToolTip(this.dragSource7,"商店");
			this.toolTip.SetToolTip(this.dragSource8,"汽车");
			this.toolTip.SetToolTip(this.dragSource9,"食品");
			this.toolTip.SetToolTip(this.dragSource10,"矿厂");
			this.toolTip.SetToolTip(this.dragSource11,"纺织厂");
			this.toolTip.SetToolTip(this.dragSource12,"冶炼厂");
			this.toolTip.SetToolTip(this.dragSource13,"房子");
			this.toolTip.SetToolTip(this.dragSource42,"酒店");

			//初始化成员变量的信息
			this.ifEnabled = false;
			this.currentPlayerIndex = -1;
			this.playerState = new Player[FormMain.PlayerMaxNumber];
			for(int i = 0;i < FormMain.PlayerMaxNumber;i++)
			{
				this.playerState[i].imageIndex = i;
				this.playerState[i].isPlayer = true;
				this.playerState[i].money = 0;
				this.playerState[i].name = "";
				this.playerState[i].x = -1;
				this.playerState[i].y = -1;
				this.playerState[i].exp = 0;
			}

			this.isDown = false;
			this.isDraging = false;
			this.downX = 0;
			this.downY = 0;

			//DragSource a = new DragSource();
			//MessageBox.Show(a.ImageIndex.ToString() + " " + a.FileIndex.ToString());
			this.g = this.panelMap.CreateGraphics();
			this.InitImageLists();
			this.InitDragSources();

			DragSource.thisControl = this.dragSource6;
			DragSource.thisControl.BorderStyle = BorderStyle.Fixed3D;
			//MessageBox.Show(DragSource.thisControl.ImageIndex.ToString());

			this.formInputServerIP = new FormInputServerIP();

			this.server = null;
			this.client = null;
			this.strServerIPAddress = "";

			this.strCurrentState = "无连接";

			this.ifSaved = true;

			this.map = new MapState[64,48];
			for(int i = 0;i < 64;i++)
			{
				for(int j = 0;j < 48;j++)
				{
					map[i,j].imageIndex = 5;
					map[i,j].fileIndex = 0;
				}
			}
		}

		public MapState[,] Map
		{
			get
			{
				return this.map;
			}
			set
			{
				this.map = value;
			}
		}

		public Panel PanelMap
		{
			get
			{
				return this.panelMap;
			}
		}

⌨️ 快捷键说明

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