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

Game Attack Combos : WPF Hybrid Smart Client for Combo Calculations

, 23 May 2009
A WPF hybrid smart client for calculating attack combos in the Prince of Persia game.
GameAttackCombos_Src.zip
ComboServices
App_Data
ComboPackagesService.svc
GameAttackCombos.snk
Properties
GameAttackCombos.mdf
GameAttackCombos_log.LDF
Packages
PrinceOfPersia2008.gcp
PrinceOfPersia2010.gcp
PackageComboFiles
Properties
ServiceData
GameAttackCombosModel.edmx
Properties
GameAttackCombos.snk
Assets
Button Icons.design
Game Attack Combos Icon.design
Game Attack Combos Icon.ico
Prince of Persia 2008
Prince of Persia 2010
PrinceOfPersia2010Background.png
PrinceOfPersia2010Icon.png
PrinceOfPersia2008Background.png
PrinceOfPersia2008Icon.png
ComboClient
Game Attack Combos Icon.ico
Properties
Resources
Service References
Supporting
Themes
ComboServices
ComboPackagesService.disco
ComboPackagesService.wsdl
ComboPackagesService1.wsdl
configuration.svcinfo
configuration91.svcinfo
Reference.svcmap
app.manifest
ComboLogic
Properties
GameAttackCombos_Standalone.zip
Packages
PrinceOfPersia2008.gcp
PrinceOfPersia2010.gcp
Resources
PresentationFramework.Aero.dll
GameAttackCombos.exe
GameAttackCombos.Logic.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using GGG.GameAttackCombos.Logic;

namespace GGG.GameAttackCombos.Client {

	/// <summary>
	/// Works with resources of the current skin of the application.
	/// </summary>
	public class CurrentSkinResource : IDisposable {

		// Last requested skin resource information.
		private string LastNameRequested;
		private Stream LastStreamRequested;


		/// <summary>
		/// Gets a Stream to a resource for the currently viewed skin of the application.
		/// </summary>
		/// <param name="resourceName">The name of the skin resource to retrieve.</param>
		/// <returns></returns>
		public Stream LoadResourceByName(string resourceName) {
			// Check if this resource was last requested.
			if (string.Compare(resourceName, LastNameRequested) != 0 || LastStreamRequested == null) {
				// Dispose of any previously requested stream to be safe.
				if (LastStreamRequested != null) {
					LastStreamRequested.Dispose();
				}

				// Store the name of the resource requested for comparison later.
				LastNameRequested = resourceName;

				// Get the main form.
				if (Application.Current != null) {
					MainWindow Main = Application.Current.MainWindow as MainWindow;
					if (Main != null) {
						// Open the current combo package being viewed.
						// TODO: Fix this! Copy the stream from the package to a memory stream.
						LastStreamRequested = File.Open(@"C:\Development\Applications\GameAttackCombos\Assets\Prince of Persia 2008\PrinceOfPersia2008Background.png", FileMode.Open, FileAccess.Read);
						//using (ComboPackage Package = Main.OpenCurrentComboPackage()) {
						//    LastStreamRequested = Package.OpenSkinResourceStream(resourceName);
						//}
					}
				}
			}

			return LastStreamRequested;
		}


		#region IDisposable Members

		/// <summary>
		/// Disposes of any remaining resources as a fail safe.
		/// </summary>
		public void Dispose() {
			// Dispose of any read stream that is still lingering.
			if (LastStreamRequested != null &&
				LastStreamRequested.CanSeek &&
				LastStreamRequested.Position >= LastStreamRequested.Length - 1) {
				// This should never be necessary because of the BitmapImage property 
				// CacheOption. It should be set to OnLoad from a skin file to dispose of the
				// stream itself. This is just a fail safe in case it is forgotten.
				LastStreamRequested.Dispose();
			}
		}

		#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 Code Project Open License (CPOL)

Share

About the Author

Matt Sollars
Web Developer
United States United States
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.
 
The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 23 May 2009
Article Copyright 2009 by Matt Sollars
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid