/* * GenericScoreCard.cs * Authors: August Zinsser * * Copyright Matthew Belmonte 2007 */ using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using Microsoft.Xna.Framework; namespace tAC_Engine { /// /// Games should use this class to store the score and then pass it along to the ScoreSummary class /// to display the game's final score and optionally transfer resources to another game (for example, /// a minigame passing resources along to a main game). /// public class GenericScoreCard { protected Dictionary mResourcesGathered; // Holds the raw score data /// /// Create a new score card. /// public GenericScoreCard() { mResourcesGathered = new Dictionary(); } /// /// Increases the gathered resource amount (opposite of Lose) /// /// The type of resource to add /// The amount of resource to add public void Gather(string resourceType, int amount) { if (mResourcesGathered.ContainsKey(resourceType)) { mResourcesGathered[resourceType] += amount; } else { mResourcesGathered.Add(resourceType, amount); } } /// /// Attempts to decrease the lost resource amount (opposite of Gather) /// /// True if successfully deducted resource, false otherwise public bool Lose(string resourceType, int amount) { if (mResourcesGathered.ContainsKey(resourceType) && mResourcesGathered[resourceType] >= amount) { mResourcesGathered[resourceType] -= amount; return true; } return false; } /// /// Inquire about a specific resource gathered so far /// /// Type of resource /// The amount of that resouce collected public int QueryResource(string resourceType) { if (mResourcesGathered.ContainsKey(resourceType)) { return mResourcesGathered[resourceType]; } else { return 0; } } /// /// Transfer resources from this scorecard to the game /// public void CashOut(GenericGame recipientGame) { if (recipientGame != null) { List keys = new List(); foreach (KeyValuePair kvp in mResourcesGathered) { recipientGame.IncreaseResource(kvp.Key, kvp.Value); keys.Add(kvp.Key); } foreach (string key in keys) { mResourcesGathered[key] = 0; } } } } }