//====================================== // Save file handling //====================================== // Saving actual game private void buttonSaveGame_Click(object sender, EventArgs e) { if (gameState < 0) // 0=not playing / 1=playing / -1-play stopped // here stopped - restart playing { buttonSaveGame.Text = "Megállítás"; gameState = 1; } else if (gameState == 1) { // here playing - stop playing buttonSaveGame.Text = "Folytatás"; gameState = -1; } else { // here not playing - start game saving string gameName = textGameName.Text; if (string.IsNullOrWhiteSpace(gameName)) { string msgid = chlang.GetLocalizedString("MB_msg_MISSname"); string msgtype = chlang.GetLocalizedString("MB_caption_err"); MessageBox.Show(msgid, msgtype, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int gameIndex = GameFile.GetGameIndex(gameName); string oLine = string.Format("[{0}]\t={1}{2}*{3}\t({4}*{4}\t#{5}\t; {6})", textGameName.Text, (actGameDef.gxCross != 0)?"X":"", actGameDef.gxCells, actGameDef.gyCells, actGameDef.gtabSize, numericLevel.Value, textGameComment.Text); gameIndex = GameFile.AddGame(gameIndex, 0, oLine); int ch0 = (gameTable.tabSize > 9)?Constants.chrBase:Constants.numBase; // show '1' if table <= 3x3 else 'A' for (int ii = 0; ii < gameTable.tabSize; ii++) { oLine = ""; for (int jj = 0; jj < gameTable.tabSize; jj++) { int num = gameTable.cell(jj, ii).fixNum; oLine += ((char)((num > 0)?(num + ch0):0x20)).ToString(); } GameFile.AddGame(gameIndex, 1, oLine); } GameFile.AddGame(gameIndex, 2, "*"); } }
private void buttonSaveFile_Click(object sender, EventArgs e) { if (gameState != 0) // 0=not playing / 1=playing / -1-play stopped { return; } // here not playing OpenFileDialog saveFileDlg = new OpenFileDialog(); saveFileDlg.InitialDirectory = ".\\"; saveFileDlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDlg.FilterIndex = 2; saveFileDlg.RestoreDirectory = true; if (saveFileDlg.ShowDialog() == DialogResult.OK) { GameFile.SaveFile(saveFileDlg.FileName); } }
private void comboGameName_SelectedIndexChanged(object sender, EventArgs e) { if (comboGameName.SelectedIndex < 0) { return; } int gameIndex = GameFile.GetGameIndexFull((string)comboGameName.Items[comboGameName.SelectedIndex]); if (gameIndex < 0) { return; } GameParams pars = GameFile.GetGameParameters(gameIndex); if (pars == null) { return; } textGameName.Text = pars.pName; comboGameType.Text = string.Format("={0}{1}*{2}\t({3}*{3})", (pars.pDiag != 0)?"X":"", pars.pX, pars.pY, pars.pSize); numericLevel.Value = pars.pLevel; textGameComment.Text = pars.pComment; if ((actGameDef.gxCells != pars.pX) || (actGameDef.gyCells != pars.pY) || (actGameDef.gxCross != pars.pDiag)) { actGameDef = new GameDef(pars.pX, pars.pY, pars.pDiag, comboGameType.Text); gameTable.InitTable(pars.pX, pars.pY, pars.pDiag); } for (int yy = 0; yy < pars.pSize; yy++) { string rowLine = GameFile.GetGameRow(gameIndex, yy); gameTable.FillTableRow(yy, ((rowLine.Length > 0) && (rowLine[0] != '*'))?rowLine:""); } int nErr = gameTable.CheckTable(true); pictureTable_Resize(null, null); //int errnum=gameTable.CheckTable(true); }
private void buttonLoadFile_Click(object sender, EventArgs e) { if (gameState != 0) // 0=not playing / 1=playing / -1-play stopped { return; } // here not playing OpenFileDialog loadFileDlg = new OpenFileDialog(); loadFileDlg.InitialDirectory = ".\\"; loadFileDlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; loadFileDlg.FilterIndex = 2; loadFileDlg.RestoreDirectory = true; if (loadFileDlg.ShowDialog() == DialogResult.OK) { List <string> names = GameFile.LoadFile(loadFileDlg.FileName); if (names.Count > 0) { comboGameName.Items.Clear(); comboGameName.Items.AddRange(names.ToArray()); comboGameName.SelectedIndex = 0; } } }