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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Reflection;
using System;
using System.IO;

namespace GG.GameAttackCombos.Client {

	/// <summary>
	/// Common information and actions used by the client application.
	/// </summary>
	public static class Common {

		/// <summary>
		/// Gets the directory containing the application.
		/// </summary>
		public static string ApplicationDirectory {
			get { return AppDomain.CurrentDomain.BaseDirectory; }
		}

#if Standalone
		private static string _packageDirectory;
		/// <summary>
		/// Gets the directory where packages are stored.
		/// </summary>
		public static string PackageDirectory {
			get {
				if (string.IsNullOrEmpty(_packageDirectory)) {
					_packageDirectory = Path.Combine(ApplicationDirectory, "Packages");
				}
				return _packageDirectory;
			}
		}
#endif


		/// <summary>
		/// Finds a child with the requested name and type within the specified object's template.
		/// </summary>
		/// <typeparam name="T">The type of the child to find.</typeparam>
		/// <param name="name">The name of the child to find.</param>
		/// <param name="obj">The object to act as the parent reference when finding the child.</param>
		/// <returns>A child of obj with type T and the specified name, or null if none is found.</returns>
		public static T FindTemplateChild<T>(string name, DependencyObject obj) where T : DependencyObject {
			// Find the content presenter for the specified object.
			ContentPresenter Presenter = Common.FindVisualChild<ContentPresenter>(obj);
			if (Presenter != null) {
				// Find the child element within the presenter's ContentTemplate.
				return Presenter.ContentTemplate.FindName(name, Presenter) as T;
			} else {
				return null;
			}
		}
		
		/// <summary>
		/// Finds the first visual child of the specified object of the indicated type.
		/// </summary>
		/// <typeparam name="T">The type of the child to find.</typeparam>
		/// <param name="obj">The object to act as the parent reference when finding the child.</param>
		/// <returns>The first child of obj with type T, or null if none is found.</returns>
		public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject {
			// Traverse the visual children of the specified object.
			for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) {
				// Test each child for the type we are looking for.
				DependencyObject Child = VisualTreeHelper.GetChild(obj, i);
				if (Child != null && Child is T)
					return (T)Child;
				else {
					// Look in the child's children for a match.
					T ChildOfChild = FindVisualChild<T>(Child);
					if (ChildOfChild != null)
						return ChildOfChild;
				}
			}
			return null;
		}

	}

}

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
Web02 | 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