Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Reversi in C#

, 26 Sep 2005
The game of Reversi in C#.
reversi_exe.zip
Reversi
Reversi.chm
Reversi.exe
reversi_src.zip
bin
Release
help files
App.ico
figures.psp
Index.hhk
newGame.gif
redoAllMoves.gif
redoMove.gif
resignGame.gif
resumePlay.gif
Reversi.chm
Reversi.hhp
rulesFigure1.gif
rulesFigure2.gif
rulesFigure3.gif
rulesFigure4.gif
rulesFigure5.gif
rulesFigure6.gif
rulesFigure7.gif
rulesFigure8.gif
rulesFigure9.gif
strategyFigure1.gif
strategyFigure10.gif
strategyFigure11.gif
strategyFigure12.gif
strategyFigure13.gif
strategyFigure14.gif
strategyFigure2.gif
strategyFigure3.gif
strategyFigure4.gif
strategyFigure5.gif
strategyFigure6.gif
strategyFigure7.gif
strategyFigure8.gif
strategyFigure9.gif
Table of Contents.hhc
undoAllMoves.gif
undoMove.gif
newGame.gif
redoAllMoves.gif
redoMove.gif
resignGame.gif
resumePlay.gif
Reversi.csproj.user
undoAllMoves.gif
undoMove.gif
using System;
using System.Drawing;
using System.Xml;

namespace Reversi
{
	/// <summary>
	/// Summary description for ProgramSettings.
	/// </summary>
	public class ProgramSettings
	{
		// The file name used to save the program settings.
		private string fileName;

		// An Xml document used to store and save program settings.
		private XmlDocument document;

		public ProgramSettings(string fileName)
		{
			//
			// TODO: Add constructor logic here
			//

			// Assign the file name.
			this.fileName = fileName;

			// If the file already exists, load it. Otherwise, create a new document.
			this.document = new XmlDocument();
			try
			{
				document.Load(this.fileName);
			}
			catch (Exception ex)
			{
				// Create a new XML document and set the root node.
				document = new XmlDocument();
				document.AppendChild(document.CreateElement("ProgramSettings"));
			}
		}

		//
		// Saves the settings XML file.
		//
		public void Save()
		{
			this.document.Save(this.fileName);
		}

		//
		// Reads a value from the settings file.
		//
		public string GetValue(string section, string name)
		{
			try
			{
				return this.document.DocumentElement.SelectSingleNode(section + "/" + name).InnerText;
			}
			catch (Exception ex)
			{
				return "";
			}
		}

		//
		// Writes a value to the settings file.
		//
		public void SetValue(string section, string name, string value)
		{
			// If the section does not exist, create it.
			XmlNode sectionNode = this.document.DocumentElement.SelectSingleNode(section);
			if (sectionNode == null)
				sectionNode = this.document.DocumentElement.AppendChild(this.document.CreateElement(section));
			// If the node does not exist, create it.
			XmlNode node = sectionNode.SelectSingleNode(name);
			if (node == null)
				node = sectionNode.AppendChild(this.document.CreateElement(name));

			// Set the value.
			node.InnerText = 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

Share

About the Author

BrainJar
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150123.1 | Last Updated 26 Sep 2005
Article Copyright 2003 by BrainJar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid