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

WPF Alien Sokoban

, 16 Jun 2008 BSD
A fun implementation of the game Sokoban, written to showcase some features of WPF, C# 3.0, Expression Design, and Visual Studio 2008.
wpfsokobandemo.zip
WpfSokobanDemo
Levels
Level000.skbn
Level000.skbn.test
Level001.skbn
Level002.skbn
Level003.skbn
Level004.skbn
Level005.skbn
Level006.skbn
Level007.skbn
Level008.skbn
Level009.skbn
Level010.skbn
Level011.skbn
Level012.skbn
Level013.skbn
Level014.skbn
Level015.skbn
Level016.skbn
Level017.skbn
Level018.skbn
Level019.skbn
Level020.skbn
Level021.skbn
Level022.skbn
Level023.skbn
Level024.skbn
Level025.skbn
Level026.skbn
Level027.skbn
Level028.skbn
Level029.skbn
Level030.skbn
Level031.skbn
Level032.skbn
Level033.skbn
Level034.skbn
Level035.skbn
Level036.skbn
Level037.skbn
Level038.skbn
Level039.skbn
Level040.skbn
Level041.skbn
Level042.skbn
Level043.skbn
Level044.skbn
Level045.skbn
Level046.skbn
Level047.skbn
Level048.skbn
Level049.skbn
Level050.skbn
Source
WpfSokoban
Audio
DingDong.wav
DullClapping.mp3
Footstep.wav
Intro.wav
Movement_from_NEO_Sounds.mp3
TreasurePush.wav
bin
Release
Orpius.Sokoban.dll
WpfSokoban.exe
WpfSokoban.vshost.exe
WpfSokoban.vshost.exe.manifest
Images
AppIcon.ico
AppIcon.png
wpfsokobansource.zip
WpfSokobanSource
Graphics
Banner.design
Cell.design
Levels
Level000.skbn
Level000.skbn.test
Level001.skbn
Level002.skbn
Level003.skbn
Level004.skbn
Level005.skbn
Level006.skbn
Level007.skbn
Level008.skbn
Level009.skbn
Level010.skbn
Level011.skbn
Level012.skbn
Level013.skbn
Level014.skbn
Level015.skbn
Level016.skbn
Level017.skbn
Level018.skbn
Level019.skbn
Level020.skbn
Level021.skbn
Level022.skbn
Level023.skbn
Level024.skbn
Level025.skbn
Level026.skbn
Level027.skbn
Level028.skbn
Level029.skbn
Level030.skbn
Level031.skbn
Level032.skbn
Level033.skbn
Level034.skbn
Level035.skbn
Level036.skbn
Level037.skbn
Level038.skbn
Level039.skbn
Level040.skbn
Level041.skbn
Level042.skbn
Level043.skbn
Level044.skbn
Level045.skbn
Level046.skbn
Level047.skbn
Level048.skbn
Level049.skbn
Level050.skbn
Source
Orpius.Sokoban
bin
CellContents
Cells
Commands
Diagrams
All.cd
GameLevelCell.cd
Properties
WpfSokoban
Audio
DingDong.wav
DullClapping.mp3
Footstep.wav
Intro.wav
Movement_from_NEO_Sounds.mp3
TreasurePush.wav
bin
Commands
Controls
Images
AppIcon.ico
AppIcon.png
Properties
Settings.settings
ResourceDictionaries
WpfSokoban.csproj.user
wpfsokoban_1_1.zip
WpfSokoban
Documentation
Graphics
BackgroundControl.design
Banner.design
Cell.design
Levels
Level000.skbn
Level000.skbn.test
Level001.skbn
Level002.skbn
Level003.skbn
Level004.skbn
Level005.skbn
Level006.skbn
Level007.skbn
Level008.skbn
Level009.skbn
Level010.skbn
Level011.skbn
Level012.skbn
Level013.skbn
Level014.skbn
Level015.skbn
Level016.skbn
Level017.skbn
Level018.skbn
Level019.skbn
Level020.skbn
Level021.skbn
Level022.skbn
Level023.skbn
Level024.skbn
Level025.skbn
Level026.skbn
Level027.skbn
Level028.skbn
Level029.skbn
Level030.skbn
Level031.skbn
Level032.skbn
Level033.skbn
Level034.skbn
Level035.skbn
Level036.skbn
Level037.skbn
Level038.skbn
Level039.skbn
Level040.skbn
Level041.skbn
Level042.skbn
Level043.skbn
Level044.skbn
Level045.skbn
Level046.skbn
Level047.skbn
Level048.skbn
Level049.skbn
Level050.skbn
Source
Orpius.Sokoban
bin
Debug
Release
CellContents
Actor
Cells
Commands
Diagrams
All.cd
GameLevelCell.cd
Moves
PathFinders
Properties
WpfSokoban
Audio
DingDong.wav
DullClapping.mp3
Footstep.wav
Intro.wav
Movement_from_NEO_Sounds.mp3
TreasurePush.wav
bin
Debug
WpfSokoban.exe
WpfSokoban.vshost.exe
Release
WpfSokoban.exe
WpfSokoban.vshost.exe
WpfSokoban.vshost.exe.manifest
Commands
Controls
Images
AppIcon.ico
AppIcon.png
Properties
Settings.settings
ResourceDictionaries
/*	<File>
		<Author Name="Daniel Vaughan" Email="dbvaughan NOSPAM at NOSPAM gmail NOSPAM dot NOSPAM com"/>
		<CreationDate>2007/10/29 18:09</CreationDate>
		<LastSubmissionDate>$Date: $</LastSubmissionDate>
		<Version>$Revision: $</Version>
		<License>
Copyright © 2007, Daniel Vaughan
All rights reserved.
http://www.orpius.com

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

- Neither Daniel Vaughan, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written 
permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
		</License>
	</File>
*/

