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

📄 thrustreetfinder.cs

📁 game implemented java
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsApplication2
{
	/// <summary>
	/// Allows the user to reassign the automatically discovered ThruStreets.
	/// 
	/// Provides mini-map so that user can have some idea of what they are doing.
	/// </summary>
	public class ThruStreetFinder : System.Windows.Forms.Form
	{
		private CityMap myMap;
		private Intersection current;
		private ArrayList segsLeft;
		private System.Windows.Forms.PictureBox mapBox;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ListBox availListBox;
		private System.Windows.Forms.ListBox idListBox;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button addButton;
		private System.Windows.Forms.Button removeButton;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button nextButton;
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;

		public ThruStreetFinder(int interID, CityMap currMap)
		{
			current = (Intersection)currMap.getIntersectionList[interID];
			doThruStreet (current, currMap);
		}
		public ThruStreetFinder(Intersection inter, CityMap currMap)
		{
			doThruStreet(inter,currMap);
		}

		private void doThruStreet (Intersection inter, CityMap currMap)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			myMap = currMap;
			current = inter;
			segsLeft = new ArrayList();

			for (int i=0;i<current.getConnections.Count;i++)
			{
				segsLeft.Add(current.getConnections[i]);
			}
			for (int i=0;i<current.getThruSts.Count;i++)
			{
				ThruStreet toAdd = (ThruStreet)current.getThruSts[i];
				segsLeft.Remove(toAdd.seg1);
				segsLeft.Remove(toAdd.seg2);
				idListBox.Items.Add(i+getThruLable(toAdd));
			}
			for (int i=0; i<segsLeft.Count; i++)
				availListBox.Items.Add(segsLeft[i]+": "+myMap.getSegment((int)segsLeft[i]).StreetName);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.mapBox = new System.Windows.Forms.PictureBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.availListBox = new System.Windows.Forms.ListBox();
			this.idListBox = new System.Windows.Forms.ListBox();
			this.label3 = new System.Windows.Forms.Label();
			this.addButton = new System.Windows.Forms.Button();
			this.removeButton = new System.Windows.Forms.Button();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.nextButton = new System.Windows.Forms.Button();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.SuspendLayout();
			// 
			// mapBox
			// 
			this.mapBox.BackColor = System.Drawing.Color.Black;
			this.mapBox.Location = new System.Drawing.Point(8, 0);
			this.mapBox.Name = "mapBox";
			this.mapBox.Size = new System.Drawing.Size(376, 240);
			this.mapBox.TabIndex = 0;
			this.mapBox.TabStop = false;
			this.mapBox.Paint += new System.Windows.Forms.PaintEventHandler(this.mapBox_Paint);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 256);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 24);
			this.label1.TabIndex = 1;
			this.label1.Text = "Available Blocks";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(208, 256);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(168, 24);
			this.label2.TabIndex = 2;
			this.label2.Text = "Thru Streets Identified";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// availListBox
			// 
			this.availListBox.HorizontalScrollbar = true;
			this.availListBox.Location = new System.Drawing.Point(16, 288);
			this.availListBox.Name = "availListBox";
			this.availListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
			this.availListBox.Size = new System.Drawing.Size(120, 121);
			this.availListBox.TabIndex = 3;
			// 
			// idListBox
			// 
			this.idListBox.HorizontalScrollbar = true;
			this.idListBox.Location = new System.Drawing.Point(208, 288);
			this.idListBox.Name = "idListBox";
			this.idListBox.Size = new System.Drawing.Size(168, 121);
			this.idListBox.TabIndex = 4;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(144, 288);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 24);
			this.label3.TabIndex = 5;
			this.label3.Text = "ADD";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// addButton
			// 
			this.addButton.Location = new System.Drawing.Point(160, 312);
			this.addButton.Name = "addButton";
			this.addButton.Size = new System.Drawing.Size(24, 24);
			this.addButton.TabIndex = 6;
			this.addButton.Text = ">";
			this.addButton.Click += new System.EventHandler(this.addButton_Click);
			// 
			// removeButton
			// 
			this.removeButton.Location = new System.Drawing.Point(160, 376);
			this.removeButton.Name = "removeButton";
			this.removeButton.Size = new System.Drawing.Size(24, 24);
			this.removeButton.TabIndex = 8;
			this.removeButton.Text = "<";
			this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(144, 352);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(56, 24);
			this.label4.TabIndex = 7;
			this.label4.Text = "REMOVE";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 416);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(392, 40);
			this.label5.TabIndex = 9;
			this.label5.Text = "Select one or two available blocks, and ADD them to the list of thru streets.  Yo" +
				"u MUST assign all blocks to Thru Streets";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// nextButton
			// 
			this.nextButton.Enabled = false;
			this.nextButton.Location = new System.Drawing.Point(216, 464);
			this.nextButton.Name = "nextButton";
			this.nextButton.Size = new System.Drawing.Size(160, 24);
			this.nextButton.TabIndex = 10;
			this.nextButton.Text = "CONTINUE >>";
			this.nextButton.Click += new System.EventHandler(this.nextButton_Click);
			// 
			// timer1
			// 
			this.timer1.Enabled = true;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// ThruStreetFinder
			// 
			this.AcceptButton = this.nextButton;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(392, 494);
			this.Controls.Add(this.nextButton);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.removeButton);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.addButton);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.idListBox);
			this.Controls.Add(this.availListBox);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.mapBox);
			this.Name = "ThruStreetFinder";
			this.ShowInTaskbar = false;
			this.Text = "Connect the Streets";
			this.ResumeLayout(false);

		}
		#endregion

		private string getThruLable (ThruStreet ts)
		{
			string segs;

			if (ts.seg2 >= 0)
			{
				segs = " ("+ts.seg1+", "+ts.seg2+")";
			}
			else
				segs = " (Only "+ts.seg1+")";
			return ": "+myMap.getSegment(ts.seg1).StreetName+segs;
		}
		private void mapBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Scaler tempScale = new Scaler();
			tempScale.Height = mapBox.Height;
			tempScale.Width = mapBox.Width;
			current.drawIsolated(e.Graphics,myMap,tempScale);
		}

		private void nextButton_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			if (availListBox.Items.Count == 0)
			{
				nextButton.Enabled = true;
				addButton.Enabled = false;
			}
			else
			{
				nextButton.Enabled = false;
				addButton.Enabled = true;
			}
			if (idListBox.Items.Count == 0)
				removeButton.Enabled = false;
			else
				removeButton.Enabled = true;
		}

		private void addButton_Click(object sender, System.EventArgs e)
		{
			ThruStreet toAdd = new ThruStreet();
			switch (availListBox.SelectedIndices.Count)
			{
				case 1:
					toAdd.seg1 = (int)segsLeft[(int)availListBox.SelectedIndices[0]];
					toAdd.seg2 = -1;
					segsLeft.Remove(toAdd.seg1);
					break;
				case 2:
					toAdd.seg1 = (int)segsLeft[(int)availListBox.SelectedIndices[0]];
					toAdd.seg2 = (int)segsLeft[(int)availListBox.SelectedIndices[1]];
					segsLeft.Remove(toAdd.seg1);
					segsLeft.Remove(toAdd.seg2);
					break;
				default:
					MessageBox.Show("You can only add one or two blocks to a thru street.");
					return;
			}
			toAdd.offset = 0;
			toAdd.timeGreen = 0;
			toAdd.type = Intersection.IS_STOP;
			current.getThruSts.Add(toAdd);
			idListBox.Items.Add(idListBox.Items.Count+getThruLable(toAdd));
			availListBox.Items.Clear();
			for (int i=0; i<segsLeft.Count; i++)
                availListBox.Items.Add(segsLeft[i]+": "+myMap.getSegment((int)segsLeft[i]).StreetName);
		}

		private void removeButton_Click(object sender, System.EventArgs e)
		{
			ThruStreet toRemove = (ThruStreet)current.getThruSts[idListBox.SelectedIndex];
			segsLeft.Add(toRemove.seg1);
			if (toRemove.seg2 >= 0)
				segsLeft.Add(toRemove.seg2);
			availListBox.Items.Clear();
			for (int i=0; i<segsLeft.Count; i++)
				availListBox.Items.Add(segsLeft[i]+": "+myMap.getSegment((int)segsLeft[i]).StreetName);
			current.getThruSts.RemoveAt(idListBox.SelectedIndex);
			idListBox.Items.RemoveAt(idListBox.SelectedIndex);
		}
	
		public CityMap getMap
		{
			get {return myMap;}
		}
	}
}

⌨️ 快捷键说明

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