private void saveSettingToObjectMyGame() { myBoardGame.setSizeBoard(boardWidth, boardHeight); //myBoardGame.setRowItem(rowItem); //myBoardGame.setColorSection(colorSectionA,colorSectionB); // have bug when player not choose button. myBoardGame.setColorSection(previewBoard.getColorSectionA(), previewBoard.getColorSectionB()); myBoardGame.setAI(flagAI); }
private void btn_play_Click(object sender, EventArgs e) { myBoardGame.clearData(); myBoardGame.setAI(flagAI); // Save all data setting to Object. //saveSettingToObjectMyGame(); string size = ""; foreach (DataGridViewRow row in dataGridViewLoadBoard.SelectedRows) { setXMLToObjectGame(row.Cells[1].Value.ToString()); // name file is keyword. size = row.Cells[2].Value.ToString(); // size } //if (colorSectionA != Color.Transparent && colorSectionB != Color.Transparent) { // myBoardGame.setColorSection(colorSectionA, colorSectionB); //} myBoardGame.setColorSection(previewBoard.getColorSectionA(), previewBoard.getColorSectionB()); //myBoardGame.setColorSection(colorSectionA, colorSectionB); if (size == "8 x 8") { myBoardGame.backup(); FormPlay8x8 form = new FormPlay8x8(myBoardGame); form.Show(); Hide(); form.Location = this.Location; if (parentForm != null) { parentForm.Close(); } } else if (size == "12 x 12") { myBoardGame.backup(); FormPlay12x12 form = new FormPlay12x12(myBoardGame); form.Show(); Hide(); form.Location = this.Location; if (parentForm != null) { parentForm.Close(); } } }
private void setXMLToObjectGame(string namefile) { string namefolder = previewBoard.getFolderXML(); string path = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + namefolder + "\\" + namefile + ".xml"; XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch (Exception) { MessageBox.Show("Error , not found file."); return; } myBoardGame.setColorSection(colorA, colorB); // save color. foreach (XmlNode node in doc.DocumentElement.ChildNodes) { if (node.Name == "boardWidth") { myBoardGame.setWidth(Convert.ToInt32(node.InnerText.ToString())); } else if (node.Name == "boardHeight") { myBoardGame.setHeight(Convert.ToInt32(node.InnerText.ToString())); } else if (node.Name == "listTableBoard") { foreach (XmlNode subnode in node.ChildNodes) { if (subnode.Name == "string") { string[] separators = { "," }; string value = subnode.InnerText.ToString(); string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries); int i = 0; int j = 0; int player = 0; int status = 0; i = Convert.ToInt32(words[0]); j = Convert.ToInt32(words[1]); player = Convert.ToInt32(words[2]); status = Convert.ToInt32(words[3]); //Console.Write("" + player); if (player > 0) // have item. { myBoardGame.setTablePlayerHolder(i, j, player); myBoardGame.setTableItemStatus(i, j, status); } } } } else if (node.Name == "TextColorHtmlSection1") { myBoardGame.setColorSectionA(ColorTranslator.FromHtml(node.InnerText.ToString())); } else if (node.Name == "TextColorHtmlSection2") { myBoardGame.setColorSectionB(ColorTranslator.FromHtml(node.InnerText.ToString())); } } }