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; } // set color. myBoardGame.setColorSection(previewBoard.getColorSectionA(), previewBoard.getColorSectionB()); 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 == "typeBoard") { myBoardGame.setTypeBoard(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())); // } } }
private void btn_export_Click(object sender, EventArgs e) { int[,] tablePlayerHolder = new int[boardHeight, boardWidth]; int[,] tableStatusItem = new int[boardHeight, boardWidth]; int count_player1 = 0; int count_player2 = 0; for (int i = 0; i < boardHeight; i++) { for (int j = 0; j < boardWidth; j++) { if (btnSection[i, j].BackColor == btn_status[1]) { tablePlayerHolder[i, j] = 1; tableStatusItem[i, j] = 1; count_player1++; } else if (btnSection[i, j].BackColor == btn_status[2]) { tablePlayerHolder[i, j] = 1; if (radio_makNeeb.Checked) // mak neeb not hav super. { tableStatusItem[i, j] = 1; } else { tableStatusItem[i, j] = 2; } count_player1++; } else if (btnSection[i, j].BackColor == btn_status[3]) { tablePlayerHolder[i, j] = 2; tableStatusItem[i, j] = 1; count_player2++; } else if (btnSection[i, j].BackColor == btn_status[4]) { tablePlayerHolder[i, j] = 2; if (radio_makNeeb.Checked) // mak neeb not hav super. { tableStatusItem[i, j] = 1; } else { tableStatusItem[i, j] = 2; } count_player2++; } else { tablePlayerHolder[i, j] = 0; tableStatusItem[i, j] = 0; } // set Hsuper , prevent bug. if (i == 0 && btnSection[i, j].BackColor == btn_status[3]) { tableStatusItem[i, j] = 2; } else if (i == boardHeight - 1 && btnSection[i, j].BackColor == btn_status[1]) { tableStatusItem[i, j] = 2; } } } if (count_player1 > 0 && count_player1 <= 20 && count_player2 > 0 && count_player1 <= 20) { //MessageBox.Show(count_player1 + " - " + count_player2); if (radio_makHorse.Checked) { myBoardGame.setTypeBoard("Mak Horse"); } else if (radio_makNeeb.Checked) { myBoardGame.setTypeBoard("Mak Neeb"); } myBoardGame.clearData(); myBoardGame.setSizeBoard(boardWidth, boardHeight); myBoardGame.updateTableTolist(tablePlayerHolder, tableStatusItem); FormSavePage form = new FormSavePage(this, myBoardGame); // load save form. form.Show(); //Hide(); form.Location = new Point(this.Location.X + (this.Width / 4), this.Location.Y + (this.Height / 4)); } else { MessageBox.Show("Sorry , each player should have item more than 1 and less than 20."); } }