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

📄 myblockmain.cs

📁 这个程序是基于c#平台的俄罗斯方框游戏。拿来共享。要求加分哦!
💻 CS
📖 第 1 页 / 共 5 页
字号:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Resources;
using System.Threading;
using System.Globalization;
using Microsoft.Win32;

namespace AnotherBlock
{
	/// <summary>
	/// Main interface for the Another Block game.
	/// </summary>
	public class AnotherBlockMain : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components;

		/// <summary>
		/// "Game" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuGame;
		/// <summary>
		/// "Start Game" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuStartGame;
		/// <summary>
		/// "Start At..." menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuStartAt;
		/// <summary>
		/// "Pause" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuPause;
		/// <summary>
		/// "High Scores..." menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuHighScores;
		/// <summary>
		/// "Exit" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuExit;
		/// <summary>
		/// "Options" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuOptions;
		/// <summary>
		/// "Sounds" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuSounds;
		/// <summary>
		/// "Music" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuMusic;
		/// <summary>
		/// Main application menu.
		/// </summary>
		private System.Windows.Forms.MainMenu mainMenu;
		/// <summary>
		/// Timer that makes the game loop.
		/// </summary>
		private System.Windows.Forms.Timer tmrTimer;
		/// <summary>
		/// Menu separator.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuSeparator1;
		/// <summary>
		/// Menu separator.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuSeparator2;
		/// <summary>
		/// Picture box that is the game board (playing field).
		/// </summary>
		private System.Windows.Forms.PictureBox picPlayingField;
		/// <summary>
		/// Picture box that shows the next block.
		/// </summary>
		private System.Windows.Forms.PictureBox picNextBlock;
		/// <summary>
		/// Label with the text "Score: ".
		/// </summary>
		private System.Windows.Forms.Label lblTextScore;
		/// <summary>
		/// Label with the current game score.
		/// </summary>
		private System.Windows.Forms.Label lblScore;
		/// <summary>
		/// Label with the current game lines.
		/// </summary>
		private System.Windows.Forms.Label lblLines;
		/// <summary>
		/// Label with the text "Lines: ".
		/// </summary>
		private System.Windows.Forms.Label lblTextLines;
		/// <summary>
		/// Label with the current game level.
		/// </summary>
		private System.Windows.Forms.Label lblLevel;
		/// <summary>
		/// Label with the text "Level: ".
		/// </summary>
		private System.Windows.Forms.Label lblTextLevel;
		/// <summary>
		/// Label with the text "Next: ".
		/// </summary>
		private System.Windows.Forms.Label lblTextNextBlock;
		/// <summary>
		/// Menu separator.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuSeparator3;
		/// <summary>
		/// "Rotate Clockwise" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuRotateClockwise;
		/// <summary>
		/// "Rotate Counterclockwise" menu.
		/// </summary>
		private System.Windows.Forms.MenuItem mnuRotateCounterclockwise;

		/// <summary>
		/// Private constant with the initial interval for the blocks to fall, in miliseconds.
		/// </summary>
		private const int basicInterval = 600;

		/// <summary>
		/// Private attribute with the instance of the Game class, that will hold the current playing game.
		/// </summary>
		private Game game = null;
		/// <summary>
		/// Private attribute that holds the sound for a complete line.
		/// </summary>
		private Sound soundLine;
		/// <summary>
		/// Private attribute that holds the sound for a level.
		/// </summary>
		private Sound soundLevel;
		/// <summary>
		/// Private attribute that holds the sound for a block hit.
		/// </summary>
		private Sound soundHit;
		/// <summary>
		/// Private attribute that holds the sound for the background music.
		/// </summary>
		private Sound soundMusic;
		/// <summary>
		/// Private attribute that holds if the block is not to be moved down with key command.
		/// </summary>
		private bool dontMoveDown = false;
		/// <summary>
		/// Private attribute that holds the resource file with the localized resource strings.
		/// </summary>
		private ResourceManager resources = new ResourceManager("AnotherBlock.Resources", typeof(AnotherBlockMain).Assembly);

		/// <summary>
		/// Class constructor that creates the main interface for the Another Block game.
		/// </summary>
		public AnotherBlockMain()
		{
			// Define the culture to be used.
			Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;

			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			// Checks if the registry entries are right.
			CheckForRegistryEntries();

			// Make the size of the interface right.
			picPlayingField.Height = Game.PlayingFieldHeight * Game.BlockImageHeight;
			picPlayingField.Width = Game.PlayingFieldWidth * Game.BlockImageWidth;

			// Get the configurations from the registry.
			GetConfigs();

			// Loads the sounds.
			soundLevel = new Sound(this);
			soundLevel.Load("sounds/level.mp3");
			soundLine = new Sound(this);
			soundLine.Load("sounds/line.mp3");
			soundHit = new Sound(this);
			soundHit.Load("sounds/hit.mp3");
			soundMusic = new Sound(this);
			// Loads the music and checks if it was loaded correctly.
			if (soundMusic.Load("sounds/music.mp3"))
			{
				// It was loaded correctly.
				// Sets the loop property to true.
				soundMusic.Loop = true;
			}
			else
			{
				// It was not loaded correctly.
				// Disable the "Music" menu.
				mnuMusic.Checked = false;
				mnuMusic.Enabled = false;
			}
		}

		/// <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();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AnotherBlockMain));
			this.mainMenu = new System.Windows.Forms.MainMenu();
			this.mnuGame = new System.Windows.Forms.MenuItem();
			this.mnuStartGame = new System.Windows.Forms.MenuItem();
			this.mnuStartAt = new System.Windows.Forms.MenuItem();
			this.mnuPause = new System.Windows.Forms.MenuItem();
			this.mnuSeparator1 = new System.Windows.Forms.MenuItem();
			this.mnuHighScores = new System.Windows.Forms.MenuItem();
			this.mnuSeparator2 = new System.Windows.Forms.MenuItem();
			this.mnuExit = new System.Windows.Forms.MenuItem();
			this.mnuOptions = new System.Windows.Forms.MenuItem();
			this.mnuSounds = new System.Windows.Forms.MenuItem();
			this.mnuMusic = new System.Windows.Forms.MenuItem();
			this.mnuSeparator3 = new System.Windows.Forms.MenuItem();
			this.mnuRotateClockwise = new System.Windows.Forms.MenuItem();
			this.mnuRotateCounterclockwise = new System.Windows.Forms.MenuItem();
			this.tmrTimer = new System.Windows.Forms.Timer(this.components);
			this.picPlayingField = new System.Windows.Forms.PictureBox();
			this.lblTextScore = new System.Windows.Forms.Label();
			this.lblScore = new System.Windows.Forms.Label();
			this.lblLines = new System.Windows.Forms.Label();
			this.lblTextLines = new System.Windows.Forms.Label();
			this.lblLevel = new System.Windows.Forms.Label();
			this.lblTextLevel = new System.Windows.Forms.Label();
			this.lblTextNextBlock = new System.Windows.Forms.Label();
			this.picNextBlock = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// mainMenu
			// 
			this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.mnuGame,
																					 this.mnuOptions});
			this.mainMenu.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("mainMenu.RightToLeft")));
			// 
			// mnuGame
			// 
			this.mnuGame.Enabled = ((bool)(resources.GetObject("mnuGame.Enabled")));
			this.mnuGame.Index = 0;
			this.mnuGame.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					this.mnuStartGame,
																					this.mnuStartAt,
																					this.mnuPause,
																					this.mnuSeparator1,
																					this.mnuHighScores,
																					this.mnuSeparator2,
																					this.mnuExit});
			this.mnuGame.Shortcut = ((System.Windows.Forms.Shortcut)(resources.GetObject("mnuGame.Shortcut")));
			this.mnuGame.ShowShortcut = ((bool)(resources.GetObject("mnuGame.ShowShortcut")));
			this.mnuGame.Text = resources.GetString("mnuGame.Text");
			this.mnuGame.Visible = ((bool)(resources.GetObject("mnuGame.Visible")));
			// 
			// mnuStartGame
			// 
			this.mnuStartGame.Enabled = ((bool)(resources.GetObject("mnuStartGame.Enabled")));
			this.mnuStartGame.Index = 0;

⌨️ 快捷键说明

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