private void Game_List_Load(object sender, EventArgs e) { LoadAllGame(); //加载本地所有游戏 if (game_list != null && game_list.Count > 0) { GameClass game = game_list[game_index]; this.delete_button.Visible = false; string game_path = game.GameImage; this.game_pictureBox.Image = Image.FromFile(Application.StartupPath + "\\Games\\" + game_path); this.game_name_label.Text = game.GameName; } //ShowAllGame(); //显示本地游戏 }
/// <summary> /// 加载本地所有game /// </summary> private void LoadAllGame() { try { game_list = null; game_doc = null; game_list = new List <GameClass>(); game_doc = new XmlDocument(); game_doc.Load(Application.StartupPath + "\\Games\\game.xml"); // 得到根节点theme_list XmlNode xn = game_doc.SelectSingleNode("game_list"); //获得所有子节点 XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xn1 in xnl) { GameClass game = new GameClass(); // 将节点转换为元素,便于得到节点的属性值 XmlElement xe = (XmlElement)xn1; // 得到theme节点的所有子节点 XmlNodeList xnl0 = xe.ChildNodes; // 得到theme所有属性的属性值 game.GameId = int.Parse(xnl0.Item(0).InnerText); game.GameCode = xnl0.Item(1).InnerText; game.GameName = xnl0.Item(2).InnerText; game.GameImage = xnl0.Item(3).InnerText; game.GameUrl = xnl0.Item(4).InnerText; game.Price = Convert.ToDouble(xnl0.Item(5).InnerText); game.GameState = xnl0.Item(6).InnerText; game.DownloadCount = int.Parse(xnl0.Item(7).InnerText); //// 添加theme实例到theme_list集合 game_list.Add(game); } this.delete_button.Visible = false; } catch (Exception) { this.game_name_label.Text = "主题加载失败..."; } }
/// <summary> /// 购买当前游戏 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ok_button_Click(object sender, EventArgs e) { try { GameClass game = game_list[game_index]; XmlDocument game_doc = new XmlDocument(); game_doc.Load(Application.StartupPath + "\\Games\\game.xml"); // 得到根节点game_list,添加一个game节点 XmlNode root1 = game_doc.SelectSingleNode("game_list"); XmlElement root = (XmlElement)root1; //XmlNode xnl = root.FirstChild; XmlElement xe1 = game_doc.CreateElement("game");//创建一个game节点 //添加game_id节点 XmlElement xesub1 = game_doc.CreateElement("game_id"); xesub1.InnerText = game.GameId.ToString(); xe1.AppendChild(xesub1); //添加game_code节点 XmlElement xesub2 = game_doc.CreateElement("game_code"); xesub2.InnerText = game.GameCode; xe1.AppendChild(xesub2); //添加file_name节点 XmlElement xesub3 = game_doc.CreateElement("game_name"); xesub3.InnerText = game.GameName; xe1.AppendChild(xesub3); //添加file_name节点 XmlElement xesub4 = game_doc.CreateElement("game_image"); xesub4.InnerText = game.GameImage; xe1.AppendChild(xesub4); //添加speed_location_x节点 XmlElement xesub5 = game_doc.CreateElement("speed_location_x"); xesub5.InnerText = game.GameUrl; xe1.AppendChild(xesub5); //添加speed_location_y节点 XmlElement xesub6 = game_doc.CreateElement("price"); xesub6.InnerText = game.Price.ToString(); xe1.AppendChild(xesub6); //添加rad_location_x节点 XmlElement xesub7 = game_doc.CreateElement("game_state"); xesub7.InnerText = game.GameState; xe1.AppendChild(xesub7); //添加rad_location_y节点 XmlElement xesub8 = game_doc.CreateElement("download_count"); xesub8.InnerText = game.DownloadCount.ToString(); xe1.AppendChild(xesub8); root1.AppendChild(xe1); //保存XML配置文件 game_doc.Save(Application.StartupPath + "\\Games\\game.xml"); //保存主题文件 Image image = this.game_pictureBox.Image; Bitmap img = new Bitmap(image); img.Save(Application.StartupPath + "\\Games\\" + game_list[game_index].GameImage.ToString()); //更新云端资源状态 Update_Online_game(game_list[game_index].GameId); this.Close(); } catch (Exception) { Console.WriteLine(e.ToString()); //异常处理 this.game_name_label.Font = new System.Drawing.Font("幼圆", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.game_name_label.ForeColor = System.Drawing.Color.Red; this.game_name_label.Text = "暂无购买!"; } }