From: <kro...@us...> - 2007-07-27 08:05:11
|
Revision: 772 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=772&view=rev Author: kroko_koenig Date: 2007-07-27 01:05:05 -0700 (Fri, 27 Jul 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/My Minesweeper/Release/skin/BlueTwo/MyMinesweeper.xml trunk/plugins/My Minesweeper/Release/skin/SimpleMP/MyMinesweeper.xml trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.csproj trunk/plugins/My Minesweeper/Source/MyMinesweeper/Properties/AssemblyInfo.cs trunk/plugins/My Minesweeper/readme.txt Added Paths: ----------- trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_de.xml trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_en.xml trunk/plugins/My Minesweeper/Source/MyMinesweeper/LocalizeStrings.cs Added: trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_de.xml =================================================================== --- trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_de.xml (rev 0) +++ trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_de.xml 2007-07-27 08:05:05 UTC (rev 772) @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<Language name="German" characters="255"> + <Section name="unmapped"> + <String id="0" prefix="Mein ">Minesweeper</String> + <String id="1">Neues Spiel</String> + <String id="4">Zeit</String> + <String id="6">GAME OVER</String> + <String id="9">Spielgeräusche</String> + <String id="10">Stufe: </String> + <String id="11">leicht</String> + <String id="12">mittel</String> + <String id="13">schwer</String> + <String id="31">Was ist Minesweeper?</String> + <String id="32">Das Ziel bei Minesweeper ist es,alle +versteckten Minen so schnell wie möglich zu finden. Wenn du +auf eine versteckte Mine klickt's, explodiert diese und das +Spiel ist zu Ende. + +Spielfeld Design von Mikael Söderström + +OK prüfe aktuelle Position +1 markiere als Bombe +2 markiere als Fragezeichen +3 prüfe die Umgebung +0 neues Spiel + +Viel Glück +Mark König 2007 (kroko)</String> + + </Section> +</Language> \ No newline at end of file Added: trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_en.xml =================================================================== --- trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_en.xml (rev 0) +++ trunk/plugins/My Minesweeper/Release/language/MyMinesweeper/strings_en.xml 2007-07-27 08:05:05 UTC (rev 772) @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<Language name="English" characters="255"> + <Section name="unmapped"> + <String id="0" prefix="My ">Minesweeper</String> + <String id="1">New Game</String> + <String id="4">Time</String> + <String id="6">GAME OVER</String> + <String id="9">Sounds</String> + <String id="10">Level: </String> + <String id="11">easy</String> + <String id="12">medium</String> + <String id="13">difficult</String> + <String id="31">What's Minesweeper</String> + <String id="32">Your goal in Minesweeper is to discover all +hidden mines as soon as possible. If you click +on a hidden mine it will explode and the game +ends. + +Game board design by Mikael Söderström + +OK check actual position +1 mark as bomb +2 mark as not sure +3 check surrounding +0 new game + +Good luck +Mark Koenig 2007 (kroko)</String> + </Section> +</Language> \ No newline at end of file Modified: trunk/plugins/My Minesweeper/Release/skin/BlueTwo/MyMinesweeper.xml =================================================================== --- trunk/plugins/My Minesweeper/Release/skin/BlueTwo/MyMinesweeper.xml 2007-07-26 16:23:52 UTC (rev 771) +++ trunk/plugins/My Minesweeper/Release/skin/BlueTwo/MyMinesweeper.xml 2007-07-27 08:05:05 UTC (rev 772) @@ -13,7 +13,7 @@ <posY>20</posY> <align>left</align> <font>font48</font> - <label>Minesweeper</label> + <label>#header_label</label> <textcolor>20ffffff</textcolor> <id>1</id> <animation effect="fade" time="150">WindowOpen</animation> @@ -35,7 +35,7 @@ <id>11</id> <posX>250</posX> <posY>70</posY> - <label>Minesweeper</label> + <label>#header_label</label> <font>font16</font> <align>right</align> <textcolor>ffffffff</textcolor> @@ -48,10 +48,10 @@ <id>2</id> <posX>60</posX> <posY>97</posY> - <label>Start</label> + <label>New game</label> <onleft>2</onleft> <onright>21</onright> - <onup>8</onup> + <onup>10</onup> <ondown>4</ondown> <animation effect="fade" time="150">WindowOpen</animation> <animation effect="fade" time="150">WindowClose</animation> @@ -62,20 +62,32 @@ <id>4</id> <posX>60</posX> <posY>131</posY> - <label>Level: Amateur</label> + <label>Level: easy</label> <onleft>4</onleft> <onright>21</onright> <onup>2</onup> - <ondown>8</ondown> - <animation effect="fade" time="150">WindowOpen</animation> - <animation effect="fade" time="150">WindowClose</animation> + <ondown>5</ondown> + <animation effect="fade" time="150">WindowOpen</animation> + <animation effect="fade" time="150">WindowClose</animation> </control> + <control> + <description>Sounds</description> + <type>togglebutton</type> + <id>5</id> + <posX>60</posX> + <posY>165</posY> + <label>Sounds</label> + <onleft>5</onleft> + <onright>21</onright> + <onup>4</onup> + <ondown>10</ondown> + </control> <control> <description>Smily</description> <type>image</type> - <id>1</id> + <id>6</id> <posX>60</posX> - <posY>185</posY> + <posY>220</posY> <width>60</width> <height>60</height> <texture>#minesweeper_smiley</texture> @@ -83,9 +95,9 @@ <control> <description>text label</description> <type>label</type> - <id>5</id> + <id>7</id> <posX>70</posX> - <posY>264</posY> + <posY>300</posY> <label>#minesweeper_bombs</label> <font>font12</font> <align>Left</align> @@ -96,9 +108,9 @@ <control> <description>text label</description> <type>label</type> - <id>6</id> + <id>8</id> <posX>70</posX> - <posY>298</posY> + <posY>330</posY> <label>#minesweeper_seconds</label> <font>font12</font> <align>Left</align> @@ -109,9 +121,9 @@ <control> <description>text label</description> <type>label</type> - <id>7</id> + <id>9</id> <posX>70</posX> - <posY>332</posY> + <posY>350</posY> <label>#minesweeper_record</label> <font>font12</font> <align>Left</align> @@ -122,20 +134,20 @@ <control> <description>Whatsthis</description> <type>button</type> - <id>8</id> + <id>10</id> <posX>60</posX> - <posY>361</posY> + <posY>400</posY> <label>What's this?</label> <onleft>8</onleft> <onright>21</onright> - <onup>4</onup> + <onup>5</onup> <ondown>2</ondown> <animation effect="fade" time="150">WindowOpen</animation> <animation effect="fade" time="150">WindowClose</animation> </control> <control> - <description>hidden hex</description> + <description>hidden corner</description> <type>image</type> <id>1200</id> <posX>280</posX> Modified: trunk/plugins/My Minesweeper/Release/skin/SimpleMP/MyMinesweeper.xml =================================================================== --- trunk/plugins/My Minesweeper/Release/skin/SimpleMP/MyMinesweeper.xml 2007-07-26 16:23:52 UTC (rev 771) +++ trunk/plugins/My Minesweeper/Release/skin/SimpleMP/MyMinesweeper.xml 2007-07-27 08:05:05 UTC (rev 772) @@ -13,7 +13,7 @@ <posY>20</posY> <align>left</align> <font>font48</font> - <label>Minesweeper</label> + <label>#header_label</label> <textcolor>20ffffff</textcolor> <id>1</id> <animation effect="fade" time="150">WindowOpen</animation> @@ -35,7 +35,7 @@ <id>11</id> <posX>250</posX> <posY>70</posY> - <label>Minesweeper</label> + <label>#header_label</label> <font>font16</font> <align>right</align> <textcolor>ffffffff</textcolor> @@ -48,10 +48,10 @@ <id>2</id> <posX>60</posX> <posY>97</posY> - <label>Start</label> + <label>New game</label> <onleft>2</onleft> <onright>21</onright> - <onup>8</onup> + <onup>10</onup> <ondown>4</ondown> <animation effect="fade" time="150">WindowOpen</animation> <animation effect="fade" time="150">WindowClose</animation> @@ -62,20 +62,32 @@ <id>4</id> <posX>60</posX> <posY>131</posY> - <label>Level: Amateur</label> + <label>Level: easy</label> <onleft>4</onleft> <onright>21</onright> <onup>2</onup> - <ondown>8</ondown> - <animation effect="fade" time="150">WindowOpen</animation> - <animation effect="fade" time="150">WindowClose</animation> + <ondown>5</ondown> + <animation effect="fade" time="150">WindowOpen</animation> + <animation effect="fade" time="150">WindowClose</animation> </control> + <control> + <description>Sounds</description> + <type>togglebutton</type> + <id>5</id> + <posX>60</posX> + <posY>165</posY> + <label>Sounds</label> + <onleft>5</onleft> + <onright>21</onright> + <onup>4</onup> + <ondown>10</ondown> + </control> <control> <description>Smily</description> <type>image</type> - <id>1</id> + <id>6</id> <posX>60</posX> - <posY>185</posY> + <posY>220</posY> <width>60</width> <height>60</height> <texture>#minesweeper_smiley</texture> @@ -83,9 +95,9 @@ <control> <description>text label</description> <type>label</type> - <id>5</id> + <id>7</id> <posX>70</posX> - <posY>264</posY> + <posY>300</posY> <label>#minesweeper_bombs</label> <font>font12</font> <align>Left</align> @@ -96,9 +108,9 @@ <control> <description>text label</description> <type>label</type> - <id>6</id> + <id>8</id> <posX>70</posX> - <posY>298</posY> + <posY>330</posY> <label>#minesweeper_seconds</label> <font>font12</font> <align>Left</align> @@ -109,9 +121,9 @@ <control> <description>text label</description> <type>label</type> - <id>7</id> + <id>9</id> <posX>70</posX> - <posY>332</posY> + <posY>350</posY> <label>#minesweeper_record</label> <font>font12</font> <align>Left</align> @@ -122,20 +134,20 @@ <control> <description>Whatsthis</description> <type>button</type> - <id>8</id> + <id>10</id> <posX>60</posX> - <posY>361</posY> + <posY>400</posY> <label>What's this?</label> <onleft>8</onleft> <onright>21</onright> - <onup>4</onup> + <onup>5</onup> <ondown>2</ondown> <animation effect="fade" time="150">WindowOpen</animation> <animation effect="fade" time="150">WindowClose</animation> </control> <control> - <description>hidden hex</description> + <description>hidden corner</description> <type>image</type> <id>1200</id> <posX>280</posX> Added: trunk/plugins/My Minesweeper/Source/MyMinesweeper/LocalizeStrings.cs =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/LocalizeStrings.cs (rev 0) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/LocalizeStrings.cs 2007-07-27 08:05:05 UTC (rev 772) @@ -0,0 +1,260 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.IO; +using System.Globalization; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using MediaPortal.Util; +using MediaPortal.GUI.Library; +using MediaPortal.Configuration; +using MediaPortal.Localisation; + +namespace MediaPortal.GUI.MyMinesweeper +{ + /// <summary> + /// This class will hold all text used in the application + /// The text is loaded for the current language from + /// the file language/[language]/strings.xml + /// </summary> + public class GUILocalizeStrings + { + #region Variables + static LocalisationProvider _stringProvider; + static Dictionary<string, string> _cultures; + static string[] _languages; + #endregion + + #region Constructors/Destructors + // singleton. Dont allow any instance of this class + private GUILocalizeStrings() + { + } + + static public void Dispose() + { + if (_stringProvider != null) + _stringProvider.Dispose(); + } + #endregion + + #region Public Methods + /// <summary> + /// Public method to load the text from a strings/xml file into memory + /// </summary> + /// <param name="strFileName">Contains the filename+path for the string.xml file</param> + /// <returns> + /// true when text is loaded + /// false when it was unable to load the text + /// </returns> + //[Obsolete("This method has changed", true)] + static public bool Load(string language) + { + bool isPrefixEnabled = true; + + using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + isPrefixEnabled = reader.GetValueAsBool("general", "myprefix", true); + + string directory = Config.GetSubFolder(Config.Dir.Language, "MyMinesweeper"); + string cultureName = null; + if (language != null) + cultureName = GetCultureName(language); + + Log.Info(" Loading localised Strings - Path: {0} Culture: {1} Language: {2} Prefix: {3}", directory, cultureName, language, isPrefixEnabled); + + _stringProvider = new LocalisationProvider(directory, cultureName, isPrefixEnabled); + + GUIGraphicsContext.CharsInCharacterSet = _stringProvider.Characters; + + return true; + } + + static public string CurrentLanguage() + { + if (_stringProvider == null) + Load(null); + + return _stringProvider.CurrentLanguage.EnglishName; + } + + static public void ChangeLanguage(string language) + { + if (_stringProvider == null) + Load(language); + else + _stringProvider.ChangeLanguage(GetCultureName(language)); + } + + /// <summary> + /// Get the translation for a given id and format the sting with + /// the given parameters + /// </summary> + /// <param name="dwCode">id of text</param> + /// <param name="parameters">parameters used in the formating</param> + /// <returns> + /// string containing the translated text + /// </returns> + static public string Get(int dwCode, object[] parameters) + { + if (_stringProvider == null) + Load(null); + + string translation = _stringProvider.GetString("unmapped", dwCode); + // if parameters or the translation is null, return the translation. + if ((translation == null) || (parameters == null)) + { + return translation; + } + // return the formatted string. If formatting fails, log the error + // and return the unformatted string. + try + { + return String.Format(translation, parameters); + } + catch (System.FormatException e) + { + Log.Error("Error formatting translation with id {0}", dwCode); + Log.Error("Unformatted translation: {0}", translation); + Log.Error(e); + return translation; + } + } + + /// <summary> + /// Get the translation for a given id + /// </summary> + /// <param name="dwCode">id of text</param> + /// <returns> + /// string containing the translated text + /// </returns> + static public string Get(int dwCode) + { + if (_stringProvider == null) + Load(null); + + string translation = _stringProvider.GetString("unmapped", dwCode); + + if (translation == null) + { + Log.Error("No translation found for id {0}", dwCode); + return String.Empty; + } + + return translation; + } + + static public void LocalizeLabel(ref string strLabel) + { + if (_stringProvider == null) + Load(null); + + if (strLabel == null) strLabel = String.Empty; + if (strLabel == "-") strLabel = ""; + if (strLabel == "") return; + // This can't be a valid string code if the first character isn't a number. + // This check will save us from catching unnecessary exceptions. + if (!char.IsNumber(strLabel, 0)) + return; + + int dwLabelID; + + try + { + dwLabelID = System.Int32.Parse(strLabel); + } + catch (FormatException e) + { + Log.Error(e); + strLabel = String.Empty; + return; + } + + strLabel = _stringProvider.GetString("unmapped", dwLabelID); + if (strLabel == null) + { + Log.Error("No translation found for id {0}", dwLabelID); + strLabel = String.Empty; + } + } + + public static string LocalSupported() + { + if (_stringProvider == null) + Load(null); + + CultureInfo culture = _stringProvider.GetBestLanguage(); + + return culture.EnglishName; + } + + public static string[] SupportedLanguages() + { + if (_languages == null) + { + if (_stringProvider == null) + Load(null); + + CultureInfo[] cultures = _stringProvider.AvailableLanguages(); + + SortedList sortedLanguages = new SortedList(); + foreach (CultureInfo culture in cultures) + sortedLanguages.Add(culture.EnglishName, culture.EnglishName); + + _languages = new string[sortedLanguages.Count]; + + for (int i = 0; i < sortedLanguages.Count; i++) + { + _languages[i] = (string)sortedLanguages.GetByIndex(i); + } + } + + return _languages; + } + + static public string GetCultureName(string language) + { + if (_cultures == null) + { + _cultures = new Dictionary<string, string>(); + + CultureInfo[] cultureList = CultureInfo.GetCultures(CultureTypes.AllCultures); + + for (int i = 0; i < cultureList.Length; i++) + { + _cultures.Add(cultureList[i].EnglishName, cultureList[i].Name); + } + } + + if (_cultures.ContainsKey(language)) + return _cultures[language]; + + return null; + } + #endregion + } +} \ No newline at end of file Modified: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs 2007-07-26 16:23:52 UTC (rev 771) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs 2007-07-27 08:05:05 UTC (rev 772) @@ -34,28 +34,43 @@ using MediaPortal.Dialogs; using MediaPortal.Util; using MediaPortal.Configuration; +using MediaPortal.Localisation; namespace MediaPortal.GUI.MyMinesweeper { [PluginIcons("MyMinesweeper.minesweeper.png", "MyMinesweeper.minesweeperDisabled.png")] - public class MyMinesweeper : GUIWindow, ISetupForm + public class MyMinesweeperGUI : GUIWindow, ISetupForm { + #region enums + + private enum Level + { + Easy = 0, + Medium = 1, + Hard = 2 + } + + #endregion + #region SkinControl [SkinControlAttribute(2)] - protected GUIButtonControl BtnStart = null; + protected GUIButtonControl btnStart = null; [SkinControlAttribute(4)] - protected GUIButtonControl BtnLevel = null; - [SkinControlAttribute(8)] - protected GUIButtonControl BtnWhatsThis = null; + protected GUIButtonControl btnLevel = null; + [SkinControlAttribute(5)] + protected GUIToggleButtonControl btnSound = null; + [SkinControlAttribute(10)] + protected GUIButtonControl btnWhatsThis = null; #endregion #region Private variables - string Level = "Am"; // Choosen level + Level _currentLevel = Level.Easy; bool GameOver = false; // not game over bool GameON = false; // Game is on + bool _soundOn = true; int[,] board = new int[30, 30]; int[,] bombs = new int[30, 30]; @@ -153,19 +168,7 @@ public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) { - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - if (xmlreader.GetValue("general", "myprefix")=="no") - { - strButtonText = "Minesweeper"; - } - else - { - strButtonText = "My Minesweeper"; - } - - } - //strButtonText = PluginName(); + strButtonText = MyMinesweeper.GUILocalizeStrings.Get(0); ; strButtonImage = String.Empty; strButtonImageFocus = String.Empty; strPictureImage = @"hover_my_minesweeper.png"; @@ -174,6 +177,8 @@ #endregion + #region Overrides + public override int GetID { get @@ -188,59 +193,23 @@ public override bool Init() { + MyMinesweeper.GUILocalizeStrings.Load(GUI.Library.GUILocalizeStrings.CurrentLanguage()); + if (ah == null) ah = new OnActionHandler(OnAction2); + bool result = Load(GUIGraphicsContext.Skin + @"\MyMinesweeper.xml"); return result; } - #region Actions - - public override void OnAction(Action action) - { - base.OnAction(action); - } - - public void OnAction2(Action action) - { - switch (action.wID) - { - case Action.ActionType.ACTION_KEY_PRESSED: - switch (action.m_key.KeyChar) - { - case '1': - SetBomb(); - break; - case '2': - SetQuest(); - break; - case '3': - Check9(); - break; - case '0': - NewGame(); - break; - } - break; - } - } - - #endregion - public override bool OnMessage(GUIMessage message) { if (message.Message == GUI.Library.GUIMessage.MessageType.GUI_MSG_SETFOCUS) { - ID = message.TargetControlId; + ID = message.TargetControlId; } return base.OnMessage(message); } - public void Dispose() - { - _Game.Stop(); - _Game.Tick -= new EventHandler(_Game_Tick); - } - protected override void OnPageLoad() { @@ -253,8 +222,7 @@ LoadSettings(); - NewGame(); - ShowLevel(); + OnBtnStart(); GUIGraphicsContext.OnNewAction -= ah; GUIGraphicsContext.OnNewAction += ah; @@ -264,6 +232,13 @@ GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\smile.png"); + // set localized labels for static controls + GUIPropertyManager.SetProperty("#header_label", MyMinesweeper.GUILocalizeStrings.Get(0)); // MyMinesweeper + GUIControl.SetControlLabel(GetID, btnStart.GetID, MyMinesweeper.GUILocalizeStrings.Get(1)); // New Game + GUIControl.SetControlLabel(GetID, btnSound.GetID, MyMinesweeper.GUILocalizeStrings.Get(9)); // Sounds + GUIControl.SetControlLabel(GetID, btnWhatsThis.GetID, MyMinesweeper.GUILocalizeStrings.Get(31)); // What is MyMinesweeper? + + UpdateButtonStates(); } protected override void OnPageDestroy(int new_windowId) @@ -295,24 +270,29 @@ pt.X = x; pt.Y = y; + OnRenderSound("tick.wav"); + SetPlace(pt); } } - if (control == BtnWhatsThis) + if (control == btnWhatsThis) { OnBtnWhatsThis(); } - if (control == BtnLevel) + if (control == btnLevel) { OnBtnLevel(); } - if (control == BtnStart) + if (control == btnStart) { - NewGame(); + OnBtnStart(); } - + if (control == btnSound ) + { + OnBtnSound(); + } } @@ -321,76 +301,226 @@ base.OnShowContextMenu(); } - private void CreateButton(int ID, int posx, int posy, int height, int width, string focusimg, string nofocusimg) + #endregion + + #region Implementation + + private void OnBtnStart() { - GUIButtonControl button = new GUIButtonControl(GetID, ID, posx, posy, width, height, focusimg, nofocusimg); - button.AllocResources(); - GUIControl btnControl = (GUIControl)button; - Add(ref btnControl); + GameOver = false; + GameON = false; + time = 0; + ID = 0; + + GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\smile.png"); + + if (_currentLevel == Level.Easy) + { + bx = 10; + by = 10; + bcnt = 10; + time_rec = t_am; + time_name = n_am; + } + if (_currentLevel == Level.Medium) + { + bx = 15; + by = 15; + bcnt = 40; + time_rec = t_nor; + time_name = n_nor; + } + if (_currentLevel == Level.Hard) + { + bx = 20; + by = 20; + bcnt = 100; + time_rec = t_pro; + time_name = n_pro; + } + + GUIPropertyManager.SetProperty("#minesweeper_record", "Record: " + time_rec + "s - " + time_name); + + // remove controls from form + try + { + for (int i = 500; i < 1180; i++) + { + Remove(i); + } + } + catch + { + + } + + for (int i = 0; i < 30; i++) + { + for (int j = 0; j < 30; j++) + { // 20 = not checked + board[i, j] = 20; + // no bombs + bombs[i, j] = 0; + } + } + + Random rnd = new Random(); + + for (int i = 0; i < bcnt; i++) + { + int x = rnd.Next(0, bx); + int y = rnd.Next(0, by); + if (bombs[x, y] == 1) + { // already bomb + i = i - 1; + } + else + { + Point px = new Point(); + px.X = x; + px.Y = y; + if (GetValue(px) < 4) + { + bombs[x, y] = 1; + } + else + { + i = i - 1; + } + } + + } + + Init_board(); } - void _Game_Tick(object sender, EventArgs e) - { - if ((!GameOver) && (time<999) && (GameON == true)) + private void OnBtnLevel() + { //Choose level for the game { - time++; + switch (_currentLevel) + { + case Level.Easy: + _currentLevel = Level.Medium; + break; + case Level.Medium: + _currentLevel = Level.Hard; + break; + case Level.Hard: + _currentLevel = Level.Easy; + break; + } + + OnBtnStart(); + + UpdateButtonStates(); } - GUIPropertyManager.SetProperty("#minesweeper_seconds", "Time: " + time.ToString()); - GUIPropertyManager.SetProperty("#minesweeper_bombs", "Bombs: " + bcnt.ToString()); } + private void OnBtnSound() + { + _soundOn = btnSound.Selected; + UpdateButtonStates(); + } + private void OnBtnWhatsThis() { GUIDialogText dlg = (GUIDialogText)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TEXT); - dlg.SetHeading("What's Minesweeper"); - dlg.SetText("Your goal in Minesweeper is to discover all\n" + - "hidden mines as soon as possible. If you click\n" + - "on a hidden mine it will explode and the game\n" + - "ends.\n" + - "Game board design by Mikael S\xF6derstr\xF6m\n\n" + - "OK check actual position\n" + - "1 mark as bomb\n" + - "2 mark as not sure\n" + - "3 check surrounding\n" + - "0 new game\n\n" + - "Good luck\nMark Koenig (kroko)"); + dlg.SetHeading(MyMinesweeper.GUILocalizeStrings.Get(31)); // help dialog heading + dlg.SetText(MyMinesweeper.GUILocalizeStrings.Get(32)); // help dialog text dlg.DoModal(GetID); } - private void OnBtnLevel() - { //Choose level for the game + private void OnRenderSound(string strFilePath) + { + if (_soundOn) { - if (Level == "Nor") - { - Level = "Pro"; - } - else if (Level == "Pro") - { - Level = "Am"; - } - else - { - Level = "Nor"; - } - NewGame(); - ShowLevel(); + MediaPortal.Util.Utils.PlaySound(strFilePath, false, true); } } - private void ShowLevel() + private void UpdateButtonStates() { - if (Level == "Pro") + // enable/disable buttons + btnSound.Selected = _soundOn; + + // refresh label for btnLevel + string strLine = MyMinesweeper.GUILocalizeStrings.Get(10); // Level: + switch (_currentLevel) { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Professional"); + case Level.Easy: + strLine += MyMinesweeper.GUILocalizeStrings.Get(11); // easy + break; + case Level.Medium: + strLine += MyMinesweeper.GUILocalizeStrings.Get(12); // medium + break; + case Level.Hard: + strLine += MyMinesweeper.GUILocalizeStrings.Get(13); // difficult + break; } - if (Level == "Am") + GUIControl.SetControlLabel(GetID, btnLevel.GetID, strLine); + + // refresh label for btnMode + strLine = MyMinesweeper.GUILocalizeStrings.Get(20); // Mode: Play vs + + } + + #endregion + + public void Dispose() + { + _Game.Stop(); + _Game.Tick -= new EventHandler(_Game_Tick); + } + + #region Actions + + public override void OnAction(Action action) + { + base.OnAction(action); + } + + public void OnAction2(Action action) + { + switch (action.wID) { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Amateur"); + case Action.ActionType.ACTION_KEY_PRESSED: + switch (action.m_key.KeyChar) + { + case '1': + SetBomb(); + break; + case '2': + SetQuest(); + break; + case '3': + Check9(); + break; + case '0': + OnBtnStart(); + break; + } + break; } - if (Level == "Nor") + } + + #endregion + + private void CreateButton(int ID, int posx, int posy, int height, int width, string focusimg, string nofocusimg) + { + GUIButtonControl button = new GUIButtonControl(GetID, ID, posx, posy, width, height, focusimg, nofocusimg); + button.AllocResources(); + GUIControl btnControl = (GUIControl)button; + Add(ref btnControl); + } + + void _Game_Tick(object sender, EventArgs e) + { + if ((!GameOver) && (time<999) && (GameON == true)) { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Normal"); + time++; } + GUIPropertyManager.SetProperty("#minesweeper_seconds", "Time: " + time.ToString()); + GUIPropertyManager.SetProperty("#minesweeper_bombs", "Bombs: " + bcnt.ToString()); } private void Init_board() @@ -518,7 +648,7 @@ { GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\sad.png"); GameOver = true; - MediaPortal.Util.Utils.PlaySound("bomb.wav", false, true); + OnRenderSound ("bomb.wav"); EndGame(); board[pos.X, pos.Y] = 12; SetPoint(pos); @@ -615,97 +745,8 @@ GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\unchecksel.png"); GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\uncheckunsel.png"); } - } + } - private void NewGame() - { - GameOver = false; - GameON = false; - time = 0; - ID = 0; - - GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\smile.png"); - - if (Level == "Am") - { - bx = 10; - by = 10; - bcnt = 10; - time_rec = t_am; - time_name = n_am; - } - if (Level == "Nor") - { - bx = 15; - by = 15; - bcnt = 40; - time_rec = t_nor; - time_name = n_nor; - } - if (Level == "Pro") - { - bx = 20; - by = 20; - bcnt = 100; - time_rec = t_pro; - time_name = n_pro; - } - - GUIPropertyManager.SetProperty("#minesweeper_record", "Record: " + time_rec + "s - " + time_name); - - // remove controls from form - try - { - for (int i = 500; i < 1180; i++) - { - Remove(i); - } - } - catch - { - - } - - for (int i = 0; i < 30; i++) - { - for (int j = 0; j < 30; j++) - { // 20 = not checked - board[i, j] = 20; - // no bombs - bombs[i, j] = 0; - } - } - - Random rnd = new Random(); - - for (int i = 0; i < bcnt ; i++) - { - int x = rnd.Next(0,bx); - int y = rnd.Next(0,by); - if (bombs[x, y] == 1) - { // already bomb - i = i - 1; - } - else - { - Point px = new Point(); - px.X=x; - px.Y=y; - if (GetValue(px) < 4) - { - bombs[x, y] = 1; - } - else - { - i = i - 1; - } - } - - } - - Init_board(); - } - private int GetValue(Point pos) { int val=0; @@ -994,6 +1035,7 @@ { if (time < int.Parse (time_rec)) { + OnRenderSound("highscore.wav"); time_rec = time.ToString(); VirtualKeyboard menu = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); @@ -1015,17 +1057,17 @@ private void SetScore() { - if (Level == "Pro") + if (_currentLevel == Level.Hard) { t_pro = time_rec; n_pro = time_name; } - if (Level == "Am") + if (_currentLevel == Level.Easy ) { t_am = time_rec; n_am = time_name; } - if (Level == "Nor") + if (_currentLevel == Level.Medium) { t_nor = time_rec; n_nor = time_name; Modified: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.csproj =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.csproj 2007-07-26 16:23:52 UTC (rev 771) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.csproj 2007-07-27 08:05:05 UTC (rev 772) @@ -14,7 +14,7 @@ <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> + <OutputPath>..\..\..\..\..\..\Mediaportal\xbmc\bin\Debug\plugins\Windows\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> @@ -30,12 +30,12 @@ <ItemGroup> <Reference Include="Core, Version=1.0.2681.38747, Culture=neutral, processorArchitecture=x86"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\..\MediaPortal\xbmc\bin\Debug\Core.dll</HintPath> + <HintPath>..\..\..\..\..\..\Mediaportal\xbmc\bin\Debug\Core.dll</HintPath> <Private>False</Private> </Reference> <Reference Include="Dialogs, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\..\MediaPortal\xbmc\bin\Debug\plugins\windows\Dialogs.dll</HintPath> + <HintPath>..\..\..\..\..\..\Mediaportal\xbmc\bin\Debug\plugins\Windows\Dialogs.dll</HintPath> <Private>False</Private> </Reference> <Reference Include="System" /> @@ -45,11 +45,12 @@ <Reference Include="System.Xml" /> <Reference Include="Utils, Version=1.0.2681.38745, Culture=neutral, processorArchitecture=x86"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\..\MediaPortal\xbmc\bin\Debug\Utils.dll</HintPath> + <HintPath>..\..\..\..\..\..\Mediaportal\xbmc\bin\Debug\Utils.dll</HintPath> <Private>False</Private> </Reference> </ItemGroup> <ItemGroup> + <Compile Include="LocalizeStrings.cs" /> <Compile Include="MyMinesweeper.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> @@ -66,7 +67,7 @@ </Target> --> <PropertyGroup> - <PostBuildEvent>cd "$(SolutionDir)" -call postbuild.bat "$(TargetPath)" "$(TargetFileName)"</PostBuildEvent> + <PostBuildEvent> + </PostBuildEvent> </PropertyGroup> </Project> \ No newline at end of file Modified: trunk/plugins/My Minesweeper/Source/MyMinesweeper/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/Properties/AssemblyInfo.cs 2007-07-26 16:23:52 UTC (rev 771) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/Properties/AssemblyInfo.cs 2007-07-27 08:05:05 UTC (rev 772) @@ -31,5 +31,5 @@ // // Sie können alle Werte angeben oder die standardmäßigen Revisions- und Buildnummern // übernehmen, indem Sie "*" eingeben: -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0")] +[assembly: AssemblyVersion("0.2.0.0")] +[assembly: AssemblyFileVersion("0.2.0")] Modified: trunk/plugins/My Minesweeper/readme.txt =================================================================== --- trunk/plugins/My Minesweeper/readme.txt 2007-07-26 16:23:52 UTC (rev 771) +++ trunk/plugins/My Minesweeper/readme.txt 2007-07-27 08:05:05 UTC (rev 772) @@ -1,7 +1,16 @@ Minesweeper ------------------- +Version 0.2 +----------- + - MediaPortal 0.2.3.0 ready + - added option to enable/disable sounds, while playing + - added sound for click and highscore + - plugin should be full localisable now + - minor improvements + Version 0.1 +----------- -Initial release Copy the plugin and skin files into your favorite skin folder. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |