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

📄 formmain.cs

📁 windows mobile 开发实例wi ndows mobile 开发实例
💻 CS
📖 第 1 页 / 共 2 页
字号:
         // 
         this.mnuSpeedNormal.Text = "Normal";
         this.mnuSpeedNormal.Click += new System.EventHandler(this.mnuSpeed_Click);
         // 
         // mnuSlower
         // 
         this.mnuSlower.Text = "Slower";
         this.mnuSlower.Click += new System.EventHandler(this.mnuSpeed_Click);
         // 
         // mnuSlow
         // 
         this.mnuSlow.Text = "Slow";
         this.mnuSlow.Click += new System.EventHandler(this.mnuSpeed_Click);
         // 
         // mnuSlowest
         // 
         this.mnuSlowest.Text = "Slowest";
         this.mnuSlowest.Click += new System.EventHandler(this.mnuSpeed_Click);
         // 
         // mnuZoom
         // 
         this.mnuZoom.MenuItems.Add(this.mnuInnest);
         this.mnuZoom.MenuItems.Add(this.mnuIn);
         this.mnuZoom.MenuItems.Add(this.mnuSizeNormal);
         this.mnuZoom.MenuItems.Add(this.mnuOut);
         this.mnuZoom.MenuItems.Add(this.mnuOutest);
         this.mnuZoom.Text = "Zoom";
         this.mnuZoom.Click += new System.EventHandler(this.mnuZoom_Click);
         // 
         // mnuInnest
         // 
         this.mnuInnest.Text = "Innest";
         this.mnuInnest.Click += new System.EventHandler(this.mnuZoom_Click);
         // 
         // mnuIn
         // 
         this.mnuIn.Text = "In";
         this.mnuIn.Click += new System.EventHandler(this.mnuZoom_Click);
         // 
         // mnuSizeNormal
         // 
         this.mnuSizeNormal.Text = "Normal";
         this.mnuSizeNormal.Click += new System.EventHandler(this.mnuZoom_Click);
         // 
         // mnuOut
         // 
         this.mnuOut.Text = "Out";
         this.mnuOut.Click += new System.EventHandler(this.mnuZoom_Click);
         // 
         // mnuOutest
         // 
         this.mnuOutest.Text = "Outest";
         this.mnuOutest.Click += new System.EventHandler(this.mnuZoom_Click);
         // 
         // mnuLines
         // 
         this.mnuLines.MenuItems.Add(this.mnuDiagonal);
         this.mnuLines.MenuItems.Add(this.mnuVertical);
         this.mnuLines.MenuItems.Add(this.mnuFlawedVertical);
         this.mnuLines.Text = "Lines";
         // 
         // mnuDiagonal
         // 
         this.mnuDiagonal.Text = "Diagonal";
         this.mnuDiagonal.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuVertical
         // 
         this.mnuVertical.Text = "Vertical";
         this.mnuVertical.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuFlawedVertical
         // 
         this.mnuFlawedVertical.Text = "FlawedVertical";
         this.mnuFlawedVertical.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuCheckers
         // 
         this.mnuCheckers.MenuItems.Add(this.mnuBoard);
         this.mnuCheckers.MenuItems.Add(this.mnuSelfFix);
         this.mnuCheckers.MenuItems.Add(this.mnuSelfDestruct);
         this.mnuCheckers.Text = "Checkers";
         // 
         // mnuBoard
         // 
         this.mnuBoard.Text = "Board";
         this.mnuBoard.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuSelfFix
         // 
         this.mnuSelfFix.Text = "Self Fixing";
         this.mnuSelfFix.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuSelfDestruct
         // 
         this.mnuSelfDestruct.Text = "Self Destructive";
         this.mnuSelfDestruct.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuGliders
         // 
         this.mnuGliders.MenuItems.Add(this.mnuGlider);
         this.mnuGliders.MenuItems.Add(this.mnuGliderMate);
         this.mnuGliders.MenuItems.Add(this.mnuGliderPump);
         this.mnuGliders.Text = "Gliders";
         // 
         // mnuGlider
         // 
         this.mnuGlider.Text = "Single";
         this.mnuGlider.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuGliderMate
         // 
         this.mnuGliderMate.Text = "Mate";
         this.mnuGliderMate.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuGliderPump
         // 
         this.mnuGliderPump.Text = "Pump";
         this.mnuGliderPump.Click += new System.EventHandler(this.mnuPatterns_Click);
         // 
         // mnuAbout
         // 
         this.mnuAbout.Text = "&Help";
         this.mnuAbout.Click += new System.EventHandler(this.mnuAbout_Click);

         // Starting selections
         this.mnuSpeed_Click(this.mnuSpeedNormal, EventArgs.Empty);
         this.mnuZoom_Click(this.mnuSizeNormal, EventArgs.Empty);
      }

      # endregion

      #region Utilities

      private int LittlePowerOfTwo(int exponent)
      {
         //	Don't laugh.  It is not in the CLR 
         //		(except for SQL non-integer types).
         switch( exponent )
         {
            case 0: return 1;
            case 1: return 2;
            case 2: return 4;
            case 3: return 8;
            case 4: return 16;
            case 5: return 32;
            case 6: return 64;
            case 7: return 128;
            case 8: return 256;
            case 9: return 512;
            case 10: return 1024;
            default: return 1024;
         }
      }

      #endregion

      #region Menu Processing
      private void mnuStartStop_Click(object sender, System.EventArgs e)
      {
         //	The Start/Stop button is a toggle.
         boolRun = !boolRun;

         //	If requested to run.
         if( boolRun ) 
         {
            //	Do not allow the user to do certain
            //		things while the game is running.
            btnStartStop.Text = mnuStartStop.Text = "S&top";
            mnuExit.Enabled = false;

            //	Notify the object to start the game.
            refLifeMain.Start();
         }
         else
            //	If requested to stop.
         {
            refLifeMain.Stop();
            btnStartStop.Text = mnuStartStop.Text = "S&tart";
            mnuExit.Enabled = true;
         }
         
      }

      private void mnuExit_Click(object sender, System.EventArgs e)
      {
         Application.Exit();
      }

      private void mnuPatterns_Click(object sender, System.EventArgs e)
      {
         //	Some pattern work best at certain sizes.
         //         if( sender == mnuTenCell ) tbarSize.Value = 7;
         //         if( sender == mnuFlawedVertical ) tbarSize.Value = 7;

         //	Inform the LifeMain object of the 
         //		requested pattern.
         if( sender == mnuEmpty ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpEmpty );
         if( sender == mnuFiveCell ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpFiveCell );
         if( sender == mnuSixCell ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpSixCell );
         if( sender == mnuEightCell ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpEightCell );
         if( sender == mnuTenCell ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpTenCell );
         if( sender == mnuVertical ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpVertical );
         if( sender == mnuFlawedVertical ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpFlawedVertical );
         if( sender == mnuDiagonal ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpDiagonal );
         if( sender == mnuBoard ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpBoard );
         if( sender == mnuSelfFix ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpSelfFix );
         if( sender == mnuSelfDestruct ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpSelfDestruct );
         if( sender == mnuGlider ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpGlider );
         if( sender == mnuGliderMate ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpGliderMate );
         if( sender == mnuGliderPump ) refLifeMain.SetPattern( LifeMain.lgpPattern.lgpGliderPump );

         //	If there is a pattern in the window,
         //		enable the start button and give
         //		it the focus.
         btnStartStop.Enabled = mnuStartStop.Enabled = !(sender == mnuEmpty);
         if( btnStartStop.Enabled ) btnStartStop.Focus();

         //	Prepare to draw the patterns.
         facadeLifeGame.Invalidate();
      }

      private void mnuReset_Click(object sender, System.EventArgs e)
      {
         refLifeMain.Reset();
         facadeLifeGame.Invalidate();
      }

      private void mnuManual_Click(object sender, System.EventArgs e)
      {
         MessageBox.Show("Click in the window to create or alter a pattern");
      }

      private void mnuSpeed_Click(object sender, 
         System.EventArgs e)
      {
         if( refLifeMain == null ) return;
         switch (((MenuItem)sender).Text)
         {
            case "Fastest":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsFastest);
               break;
            case "Fast":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsFast);
               break;
            case "Faster":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsFaster);
               break;
            case "Normal":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsNormal);
               break;
            case "Slower":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsSlower);
               break;
            case "Slow":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsSlow);
               break;
            case "Slowest":
               refLifeMain.ChangeRunSpeed
                  ((int)utilGUI.gameSpeed.gsSlowest);
               break;
         }
      }

      private void mnuZoom_Click(object sender, 
         System.EventArgs e)
      {
         if( refLifeMain == null ) return;
         switch (((MenuItem)sender).Text)
         {
            case "Innest":
               refLifeMain.ChangeDisplaySize
                  ((int)utilGUI.gameZoom.gzInnest);
               break;
            case "In":
               refLifeMain.ChangeDisplaySize
                  ((int)utilGUI.gameZoom.gzIn);
               break;
               //            case "Inner":
               //               refLifeMain.ChangeDisplaySize
               //                  ((int)utilGUI.gameZoom.gzInner);
               //               break;
            case "Normal":
               refLifeMain.ChangeDisplaySize
                  ((int)utilGUI.gameZoom.gzNormal);
               break;
               //            case "Outer":
               //               refLifeMain.ChangeDisplaySize
               //                  ((int)utilGUI.gameZoom.gzOuter);
               //               break;
            case "Out":
               refLifeMain.ChangeDisplaySize
                  ((int)utilGUI.gameZoom.gzOut);
               break;
            case "Outest":
               refLifeMain.ChangeDisplaySize
                  ((int)utilGUI.gameZoom.gzOutest);
               break;
         }
      }

      private void mnuAbout_Click(object sender, System.EventArgs e)
      {
         //	Have the LifeGame object do it.
         refLifeMain.ShowAbout();
      }

      #endregion

      #region Event Handlers

      private void facadeLifeGame_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
      {
         //	The user is entering a pattern,
         //		enable Run.
         btnStartStop.Enabled = mnuStartStop.Enabled = true;
      }

      private void LifeMain_NextGenReady( object sender, EventArgs e )
      {
         // Place a reference to the current and previous
         //    generation into properties of the control.
         //    Then have the control draw the current 
         //    generation.
         this.facadeLifeGame.refCurr = refLifeMain.genCurr;
         this.facadeLifeGame.refPrev = refLifeMain.genPrev;
         this.facadeLifeGame.Invalidate();
         Application.DoEvents();
      }


      private void LifeMain_StableStateReached( object sender, EventArgs e )
      {
         //	Delegate routine.  Called by LifeMain
         //		when the pattern is now static.
         mnuStartStop_Click( this, EventArgs.Empty );
         Application.DoEvents();
         MessageBox.Show("Steady State");
      }

      #endregion

      #region Termination

      private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
      {
         //	If the form is closing, STOP THE GAME.	
         if( refLifeMain != null ) refLifeMain.Stop();
      }

      #endregion

   }
}

⌨️ 快捷键说明

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