Exemple #1
0
        private void btnSaveGame_Click(object sender, EventArgs e)
        {
            if (Board != null && Board.stkWhiteMoves.Count > 0) //&& (Board.stkWhiteMoves.Count >= Board.stkBlackMoves.Count))
            {
                SaveFileDialog dlg = new SaveFileDialog();

                dlg.Filter = "Saved Game|*.sav";
                string savedir = Application.StartupPath + "\\Saved Games";
                if (Directory.Exists(savedir) == false)
                {
                    Directory.CreateDirectory(savedir);
                }
                dlg.InitialDirectory = savedir;
                if (dlg.ShowDialog() != DialogResult.Cancel)
                {
                    string       FEN         = clsFEN.GetFEN(Board);
                    string       strMoveList = GetMoveList(Board.stkWhiteMoves, Board.stkBlackMoves);
                    clsSavedGame save        = new clsSavedGame(Board.GameMode, Board.Difficulty, Board.OwnSide, FEN, strMoveList);

                    save.TimeLimit         = TimeLimit;
                    save.TimeBonus         = TimeBonus;
                    save.MinutesRemaining1 = UcCountDownTimer1.Minute;
                    save.MinutesRemaining2 = UcCountDownTimer2.Minute;
                    save.SecondsRemaining1 = UcCountDownTimer1.Second;
                    save.SecondsRemaining2 = UcCountDownTimer2.Second;
                    if (File.Exists(dlg.FileName))
                    {
                        File.SetAttributes(dlg.FileName, FileAttributes.Normal);
                        File.Delete(dlg.FileName);
                    }
                    save.SaveToFile(dlg.FileName);
                }
            }
        }
Exemple #2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string    fname = listBox1.SelectedItem.ToString();
                DataTable tbl   = clsXMLProcess.GetTable(SavePath + "\\" + fname);
                DataRow   r     = tbl.Rows[0];
                SavedGame                   = new clsSavedGame();
                SavedGame.GameMode          = (GameMode)Convert.ToInt32(r["GameMode"]);
                SavedGame.GameDifficulty    = (GameDifficulty)Convert.ToInt32(r["GameDifficulty"]);
                SavedGame.OwnSide           = (ChessSide)Convert.ToInt32(r["Ownside"]);
                SavedGame.FEN               = r["FEN"].ToString();
                SavedGame.MoveList          = r["MoveList"].ToString();
                SavedGame.TimeBonus         = Convert.ToInt16(r["TimeBonus"]);
                SavedGame.TimeLimit         = Convert.ToInt16(r["TimeLimit"]);
                SavedGame.MinutesRemaining1 = Convert.ToInt16(r["mRemain1"]);
                SavedGame.MinutesRemaining2 = Convert.ToInt16(r["mRemain2"]);
                SavedGame.SecondsRemaining1 = Convert.ToInt16(r["sRemain1"]);
                SavedGame.SecondsRemaining2 = Convert.ToInt16(r["sRemain2"]);

                lblFileName.Text = listBox1.SelectedItem.ToString();
                Fen2Pic(SavedGame.FEN);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #3
0
        private void btnLoadGame_Click(object sender, EventArgs e)
        {
            try
            {
                frmLoadGame frm = new frmLoadGame();
                bool        K = true, Q = true, k = true, q = true;
                if (Board != null)
                {
                    K = UcChessBoard.KINGsideCastling;
                    Q = UcChessBoard.QUEENsideCastling;
                    k = UcChessBoard.kingsideCastling;
                    q = UcChessBoard.queensideCastling;
                }

                DialogResult dr = frm.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    clsSavedGame sav = frm.SavedGame;
                    if (sav != null)
                    {
                        GameMode       eGameMode   = sav.GameMode;
                        GameDifficulty eDiff       = sav.GameDifficulty;
                        ChessSide      eOwnSide    = sav.OwnSide;
                        string         Fen         = sav.FEN;
                        string         strMoveList = sav.MoveList;

                        this.TimeLimit = sav.TimeLimit;
                        this.TimeBonus = sav.TimeBonus;

                        //string[] s = strMoveList.Trim().Split(' ');
                        //if (s[0] != "")
                        //{
                        //    //if (eGameMode == GameMode.VsComputer)
                        //    //    CreateChessBoard(eOwnSide, GameMode.VsNetWorkPlayer, eDiff, clsFEN.DefaultFENstring);
                        //    //else
                        //    //    CreateChessBoard(eOwnSide, eGameMode, clsFEN.DefaultFENstring);
                        //    //bool bSound = Board.PlaySound;
                        //    //bool bMess = Board.ShowMessage;
                        //    //Board.PlaySound = false;
                        //    //frmMessageBox.ShowMessage = false;
                        //    //Board.ShowMessage = false;
                        //    //foreach (string str in s)
                        //    //{
                        //    //    Board.MakeMove(str.Remove(2, 1));
                        //    //}
                        //    //Board.PlaySound = bSound;
                        //    //Board.ShowMessage = bMess;
                        //    //Board.GameMode = eGameMode;
                        //}
                        //else
                        //{
                        if (eGameMode == GameMode.VsComputer)
                        {
                            CreateChessBoard(eOwnSide, eGameMode, eDiff, Fen);
                        }
                        else
                        {
                            CreateChessBoard(eOwnSide, eGameMode, Fen);
                        }
                        //}

                        UcCountDownTimer1.Minute = sav.MinutesRemaining1;
                        UcCountDownTimer1.Second = sav.SecondsRemaining1;
                        UcCountDownTimer2.Minute = sav.MinutesRemaining2;
                        UcCountDownTimer2.Second = sav.SecondsRemaining2;

                        frmMessageBox.ShowMessage = true;
                    }
                }
                else
                {
                    UcChessBoard.KINGsideCastling  = K;
                    UcChessBoard.QUEENsideCastling = Q;
                    UcChessBoard.kingsideCastling  = k;
                    UcChessBoard.queensideCastling = q;
                }
            }
            catch { }
        }