using System;

namespace Orpius.Sokoban
{
	/// <summary>
	/// Represents a goal on the level grid
	/// where <see cref="Treasure"/>s must be pushed
	/// in order to complete the <see cref="Level"/>.
	/// </summary>
	public class GoalCell : Cell
	{
		const string cellName = "Goal";

		/// <summary>
		/// Gets a value indicating whether this instance has a treasure in it.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance has a treasure; otherwise, <c>false</c>.
		/// </value>
		public bool HasTreasure
		{
			get
			{
				return CellContents is Treasure;
			}
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="GoalCell"/> class.
		/// </summary>
		/// <param name="location">The location of the goal
		/// on the level grid.</param>
		/// <param name="level">The level grid where this cell
		/// is located.</param>
		public GoalCell(Location location, Level level)
			: base(cellName, location, level)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="GoalCell"/> class.
		/// </summary>
		/// <param name="location">The location of the goal
		/// on the level grid.</param>
		/// <param name="level">The level grid where this cell
		/// is located.</param>
		/// <param name="contents">The contents of this goal cell.</param>
		public GoalCell(Location location, Level level, CellContents contents)
			: base(cellName, location, level, contents)
		{
		}

		/// <summary>
		/// Tries the set the contents of this goal.
		/// </summary>
		/// <param name="contents">The contents to set.</param>
		/// <returns><code>true</code> if the contents 
		/// was successfully placed on the goal, <code>false</code> otherwise.
		/// </returns>
		public override bool TrySetContents(CellContents contents)
		{
			if (base.TrySetContents(contents))
			{
				if (contents is Treasure)
				{
					OnCompletedGoalChanged(EventArgs.Empty);
				}
				return true;
			}
			return false;
		}

		/// <summary>
		/// Removes the <see cref="CellContents"/> contents from this goal.
		/// </summary>
		public override void RemoveContents()
		{
			/* Check for the removal of a treasure from goal square. */
			if (CellContents != null && CellContents is Treasure)
			{
				OnCompletedGoalChanged(EventArgs.Empty);
			}
			base.RemoveContents();
		}

		#region CompletedGoalChanged event
		event EventHandler completedGoalChanged;

		/// <summary>
		/// Occurs when a <see cref="Treasure"/> instance
		/// is either removed from or placed in this goal.
		/// </summary>
		public event EventHandler CompletedGoalChanged
		{
			add
			{
				completedGoalChanged += value;
			}
			remove
			{
				completedGoalChanged -= value;
			}
		}

		/// <summary>
		/// Raises the <see cref="E:CompletedGoalChanged"/> event.
		/// </summary>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		protected void OnCompletedGoalChanged(EventArgs e)
		{
			if (completedGoalChanged != null)
			{
				completedGoalChanged(this, e);
			}
		}
		#endregion
	}
}

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, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

Daniel Vaughan
President Outcoder
Switzerland Switzerland
Daniel Vaughan is a Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company dedicated to creating best-of-breed user experiences and leading-edge back-end solutions, using the Microsoft stack of technologies--in particular WPF, WinRT, Windows Phone, and also Xamarin.Forms.
 
Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.
 
Daniel is the developer behind several acclaimed Windows Phone apps including Surfy, Intellicam, and Splashbox; and is the creator of a number of popular open-source projects including Calcium SDK, and Clog.
 
Would you like Daniel to bring value to your organisation? Please contact

Daniel's Blog | MVP profile | Follow on Twitter
 
Windows Phone Experts
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 16 Jun 2008
Article Copyright 2007 by Daniel Vaughan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid