/// <summary> /// The opened tiles get assigned a new status according to parameter <paramref name="t"/> /// </summary> /// <param name="t">the new status</param> public static void setStatusOfOpenedImages(tileStatusType t) { for (int i = 0; i < openedImages.Length; i++) { tileStatus[openedImages[i]] = t; } }
}//restoreFromFile() /// <summary> /// Change the status of ALL present tiles to a certain status /// </summary> /// <param name="t"></param> public static void bulkChangeTileStatus(tileStatusType t) { for (int i = 0; i < tileStatus.Length; i++) { tileStatus[i] = t; } }//bulkChangeTileStatus()
/// <summary> /// Setup a new game; this initialises the board using the gamesettings previous setup by /// the settings dialogbox /// </summary> /// <returns></returns> public static bool setupNewGame() { tileStatusType tileStartStatus = tileStatusType.Unknown; switch (gameSettings.gameMode) { case gameModeType.Normal: tileStartStatus = tileStatusType.Closed; gameStatus = gameStatusType.Started; break; case gameModeType.NormalFlash: tileStartStatus = tileStatusType.Flash; gameStatus = gameStatusType.Flashing; break; case gameModeType.SinglePlayer: tileStartStatus = tileStatusType.Closed; gameStatus = gameStatusType.Started; resetSinglePlayerTimer(); break; case gameModeType.SinglePlayerFlash: tileStartStatus = tileStatusType.Flash; gameStatus = gameStatusType.Flashing; resetSinglePlayerTimer(); break; } bulkChangeTileStatus(tileStartStatus); imagePrefix = "themes\\theme-" + theme + "-"; // setup one list of images for the number of tiles. List <String> tempTiles = new List <String>(); for (int i = 0; i < numberOfImages; i++) { String img = imagePrefix + String.Format("{0:00}", i + 1) + ".png"; tempTiles.Add(img); tempTiles.Add(img); } Random rnd = new Random(); int q = 0; while (tempTiles.Count != 0) { int p = rnd.Next(tempTiles.Count); String img = tempTiles[p]; tempTiles.RemoveAt(p); tileImages[q++] = img; } return(true); }//setupNewGame()
}//bulkChangeTileStatus() /// <summary> /// Setup the game using an XML document (read from file) indicated by <paramref name="xml"/> /// </summary> /// <param name="xml">An XMLDocument </param> /// <returns></returns> public static bool setupFromXML(XmlDocument xml) { XmlNodeList nodes = xml.SelectNodes("/savegame/highscores/place"); foreach (XmlNode item in nodes) { XmlNode nodeName = item.SelectSingleNode("./name/text()"); XmlNode nodeScore = item.SelectSingleNode("./score/text()"); String strName; int intScore; strName = nodeName.Value; intScore = Convert.ToUInt16(nodeScore.Value); KeyValuePair <string, int> combi = new KeyValuePair <string, int>(strName, intScore); highscoreNames.Add(combi); } //<dimensions>< x > 4 </ x >< y > 4 </ y ></ dimensions > XmlNode dimensions = xml.SelectSingleNode("//game/dimensions"); int x, y; x = Convert.ToInt16(dimensions.SelectSingleNode("./x/text()").Value); y = Convert.ToInt16(dimensions.SelectSingleNode("./y/text()").Value); setSize(x, y); XmlNodeList tileNodes = xml.SelectNodes("//game/tile"); foreach (XmlNode n in tileNodes) { int tileNr; XmlNode img, state; tileNr = Convert.ToInt16(n.Attributes.GetNamedItem("nr").Value); state = n.SelectSingleNode("./state/text()"); img = n.SelectSingleNode("./image/text()"); tileImages[tileNr] = img.InnerText; tileStatusType tempT = tileStatusType.Unknown; switch (state.InnerText) { case "Closed": tempT = tileStatusType.Closed; break; case "Flash": tempT = tileStatusType.Flash; break; case "Found": tempT = tileStatusType.Found; break; case "ShowTemporary": tempT = tileStatusType.ShowTemporary; break; } tileStatus[tileNr] = tempT; } XmlNode themeNode = xml.SelectSingleNode("//game/theme/text()"); gameSettings.theme = themeNode.Value; XmlNodeList playerNodes = xml.SelectNodes("//game/players/player"); int j = 0; foreach (XmlNode xn in playerNodes) { XmlNode pAvatar; players[j].name = xn.SelectSingleNode("./name/text()").Value; players[j].score = Convert.ToInt16(xn.SelectSingleNode("./score/text()").Value); pAvatar = xn.SelectSingleNode("./avatar/"); if (pAvatar != null) { players[j].avatarFilename = xn.SelectSingleNode("./avatar/text()").Value; } j++; } highscoreNames.OrderByDescending(xscore => xscore.Value); return(true); }//setupFromXML()