From: <che...@us...> - 2007-05-27 11:03:53
|
Revision: 477 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=477&view=rev Author: chef_koch Date: 2007-05-27 04:03:51 -0700 (Sun, 27 May 2007) Log Message: ----------- Added Paths: ----------- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.csproj trunk/plugins/My Minesweeper/Source/MyMinesweeper/Properties/ trunk/plugins/My Minesweeper/Source/MyMinesweeper/minesweeper.png trunk/plugins/My Minesweeper/Source/MyMinesweeper/minesweeperDisabled.png trunk/plugins/My Minesweeper/Source/MyMinesweeper.sln Removed Paths: ------------- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.cs trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.csproj trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/Properties/ trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/minesweeper.png trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/minesweeperDisabled.png trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.sln Deleted: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.cs =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.cs 2007-05-27 10:46:40 UTC (rev 476) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.cs 2007-05-27 11:03:51 UTC (rev 477) @@ -1,1065 +0,0 @@ -#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.Collections.Generic; -using System.Text; -using System.Windows.Forms; -using System.Drawing; - -using MediaPortal.GUI.Library; -using MediaPortal.Dialogs; -using MediaPortal.Util; -using MediaPortal.Configuration; - -namespace MediaPortal.GUI.MyMinesweeper -{ - [PluginIcons("MyMinesweeper.minesweeper.png", "MyMinesweeper.minesweeperDisabled.png")] - public class MyMinesweeper : GUIWindow, ISetupForm - { - #region SkinControl - - [SkinControlAttribute(2)] - protected GUIButtonControl BtnStart = null; - [SkinControlAttribute(4)] - protected GUIButtonControl BtnLevel = null; - [SkinControlAttribute(8)] - protected GUIButtonControl BtnWhatsThis = null; - - #endregion - - #region Private variables - - string Level = "Am"; // Choosen level - bool GameOver = false; // not game over - bool GameON = false; // Game is on - - int[,] board = new int[30, 30]; - int[,] bombs = new int[30, 30]; - bool initBoard = false; - - int bx = 10; - int by = 10; - int bcnt = 10; - - int time = 0; - string time_rec = "999"; - string time_name = "unknown"; - - string t_pro; - string t_nor; - string t_am; - - string n_pro; - string n_nor; - string n_am; - - int ID = 0; - - private static OnActionHandler ah; - - // game ticker for the timer - private System.Windows.Forms.Timer _Game = new System.Windows.Forms.Timer(); - - int[] posX = { -1, 0, 1, -1, 1, -1 , 0 , 1 }; - int[] posY = { -1, -1, -1, 0, 0, 1, 1, 1 }; - - #endregion - - #region ISetupForm Members - - // Returns the name of the plugin which is shown in the plugin menu - public string PluginName() - { - return "My Minesweeper"; - } - - // Returns the description of the plugin is shown in the plugin menu - public string Description() - { - return "My Minesweeper"; - } - - // Returns the author of the plugin which is shown in the plugin menu - public string Author() - { - return "Mark Koenig (kroko)"; - } - - // show the setup dialog - public void ShowPlugin() - { - MessageBox.Show("Nothing to configure, this is just an example"); - } - - // Indicates whether plugin can be enabled/disabled - public bool CanEnable() - { - return true; - } - - // get ID of windowplugin belonging to this setup - public int GetWindowId() - { - return 32327501; - } - - // Indicates if plugin is enabled by default; - public bool DefaultEnabled() - { - return true; - } - - // indicates if a plugin has its own setup screen - public bool HasSetup() - { - return false; - } - - /// <summary> - /// If the plugin should have its own button on the main menu of MediaPortal then it - /// should return true to this method, otherwise if it should not be on home - /// it should return false - /// </summary> - /// <param name="strButtonText">text the button should have</param> - /// <param name="strButtonImage">image for the button, or empty for default</param> - /// <param name="strButtonImageFocus">image for the button, or empty for default</param> - /// <param name="strPictureImage">subpicture for the button or empty for none</param> - /// <returns>true : plugin needs its own button on home - /// false : plugin does not need its own button on home</returns> - - 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(); - strButtonImage = String.Empty; - strButtonImageFocus = String.Empty; - strPictureImage = @"hover_my_minesweeper.png"; - return true; - } - - #endregion - - public override int GetID - { - get - { - return 32327501; - } - set - { - base.GetID = value; - } - } - - public override bool Init() - { - 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; - } - return base.OnMessage(message); - } - - public void Dispose() - { - _Game.Stop(); - _Game.Tick -= new EventHandler(_Game_Tick); - } - - protected override void OnPageLoad() - { - - // start game ticker - _Game.Interval = 1000; - _Game.Tick += new EventHandler(_Game_Tick); - _Game.Start(); - - base.OnPageLoad(); - - LoadSettings(); - - NewGame(); - ShowLevel(); - - GUIGraphicsContext.OnNewAction -= ah; - GUIGraphicsContext.OnNewAction += ah; - - GUIPropertyManager.SetProperty("#minesweeper_bombs", "Bombs: " + bcnt.ToString()); - GUIPropertyManager.SetProperty("#minesweeper_seconds", "Time: " + time.ToString()); - - GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\smile.png"); - - } - - protected override void OnPageDestroy(int new_windowId) - { - _Game.Stop(); - _Game.Tick -= new EventHandler(_Game_Tick); - - SaveSettings(); - } - - protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) - { - if ((controlId >= 500) && (!GameOver)) - { - GameON = true; - - int y = controlId - 500; - y = (int)y / 30; - - int x = controlId - 500; - x = x - (y * 30); - - x = x - 1; - y = y - 1; - - if ((x >= 0) && (y >= 0) && (x < bx) && (y < by)) - { - Point pt = new Point(); - pt.X = x; - pt.Y = y; - - SetPlace(pt); - } - } - - - if (control == BtnWhatsThis) - { - OnBtnWhatsThis(); - } - if (control == BtnLevel) - { - OnBtnLevel(); - } - if (control == BtnStart) - { - NewGame(); - } - - - } - - protected override void OnShowContextMenu() - { - base.OnShowContextMenu(); - } - - 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)) - { - time++; - } - GUIPropertyManager.SetProperty("#minesweeper_seconds", "Time: " + time.ToString()); - GUIPropertyManager.SetProperty("#minesweeper_bombs", "Bombs: " + bcnt.ToString()); - } - - 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.DoModal(GetID); - } - - private void OnBtnLevel() - { //Choose level for the game - { - if (Level == "Nor") - { - Level = "Pro"; - } - else if (Level == "Pro") - { - Level = "Am"; - } - else - { - Level = "Nor"; - } - NewGame(); - ShowLevel(); - } - } - - private void ShowLevel() - { - if (Level == "Pro") - { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Professional"); - } - if (Level == "Am") - { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Amateur"); - } - if (Level == "Nor") - { - GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Normal"); - } - } - - private void Init_board() - { - // get position from the start button - int StartX = GetControl(1200).XPosition; - int StartY = GetControl(1200).YPosition; - // Disable level control - GUIControl.HideControl(GetID, 1200); - - try - { - int StartT = GetControl(500).XPosition; - } - catch - { - initBoard = false; - } - - if (!initBoard) - { - initBoard = true; - - // set start button navigation - GetControl(2).SetNavigation(8, 4, 2, 531); - - for (int y = 0; y < (by+2); y++) - { - for (int x = 0; x < (bx+2); x++) - { - int nr = 500 + x + (y * 30); - - int xp = StartX + (20 * x); - int yp = StartY + (20 * y); - - //default navigation - int up = nr - 30; - int dn = nr + 30; - int le = nr - 1; - int ri = nr + 1; - //top bottom navigation - if ((y == 0) || (y==by+1)) - { - up = nr; - dn = nr; - le = nr; - ri = nr; - } - //left right navigation - if ((x == 0) || (x == bx + 1)) - { - up = nr; - dn = nr; - le = nr; - ri = nr; - } - //left to start - if (x == 1) - { - le = 2; - } - // right stop - if (x == bx) - { - ri = nr; - } - // top stop - if (y == 1) - { - up = nr; - } - // right stop - if (y == by) - { - dn = nr; - } - - CreateButton(nr, xp, yp, 20, 20, "#F" + nr, "#NF" + nr); - GetControl(nr).SetNavigation(up, dn, le, ri); - - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\unchecksel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\uncheckunsel.png"); - - } - } - for (int x = 0; x < (bx + 2); x++) - { - int nr = 500 + x; - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\topborder.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\topborder.png"); - } - for (int x = 0; x < (bx + 2); x++) - { - int nr = 500 + (30*(by+1)) + x; - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\bottomborder.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\bottomborder.png"); - } - for (int y = 0; y < by; y++) - { - int nr = 530 + (y*30); - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\leftborder.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\leftborder.png"); - nr = nr + bx + 1; - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\rightborder.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\rightborder.png"); - } - GUIPropertyManager.SetProperty("#F" + 500, @"\Minesweeper\Board\topleftcorner.png"); - GUIPropertyManager.SetProperty("#NF" + 500, @"\Minesweeper\Board\topleftcorner.png"); - GUIPropertyManager.SetProperty("#F" + (501+bx), @"\Minesweeper\Board\toprightcorner.png"); - GUIPropertyManager.SetProperty("#NF" + (501+bx), @"\Minesweeper\Board\toprightcorner.png"); - - GUIPropertyManager.SetProperty("#F" + (500+(30*(by+1))), @"\Minesweeper\Board\bottomleftcorner.png"); - GUIPropertyManager.SetProperty("#NF" + (500+(30*(by+1))), @"\Minesweeper\Board\bottomleftcorner.png"); - GUIPropertyManager.SetProperty("#F" + (501+(30*(by+1)+bx)), @"\Minesweeper\Board\bottomrightcorner.png"); - GUIPropertyManager.SetProperty("#NF" + (501+(30*(by+1)+bx)), @"\Minesweeper\Board\bottomrightcorner.png"); - - } - - GUIControl.FocusControl(GetID, 531); - } - - private void SetPlace(Point pos) - { - if ((bombs[pos.X, pos.Y] != 0) && (board[pos.X, pos.Y] != 9)) - { - GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\sad.png"); - GameOver = true; - MediaPortal.Util.Utils.PlaySound("bomb.wav", false, true); - EndGame(); - board[pos.X, pos.Y] = 12; - SetPoint(pos); - } - if (board[pos.X, pos.Y] == 20) - { - board[pos.X, pos.Y] = GetValue(pos); - SetPoint(pos); - if (board[pos.X, pos.Y] == 0) - { - EmptyPos(); - } - if (Finished() == true) - { - CheckAllBoms(); - GameOver = true; - GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\cool.png"); - CheckHiScore(); - } - } - } - - private void SetPoint(Point pos) - { - int nr = 531 + (pos.Y * 30) + pos.X; - - if (board[pos.X, pos.Y] == 0) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check0sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check0unsel.png"); - } - if (board[pos.X, pos.Y] == 1) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check1sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check1unsel.png"); - } - if (board[pos.X, pos.Y] == 2) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check2sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check2unsel.png"); - } - if (board[pos.X, pos.Y] == 3) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check3sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check3unsel.png"); - } - if (board[pos.X, pos.Y] == 4) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check4sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check4unsel.png"); - } - if (board[pos.X, pos.Y] == 5) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check5sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check5unsel.png"); - } - if (board[pos.X, pos.Y] == 6) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check6sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check6unsel.png"); - } - if (board[pos.X, pos.Y] == 7) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check7sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check7unsel.png"); - } - if (board[pos.X, pos.Y] == 8) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\check8sel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\check8unsel.png"); - } - if (board[pos.X, pos.Y] == 9) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\markedasbomsel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\markedasbom.png"); - } - if (board[pos.X, pos.Y] == 10) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\questionmarksel.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\questionmark.png"); - } - if (board[pos.X, pos.Y] == 11) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\bomb.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\bomb.png"); - } - if (board[pos.X, pos.Y] == 12) - { - GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\bombexplode.png"); - GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\bombexplode.png"); - } - if (board[pos.X, pos.Y] == 20) - { - 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; - - for (int i = 0; i < 8; i++) - { - int x = pos.X + posX[i]; - int y = pos.Y + posY[i]; - if ((x>=0) && (y>=0) && (x<bx) && (y<by)) - { - if (bombs[x, y] != 0) - { - val++; - } - } - - } - return val; - } - - private int GetMBombs(Point pos) - { - int val = 0; - - for (int i = 0; i < 8; i++) - { - int x = pos.X + posX[i]; - int y = pos.Y + posY[i]; - if ((x >= 0) && (y >= 0) && (x < 30) && (y < 30)) - { - if (board[x, y] == 9) - { - val++; - } - } - - } - return val; - } - - private void EndGame() - { - for (int y = 0; y < by; y++) - { - for (int x = 0; x < bx; x++) - { - if (bombs[x, y] != 0) - { - board[x, y] = 11; - Point pos = new Point(); - pos.X = x; - pos.Y = y; - SetPoint(pos); - } - } - } - } - - private void EmptyPos() - { - bool rep = true; - - while (rep) - { - rep = false; - for (int y = 0; y < by; y++) - { - for (int x = 0; x < bx; x++) - { - if (board[x, y] == 0) - { - // bomb counter = 0 - int cnt = 0; - for (int i = 0; i < 8; i++) - { - int x1 = x + posX[i]; - int y1 = y + posY[i]; - if ((x1 >= 0) && (y1 >= 0) && (x1 < bx) && (y1 < by)) - { - if (bombs[x1, y1] != 0) - { // found bomb - cnt++; - } - } - } - - if (cnt == 0) - { - for (int i = 0; i < 8; i++) - { - int x1 = x + posX[i]; - int y1 = y + posY[i]; - if ((x1 >= 0) && (y1 >= 0) && (x1 < bx) && (y1 < by)) - { - if (board[x1, y1] == 20) - { - Point pos = new Point(); - pos.X = x1; - pos.Y = y1; - - board[x1, y1] = GetValue(pos) ; - SetPoint(pos); - rep = true; - } - } - } - } - } - } - } - } - - } - - private void SetBomb() - { - if ((ID >= 500) && (!GameOver)) - { - GameON = true; - - int y = ID - 500; - y = (int)y / 30; - - int x = ID - 500; - x = x - (y * 30); - - x = x - 1; - y = y - 1; - - int val = board[x, y]; - - if ((x >= 0) && (y >= 0) && (x < bx) && (y < by)) - { - if (val == 20) - { - Point pt = new Point(); - pt.X = x; - pt.Y = y; - board[x, y] = 9; - SetPoint(pt); - bcnt--; - } - if (val == 9) - { - Point pt = new Point(); - pt.X = x; - pt.Y = y; - board[x, y] = 20; - SetPoint(pt); - bcnt++; - } - } - if (Finished() == true) - { - CheckAllBoms(); - GameOver = true; - GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\cool.png"); - CheckHiScore(); - } - } - } - - private void SetQuest() - { - if ((ID >= 500) && (!GameOver)) - { - GameON = true; - - int y = ID - 500; - y = (int)y / 30; - - int x = ID - 500; - x = x - (y * 30); - - x = x - 1; - y = y - 1; - - int val = board[x, y]; - - if ((x >= 0) && (y >= 0) && (x < bx) && (y < by)) - { - if (val == 20) - { - Point pt = new Point(); - pt.X = x; - pt.Y = y; - board[x, y] = 10; - SetPoint(pt); - } - if (val == 10) - { - Point pt = new Point(); - pt.X = x; - pt.Y = y; - board[x, y] = 20; - SetPoint(pt); - } - } - } - } - - private void Check9() - { - if ((ID >= 500) && (!GameOver) && (GameON)) - { - int y = ID - 500; - y = (int)y / 30; - - int x = ID - 500; - x = x - (y * 30); - - x = x - 1; - y = y - 1; - - if ((x >= 0) && (y >= 0) && (x < bx) && (y < by)) - { - int val = board[x, y]; - Point pt = new Point(); - pt.X = x; - pt.Y = y; - - if (val == GetMBombs(pt)) - { - for (int i = 0; i < 8; i++) - { - Point px = new Point(); - px.X = x + posX[i]; - px.Y = y + posY[i]; - - if ((px.X >= 0) && (px.Y >= 0) && (px.X < bx) && (px.Y < by)) - { - SetPlace(px); - } - } - } - } - } - - } - - private void CheckAllBoms() - { - for (int y = 0; y < by; y++) - { - for (int x = 0; x < bx; x++) - { - if ((board[x,y]==20) && (bombs[x,y]==1)) - { - board[x, y] = 9; - Point px = new Point(); - px.X = x; - px.Y = y; - SetPoint(px); - } - } - } - bcnt = 0; - } - - private bool Finished() - { - bool state = true; - - for (int y = 0; y < by; y++) - { - for (int x = 0; x < bx; x++) - { - if ((board[x, y] == 20) && (bombs[x, y] == 0)) - { - state = false; - break; - } - if ((bombs[x,y]==1) && !((board[x, y] == 20) || (board[x, y] == 9))) - { - state = false; - break; - } - } - } - - return state; - - } - - private void CheckHiScore() - { - if (time < int.Parse (time_rec)) - { - time_rec = time.ToString(); - - VirtualKeyboard menu = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); - menu.Reset(); - menu.DoModal(GetID); - - if (menu.Text == "") - { - menu.Text = "me"; - } - - time_name = menu.Text; - - SetScore(); - GUIPropertyManager.SetProperty("#minesweeper_record", "Record: " + time_rec + "s - " + time_name); - - } - } - - private void SetScore() - { - if (Level == "Pro") - { - t_pro = time_rec; - n_pro = time_name; - } - if (Level == "Am") - { - t_am = time_rec; - n_am = time_name; - } - if (Level == "Nor") - { - t_nor = time_rec; - n_nor = time_name; - } - } - - void LoadSettings() - { - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - n_am = xmlreader.GetValueAsString("My Minesweeper", "Name_Am", "Mark"); - n_nor = xmlreader.GetValueAsString("My Minesweeper", "Name_Nor", "Mark"); - n_pro = xmlreader.GetValueAsString("My Minesweeper", "Name_Pro", "Mark"); - - t_am = xmlreader.GetValueAsString("My Minesweeper", "Time_Am", "60"); - t_nor = xmlreader.GetValueAsString("My Minesweeper", "Time_Nor", "300"); - t_pro = xmlreader.GetValueAsString("My Minesweeper", "Time_Pro", "800"); - - - } - } - - void SaveSettings() - { - using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - xmlwriter.SetValue("My Minesweeper", "Name_Am", n_am); - xmlwriter.SetValue("My Minesweeper", "Name_Nor", n_nor); - xmlwriter.SetValue("My Minesweeper", "Name_Pro", n_pro); - - xmlwriter.SetValue("My Minesweeper", "Time_Am", t_am); - xmlwriter.SetValue("My Minesweeper", "Time_Nor", t_nor); - xmlwriter.SetValue("My Minesweeper", "Time_Pro", t_pro); - } - } - } -} Deleted: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.csproj =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.csproj 2007-05-27 10:46:40 UTC (rev 476) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.csproj 2007-05-27 11:03:51 UTC (rev 477) @@ -1,68 +0,0 @@ -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>8.0.50727</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{04306ABC-5261-4EBB-B7CA-3D4AFA862739}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>MyMinesweeper</RootNamespace> - <AssemblyName>MyMinesweeper</AssemblyName> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>..\..\..\..\MediaPortal\xbmc\bin\Debug\plugins\windows\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="Core, Version=1.0.2681.38747, Culture=neutral, processorArchitecture=x86"> - <SpecificVersion>False</SpecificVersion> - <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> - <Private>False</Private> - </Reference> - <Reference Include="System" /> - <Reference Include="System.Data" /> - <Reference Include="System.Drawing" /> - <Reference Include="System.Windows.Forms" /> - <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> - <Private>False</Private> - </Reference> - </ItemGroup> - <ItemGroup> - <Compile Include="MyMinesweeper.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <ItemGroup> - <EmbeddedResource Include="minesweeper.png" /> - <EmbeddedResource Include="minesweeperDisabled.png" /> - </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project> \ No newline at end of file Deleted: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/minesweeper.png =================================================================== (Binary files differ) Deleted: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/minesweeperDisabled.png =================================================================== (Binary files differ) Copied: trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs (from rev 473, trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper/MyMinesweeper.cs) =================================================================== --- trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs (rev 0) +++ trunk/plugins/My Minesweeper/Source/MyMinesweeper/MyMinesweeper.cs 2007-05-27 11:03:51 UTC (rev 477) @@ -0,0 +1,1065 @@ +#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.Collections.Generic; +using System.Text; +using System.Windows.Forms; +using System.Drawing; + +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; +using MediaPortal.Util; +using MediaPortal.Configuration; + +namespace MediaPortal.GUI.MyMinesweeper +{ + [PluginIcons("MyMinesweeper.minesweeper.png", "MyMinesweeper.minesweeperDisabled.png")] + public class MyMinesweeper : GUIWindow, ISetupForm + { + #region SkinControl + + [SkinControlAttribute(2)] + protected GUIButtonControl BtnStart = null; + [SkinControlAttribute(4)] + protected GUIButtonControl BtnLevel = null; + [SkinControlAttribute(8)] + protected GUIButtonControl BtnWhatsThis = null; + + #endregion + + #region Private variables + + string Level = "Am"; // Choosen level + bool GameOver = false; // not game over + bool GameON = false; // Game is on + + int[,] board = new int[30, 30]; + int[,] bombs = new int[30, 30]; + bool initBoard = false; + + int bx = 10; + int by = 10; + int bcnt = 10; + + int time = 0; + string time_rec = "999"; + string time_name = "unknown"; + + string t_pro; + string t_nor; + string t_am; + + string n_pro; + string n_nor; + string n_am; + + int ID = 0; + + private static OnActionHandler ah; + + // game ticker for the timer + private System.Windows.Forms.Timer _Game = new System.Windows.Forms.Timer(); + + int[] posX = { -1, 0, 1, -1, 1, -1 , 0 , 1 }; + int[] posY = { -1, -1, -1, 0, 0, 1, 1, 1 }; + + #endregion + + #region ISetupForm Members + + // Returns the name of the plugin which is shown in the plugin menu + public string PluginName() + { + return "My Minesweeper"; + } + + // Returns the description of the plugin is shown in the plugin menu + public string Description() + { + return "My Minesweeper"; + } + + // Returns the author of the plugin which is shown in the plugin menu + public string Author() + { + return "Mark Koenig (kroko)"; + } + + // show the setup dialog + public void ShowPlugin() + { + MessageBox.Show("Nothing to configure, this is just an example"); + } + + // Indicates whether plugin can be enabled/disabled + public bool CanEnable() + { + return true; + } + + // get ID of windowplugin belonging to this setup + public int GetWindowId() + { + return 32327501; + } + + // Indicates if plugin is enabled by default; + public bool DefaultEnabled() + { + return true; + } + + // indicates if a plugin has its own setup screen + public bool HasSetup() + { + return false; + } + + /// <summary> + /// If the plugin should have its own button on the main menu of MediaPortal then it + /// should return true to this method, otherwise if it should not be on home + /// it should return false + /// </summary> + /// <param name="strButtonText">text the button should have</param> + /// <param name="strButtonImage">image for the button, or empty for default</param> + /// <param name="strButtonImageFocus">image for the button, or empty for default</param> + /// <param name="strPictureImage">subpicture for the button or empty for none</param> + /// <returns>true : plugin needs its own button on home + /// false : plugin does not need its own button on home</returns> + + 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(); + strButtonImage = String.Empty; + strButtonImageFocus = String.Empty; + strPictureImage = @"hover_my_minesweeper.png"; + return true; + } + + #endregion + + public override int GetID + { + get + { + return 32327501; + } + set + { + base.GetID = value; + } + } + + public override bool Init() + { + 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; + } + return base.OnMessage(message); + } + + public void Dispose() + { + _Game.Stop(); + _Game.Tick -= new EventHandler(_Game_Tick); + } + + protected override void OnPageLoad() + { + + // start game ticker + _Game.Interval = 1000; + _Game.Tick += new EventHandler(_Game_Tick); + _Game.Start(); + + base.OnPageLoad(); + + LoadSettings(); + + NewGame(); + ShowLevel(); + + GUIGraphicsContext.OnNewAction -= ah; + GUIGraphicsContext.OnNewAction += ah; + + GUIPropertyManager.SetProperty("#minesweeper_bombs", "Bombs: " + bcnt.ToString()); + GUIPropertyManager.SetProperty("#minesweeper_seconds", "Time: " + time.ToString()); + + GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\smile.png"); + + } + + protected override void OnPageDestroy(int new_windowId) + { + _Game.Stop(); + _Game.Tick -= new EventHandler(_Game_Tick); + + SaveSettings(); + } + + protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) + { + if ((controlId >= 500) && (!GameOver)) + { + GameON = true; + + int y = controlId - 500; + y = (int)y / 30; + + int x = controlId - 500; + x = x - (y * 30); + + x = x - 1; + y = y - 1; + + if ((x >= 0) && (y >= 0) && (x < bx) && (y < by)) + { + Point pt = new Point(); + pt.X = x; + pt.Y = y; + + SetPlace(pt); + } + } + + + if (control == BtnWhatsThis) + { + OnBtnWhatsThis(); + } + if (control == BtnLevel) + { + OnBtnLevel(); + } + if (control == BtnStart) + { + NewGame(); + } + + + } + + protected override void OnShowContextMenu() + { + base.OnShowContextMenu(); + } + + 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)) + { + time++; + } + GUIPropertyManager.SetProperty("#minesweeper_seconds", "Time: " + time.ToString()); + GUIPropertyManager.SetProperty("#minesweeper_bombs", "Bombs: " + bcnt.ToString()); + } + + 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.DoModal(GetID); + } + + private void OnBtnLevel() + { //Choose level for the game + { + if (Level == "Nor") + { + Level = "Pro"; + } + else if (Level == "Pro") + { + Level = "Am"; + } + else + { + Level = "Nor"; + } + NewGame(); + ShowLevel(); + } + } + + private void ShowLevel() + { + if (Level == "Pro") + { + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Professional"); + } + if (Level == "Am") + { + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Amateur"); + } + if (Level == "Nor") + { + GUIControl.SetControlLabel(GetID, BtnLevel.GetID, "Level: Normal"); + } + } + + private void Init_board() + { + // get position from the start button + int StartX = GetControl(1200).XPosition; + int StartY = GetControl(1200).YPosition; + // Disable level control + GUIControl.HideControl(GetID, 1200); + + try + { + int StartT = GetControl(500).XPosition; + } + catch + { + initBoard = false; + } + + if (!initBoard) + { + initBoard = true; + + // set start button navigation + GetControl(2).SetNavigation(8, 4, 2, 531); + + for (int y = 0; y < (by+2); y++) + { + for (int x = 0; x < (bx+2); x++) + { + int nr = 500 + x + (y * 30); + + int xp = StartX + (20 * x); + int yp = StartY + (20 * y); + + //default navigation + int up = nr - 30; + int dn = nr + 30; + int le = nr - 1; + int ri = nr + 1; + //top bottom navigation + if ((y == 0) || (y==by+1)) + { + up = nr; + dn = nr; + le = nr; + ri = nr; + } + //left right navigation + if ((x == 0) || (x == bx + 1)) + { + up = nr; + dn = nr; + le = nr; + ri = nr; + } + //left to start + if (x == 1) + { + le = 2; + } + // right stop + if (x == bx) + { + ri = nr; + } + // top stop + if (y == 1) + { + up = nr; + } + // right stop + if (y == by) + { + dn = nr; + } + + CreateButton(nr, xp, yp, 20, 20, "#F" + nr, "#NF" + nr); + GetControl(nr).SetNavigation(up, dn, le, ri); + + GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\unchecksel.png"); + GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\uncheckunsel.png"); + + } + } + for (int x = 0; x < (bx + 2); x++) + { + int nr = 500 + x; + GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\topborder.png"); + GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\topborder.png"); + } + for (int x = 0; x < (bx + 2); x++) + { + int nr = 500 + (30*(by+1)) + x; + GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\bottomborder.png"); + GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\bottomborder.png"); + } + for (int y = 0; y < by; y++) + { + int nr = 530 + (y*30); + GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\leftborder.png"); + GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\leftborder.png"); + nr = nr + bx + 1; + GUIPropertyManager.SetProperty("#F" + nr, @"\Minesweeper\Board\rightborder.png"); + GUIPropertyManager.SetProperty("#NF" + nr, @"\Minesweeper\Board\rightborder.png"); + } + GUIPropertyManager.SetProperty("#F" + 500, @"\Minesweeper\Board\topleftcorner.png"); + GUIPropertyManager.SetProperty("#NF" + 500, @"\Minesweeper\Board\topleftcorner.png"); + GUIPropertyManager.SetProperty("#F" + (501+bx), @"\Minesweeper\Board\toprightcorner.png"); + GUIPropertyManager.SetProperty("#NF" + (501+bx), @"\Minesweeper\Board\toprightcorner.png"); + + GUIPropertyManager.SetProperty("#F" + (500+(30*(by+1))), @"\Minesweeper\Board\bottomleftcorner.png"); + GUIPropertyManager.SetProperty("#NF" + (500+(30*(by+1))), @"\Minesweeper\Board\bottomleftcorner.png"); + GUIPropertyManager.SetProperty("#F" + (501+(30*(by+1)+bx)), @"\Minesweeper\Board\bottomrightcorner.png"); + GUIPropertyManager.SetProperty("#NF" + (501+(30*(by+1)+bx)), @"\Minesweeper\Board\bottomrightcorner.png"); + + } + + GUIControl.FocusControl(GetID, 531); + } + + private void SetPlace(Point pos) + { + if ((bombs[pos.X, pos.Y] != 0) && (board[pos.X, pos.Y] != 9)) + { + GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\sad.png"); + GameOver = true; + MediaPortal.Util.Utils.PlaySound("bomb.wav", false, true); + EndGame(); + board[pos.X, pos.Y] = 12; + SetPoint(pos); + } + if (board[pos.X, pos.Y] == 20) + { + board[pos.X, pos.Y] = GetValue(pos); + SetPoint(pos); + if (board[pos.X, pos.Y] == 0) + { + EmptyPos(); + } + if (Finished() == true) + { + CheckAllBoms(); + GameOver = true; + GUIPropertyManager.SetProperty("#minesweeper_smiley", @"\Minesweeper\cool.png"); + CheckHiScore(); + } + } + } + + private void SetPoint(Point pos) + { + int nr = 531 + (pos.Y * 30) + pos.X; + + if (board[pos.X, pos.Y] == 0) + ... [truncated message content] |