Click here to Skip to main content
15,880,796 members
Articles / Mobile Apps

A C# implementation of Reversi (Othello) Game for PocketPC and Windows

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
4 Aug 20043 min read 91.4K   4.4K   36  
A C# implementation of Reversi (Othello) Game for PocketPC and Windows.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using gma.Reversi;

namespace gma.Windows.Reversi
{
	/// <summary>
	/// Zusammenfassung f�r frmStartGame.
	/// </summary>
	public class frmStartGame : System.Windows.Forms.Form
	{
		private System.Windows.Forms.NumericUpDown numericUpDownAnimationSpeed;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button buttonCancel;
		private System.Windows.Forms.NumericUpDown numericUpDownDificulcy;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button buttonOk;
		private System.Windows.Forms.RadioButton radioButtonColor2;
		private System.Windows.Forms.RadioButton radioButtonColor1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.CheckBox checkBoxEnableUndo;
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmStartGame()
		{
			//
			// Erforderlich f�r die Windows Form-Designerunterst�tzung
			//
			InitializeComponent();

			//
			// TODO: F�gen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
			//
		}

		/// <summary>
		/// Die verwendeten Ressourcen bereinigen.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Vom Windows Form-Designer generierter Code
		/// <summary>
		/// Erforderliche Methode f�r die Designerunterst�tzung. 
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor ge�ndert werden.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmStartGame));
			this.numericUpDownAnimationSpeed = new System.Windows.Forms.NumericUpDown();
			this.label3 = new System.Windows.Forms.Label();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.numericUpDownDificulcy = new System.Windows.Forms.NumericUpDown();
			this.label2 = new System.Windows.Forms.Label();
			this.buttonOk = new System.Windows.Forms.Button();
			this.radioButtonColor2 = new System.Windows.Forms.RadioButton();
			this.radioButtonColor1 = new System.Windows.Forms.RadioButton();
			this.label1 = new System.Windows.Forms.Label();
			this.checkBoxEnableUndo = new System.Windows.Forms.CheckBox();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownAnimationSpeed)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownDificulcy)).BeginInit();
			this.SuspendLayout();
			// 
			// numericUpDownAnimationSpeed
			// 
			this.numericUpDownAnimationSpeed.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.numericUpDownAnimationSpeed.Location = new System.Drawing.Point(72, 128);
			this.numericUpDownAnimationSpeed.Maximum = new System.Decimal(new int[] {
																						10,
																						0,
																						0,
																						0});
			this.numericUpDownAnimationSpeed.Minimum = new System.Decimal(new int[] {
																						1,
																						0,
																						0,
																						0});
			this.numericUpDownAnimationSpeed.Name = "numericUpDownAnimationSpeed";
			this.numericUpDownAnimationSpeed.Size = new System.Drawing.Size(64, 20);
			this.numericUpDownAnimationSpeed.TabIndex = 9;
			this.numericUpDownAnimationSpeed.Value = new System.Decimal(new int[] {
																					  1,
																					  0,
																					  0,
																					  0});
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 104);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(128, 20);
			this.label3.TabIndex = 10;
			this.label3.Text = "Animation Speed:";
			// 
			// buttonCancel
			// 
			this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.buttonCancel.Location = new System.Drawing.Point(120, 192);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.TabIndex = 11;
			this.buttonCancel.Text = "Cancel";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// numericUpDownDificulcy
			// 
			this.numericUpDownDificulcy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.numericUpDownDificulcy.Location = new System.Drawing.Point(72, 72);
			this.numericUpDownDificulcy.Maximum = new System.Decimal(new int[] {
																				   10,
																				   0,
																				   0,
																				   0});
			this.numericUpDownDificulcy.Minimum = new System.Decimal(new int[] {
																				   1,
																				   0,
																				   0,
																				   0});
			this.numericUpDownDificulcy.Name = "numericUpDownDificulcy";
			this.numericUpDownDificulcy.Size = new System.Drawing.Size(64, 20);
			this.numericUpDownDificulcy.TabIndex = 12;
			this.numericUpDownDificulcy.Value = new System.Decimal(new int[] {
																				 1,
																				 0,
																				 0,
																				 0});
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 72);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 20);
			this.label2.TabIndex = 13;
			this.label2.Text = "Dificulcy:";
			// 
			// buttonOk
			// 
			this.buttonOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.buttonOk.Location = new System.Drawing.Point(40, 192);
			this.buttonOk.Name = "buttonOk";
			this.buttonOk.TabIndex = 14;
			this.buttonOk.Text = "Ok";
			this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
			// 
			// radioButtonColor2
			// 
			this.radioButtonColor2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.radioButtonColor2.Location = new System.Drawing.Point(80, 35);
			this.radioButtonColor2.Name = "radioButtonColor2";
			this.radioButtonColor2.TabIndex = 15;
			this.radioButtonColor2.Text = "White";
			this.radioButtonColor2.CheckedChanged += new System.EventHandler(this.radioButtonColor2_CheckedChanged);
			// 
			// radioButtonColor1
			// 
			this.radioButtonColor1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.radioButtonColor1.Location = new System.Drawing.Point(80, 11);
			this.radioButtonColor1.Name = "radioButtonColor1";
			this.radioButtonColor1.TabIndex = 16;
			this.radioButtonColor1.Text = "Black";
			this.radioButtonColor1.CheckedChanged += new System.EventHandler(this.radioButtonColor1_CheckedChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 13);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(88, 20);
			this.label1.TabIndex = 17;
			this.label1.Text = "My color is:";
			// 
			// checkBoxEnableUndo
			// 
			this.checkBoxEnableUndo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBoxEnableUndo.Location = new System.Drawing.Point(8, 160);
			this.checkBoxEnableUndo.Name = "checkBoxEnableUndo";
			this.checkBoxEnableUndo.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
			this.checkBoxEnableUndo.Size = new System.Drawing.Size(88, 24);
			this.checkBoxEnableUndo.TabIndex = 18;
			this.checkBoxEnableUndo.Text = "Enable Undo";
			// 
			// frmStartGame
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(200, 223);
			this.Controls.Add(this.checkBoxEnableUndo);
			this.Controls.Add(this.numericUpDownAnimationSpeed);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.numericUpDownDificulcy);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.buttonOk);
			this.Controls.Add(this.radioButtonColor2);
			this.Controls.Add(this.radioButtonColor1);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmStartGame";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Game Options";
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownAnimationSpeed)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDownDificulcy)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void buttonOk_Click(object sender, System.EventArgs e)
		{
			DialogResult=DialogResult.OK;
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			DialogResult=DialogResult.Cancel;
		}

		private void radioButtonColor1_CheckedChanged(object sender, System.EventArgs e)
		{
		
		}

		private void radioButtonColor2_CheckedChanged(object sender, System.EventArgs e)
		{
		
		}

		public int MyColor
		{
			get 
			{
				if (radioButtonColor1.Checked) return Board.PLAYER_RED;  
				else return Board.PLAYER_WHITE;  
			}
			set 
			{
				radioButtonColor1.Checked = (value==Board.PLAYER_RED);
				radioButtonColor2.Checked = (value!=Board.PLAYER_RED);
			}
		}

		public int SearchDepth
		{
			get { return (int)numericUpDownDificulcy.Value;} 
			set {numericUpDownDificulcy.Value=value;}
		}

		public int AnimationSpeed
		{
			get { return (int)numericUpDownAnimationSpeed.Value;} 
			set {numericUpDownAnimationSpeed.Value=value;}
		}

		public bool EnableUndo
		{
			get { return checkBoxEnableUndo.Checked;}
			set {checkBoxEnableUndo.Checked=value;}
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Germany Germany
Tweeter: @gmamaladze
Google+: gmamaladze
Blog: gmamaladze.wordpress.com

Comments and Discussions