1 /* 2 * Copyright (C) 2007-2010 Jordi Mas i Hernàndez <jmas@softcatala.org> 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as 6 * published by the Free Software Foundation; either version 2 of the 7 * License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public 15 * License along with this program; if not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 using System; 19 20 using gbrainy.Core.Services; 21 22 namespace gbrainy.Core.Main 23 { 24 // See: GameTypesDescription.Get 25 public enum GameTypes 26 { 27 None = 0, 28 LogicPuzzle = 2, 29 Memory = 4, 30 Calculation = 8, 31 VerbalAnalogy = 16, 32 } 33 34 // Since we cannot override ToString in an enum type we use a helper class 35 public static class GameTypesDescription 36 { 37 // Type enum to string representation (locale sensitive) GetLocalized(ITranslations translations, GameTypes type)38 static public string GetLocalized (ITranslations translations, GameTypes type) 39 { 40 switch (type) 41 { 42 case GameTypes.LogicPuzzle: 43 return translations.GetString ("Logic"); 44 case GameTypes.Memory: 45 return translations.GetString ("Memory"); 46 case GameTypes.Calculation: 47 return translations.GetString ("Calculation"); 48 case GameTypes.VerbalAnalogy: 49 return translations.GetString ("Verbal"); 50 default: 51 throw new InvalidOperationException ("Unknown game type"); 52 } 53 } 54 55 // string (not localized) to enum representation FromString(string type)56 static public GameTypes FromString (string type) 57 { 58 switch (type) 59 { 60 case "Logic": 61 return GameTypes.LogicPuzzle; 62 case "Memory": 63 return GameTypes.Memory; 64 case "Calculation": 65 return GameTypes.Calculation; 66 case "Verbal": 67 return GameTypes.VerbalAnalogy; 68 default: 69 throw new InvalidOperationException ("Unknown game type"); 70 } 71 } 72 } 73 } 74