扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者: 朱先忠编译 来源:天极开发 2007年11月12日
关键字: C# XML 游戏 Sokoban Pro
public void SaveLevel(Level level) { XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode lastFinishedLvl = doc.SelectSingleNode("//lastFinishedLevel"); lastFinishedLvl.InnerText = level.LevelNr.ToString(); XmlNode setName = doc.SelectSingleNode("/savegame/levelSets/" +"levelSet[@title = \"" + level.LevelSetName + "\"]"); XmlNode nodeLevel = setName.SelectSingleNode("level[@levelNr = " + level.LevelNr + "]"); if (nodeLevel == null){ XmlElement nodeNewLevel = doc.CreateElement("level"); XmlAttribute xa = doc.CreateAttribute("levelNr"); xa.Value = level.LevelNr.ToString(); nodeNewLevel.Attributes.Append(xa); XmlElement moves = doc.CreateElement("moves"); moves.InnerText = level.Moves.ToString(); XmlElement pushes = doc.CreateElement("pushes"); pushes.InnerText = level.Pushes.ToString(); nodeNewLevel.AppendChild(moves); nodeNewLevel.AppendChild(pushes); setName.AppendChild(nodeNewLevel); } else{ XmlElement moves = nodeLevel["moves"]; XmlElement pushes = nodeLevel["pushes"]; int nrOfMoves = int.Parse(moves.InnerText); int nrOfPushes = int.Parse(pushes.InnerText); if (level.Pushes < nrOfPushes){ pushes.InnerText = level.Pushes.ToString(); moves.InnerText = level.Moves.ToString(); } else if (level.Pushes == nrOfPushes && level.Moves < nrOfMoves) moves.InnerText = level.Moves.ToString(); } doc.Save(filename); } |
XmlNode setName = doc.SelectSingleNode("/savegame/levelSets/"+"levelSet[@title = \"" + level.LevelSetName + "\"]"); |
XmlNode nodeLevel = setName.SelectSingleNode("level[@levelNr = "+ level.LevelNr + "]"); |
//绘制级别 for (int i = 0; i < width; i++){ for (int j = 0; j < height; j++){ Image image = GetLevelImage(levelMap[i, j], sokoDirection); g.DrawImage(image, ITEM_SIZE + i * ITEM_SIZE, ITEM_SIZE + j * ITEM_SIZE, ITEM_SIZE, ITEM_SIZE); //设置Sokoban的位置 if (levelMap[i, j] == ItemType.Sokoban || levelMap[i, j] == ItemType.SokobanOnGoal){ sokoPosX = i; sokoPosY = j; } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者