📄 form1.cs
字号:
// menuItem4
//
this.menuItem4.Index = 3;
this.menuItem4.Text = "&Exit";
this.menuItem4.Click += new System.EventHandler(this.OnExit);
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem8,
this.menuItem12,
this.menuItem10});
this.menuItem7.Text = "Edit";
//
// menuItem8
//
this.menuItem8.Index = 0;
this.menuItem8.Text = "Enter Edit Mode";
this.menuItem8.Click += new System.EventHandler(this.OnEnterEditMode);
//
// menuItem12
//
this.menuItem12.Index = 1;
this.menuItem12.Text = "Leave Edit Mode";
this.menuItem12.Click += new System.EventHandler(this.OnEnterEditMode);
//
// menuItem10
//
this.menuItem10.Enabled = false;
this.menuItem10.Index = 2;
this.menuItem10.Text = "Clear Current Map";
//
// menuItem6
//
this.menuItem6.Index = 2;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.loadStandardMenu,
this.loadPreviousMenu,
this.menuItem9,
this.loadMapMenu});
this.menuItem6.Text = "Load";
//
// loadStandardMenu
//
this.loadStandardMenu.Checked = true;
this.loadStandardMenu.Index = 0;
this.loadStandardMenu.Text = "Load Standard";
this.loadStandardMenu.Click += new System.EventHandler(this.OnLoadStandardClick);
//
// loadPreviousMenu
//
this.loadPreviousMenu.Enabled = false;
this.loadPreviousMenu.Index = 1;
this.loadPreviousMenu.Text = "Load Previous";
this.loadPreviousMenu.Click += new System.EventHandler(this.OnLoadPreviousClick);
//
// menuItem9
//
this.menuItem9.Index = 2;
this.menuItem9.Text = "-";
//
// loadMapMenu
//
this.loadMapMenu.Index = 3;
this.loadMapMenu.Text = "Load Map";
this.loadMapMenu.Click += new System.EventHandler(this.OnLoadMap);
//
// menuItem13
//
this.menuItem13.Index = 3;
this.menuItem13.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.saveCurrentMap});
this.menuItem13.Text = "Save";
//
// saveCurrentMap
//
this.saveCurrentMap.Index = 0;
this.saveCurrentMap.Text = "Save Current Map";
this.saveCurrentMap.Click += new System.EventHandler(this.OnSaveCurrentMap);
//
// updateTimer
//
this.updateTimer.Tick += new System.EventHandler(this.OnUpdateTimer);
//
// pheromoneDecayTimer
//
this.pheromoneDecayTimer.Interval = 10;
this.pheromoneDecayTimer.Tick += new System.EventHandler(this.OnPheromoneDecay);
//
// editTimer
//
this.editTimer.Tick += new System.EventHandler(this.OnEditTimerTick);
//
// pathFinderContextMenu
//
this.pathFinderContextMenu.Popup += new System.EventHandler(this.OnpathFinderContextMenuPopup);
//
// displayLabel
//
this.displayLabel.Location = new System.Drawing.Point(0, 376);
this.displayLabel.Name = "displayLabel";
this.displayLabel.Size = new System.Drawing.Size(608, 23);
this.displayLabel.TabIndex = 25;
this.displayLabel.Text = "Test Text";
this.displayLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 657);
this.Controls.Add(this.displayLabel);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Path Finder";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.timerInterval)).EndInit();
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
/// <summary>
/// show the last entry in the ap[plication log to the display label
/// </summary>
private void DisplayLog()
{
if( DisplayLogs == true )
{
displayLabel.Text = ApplicationLog.GetLatest();
}
}
private void LogString( string strLog )
{
ApplicationLog.Log( "PathFinder", strLog );
DisplayLog();
}
private void OnStart(object sender, System.EventArgs e)
{
this.startButton.Text = "Start";
bIsRunning = true;
if( bIsStart == true )
{
bIsStart = false;
Start();
}
if( bIsPaused == true )
{
bIsPaused = false;
}
this.stopButton.Enabled = true;
LogString( "Started" );
}
private void OnStop(object sender, System.EventArgs e)
{
this.startButton.Text = "Continue";
this.startButton.Enabled = true;
bIsRunning = false;
if( critter == CrittersSet.ANT )
{
pheromoneDecayTimer.Stop();
}
bIsPaused = true;
}
private void OnExit(object sender, System.EventArgs e)
{
if( bIsRunning == true )
{
OnStop( sender, e );
updateTimer.Stop();
updateTimer.Enabled = false;
}
Application.Exit();
}
private void Start()
{
int nCount = 0;
if( critter == CrittersSet.ANT )
{
LogString( "Starting using the Critter Set for the Ants" );
nCount = antsGeneralPage.NumberOfAnts;
NestSquare nest = null;
/// Find the Ants Nest Square ( Assuming One only )
for( int i=0; i<squaresArray.Count; i++ )
{
if( squaresArray[ i ] != null )
{
if( ( ( StandardSquare )squaresArray[ i ] ).SquareType == "NEST" )
{
nest = ( NestSquare )squaresArray[ i ];
i = squaresArray.Count;
}
}
}
if( nest == null )
{
bIsStart = true;
this.stopButton.Enabled = false;
MessageBox.Show( "Error the map does not contain a nest square" );
return;
}
/// create the ants
for( int i=0; i<nCount; i++ )
{
crittersArray.Add( new Ant() );
}
int nBehaviourChanged = antsGeneralPage.NumberOfAffectedAnts;
/// see if anyones playing silly buggers
if( nBehaviourChanged > nCount )
{
nBehaviourChanged = nCount;
antsGeneralPage.NumberOfAffectedAnts = nCount;
}
/// set the number of ants to pretty much wander around aimlessly
for( int i=0; i<nBehaviourChanged; i++ )
{
( ( Ant )crittersArray[ i ] ).DontAlwaysFollowStrongestPheromone = true;
}
/// set the ants up on the home square
for( int i=0; i<crittersArray.Count; i++ )
{
/// remember the home square identifiers
( ( Critter )crittersArray[ i ] ).Left = nest.Left;
( ( Critter )crittersArray[ i ] ).Right = nest.Right;
( ( Critter )crittersArray[ i ] ).Vertical = nest.Location.Y;
( ( Critter )crittersArray[ i ] ).Algorythm = algorythm;
/// draw the ant on the square
nest.DrawAnt = true;
nest.IsCritterOnSquare = true;
nest.CritterIsAnt = true;
/// didn't move here from anywhere
( ( Critter )crittersArray[ i ] ).LastDirectionTravelled = ( int )DirectionLastTravelledSet.NONE;
( ( Ant )crittersArray[ i ] ).TryToAvoidOccupiedSquares = true;
}
/// start the pheromone decay timer
pheromoneDecayTimer.Enabled = true;
pheromoneDecayTimer.Start();
/// start the update timer
updateTimer.Enabled = true;
updateTimer.Start();
/// redraw the nest square
nest.Invalidate();
}
else if( critter == CrittersSet.AMEOBA )
{
LogString( "Starting using the Critter Set for the Ameoba" );
crittersArray.Add( new Ameoba() );
updateTimer.Enabled = true;
updateTimer.Start();
Random rand = new Random();
int nLocation = rand.Next( squaresArray.Count );
if( squaresArray[ nLocation ] != null )
{
( ( StandardSquare )squaresArray[ nLocation ] ).CritterIsAnt = false;
( ( StandardSquare )squaresArray[ nLocation ] ).CritterIsAmeoba = true;
}
}
this.useAmeobaCheckBox.Enabled = false;
this.useAntsCheckBox.Enabled = false;
this.useBasicCheckBox.Enabled = false;
this.useBasic2CheckBox.Enabled = false;
this.pheromonesCheckBox.Enabled = false;
this.memoryCheckBox.Enabled = false;
this.hillClimbingCheckBox.Enabled = false;
this.startButton.Enabled = false;
this.useHillClimbingTwoAlgorythmCheckBox.Enabled = false;
this.useHillClimbingThreeAlgorythmCheckBox.Enabled = false;
}
/// <summary>
/// when the main timer fires stop and restart it as later there could be time constraints
/// trying to work everything out.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnUpdateTimer(object sender, System.EventArgs e)
{
/// if stopped well stop
if( bIsRunning == false )
return;
if( bIsPaused == true )
return;
updateTimer.Stop();
/// check if the update timer value has been changed
if( updateTimer.Interval != ( ( int )timerInterval.Value * 1000 ) )
{
updateTimer.Interval = ( int )timerInterval.Value * 1000;
}
/// get the current number of critters
int nCount = crittersArray.Count;
/// check if dealling with ants
if( critter == CrittersSet.ANT )
{
NestSquare nest = null;
/// Find the Ants Nest Square ( Assuming One only )
for( int i=0; i<squaresArray.Count; i++ )
{
if( squaresArray[ i ] != null )
{
if( ( ( StandardSquare )squaresArray[ i ] ).SquareType == "NEST" )
{
nest = ( NestSquare )squaresArray[ i ];
i = squaresArray.Count;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -