示例#1
0
        private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string winner = null;
            Rules rules = new Rules();
            rules.checkWinner(gb);
            if (gb.Winner != status.free)
            {
                switch (gb.Winner)
                {
                    case status.draw:
                        winner = "Hra skočila remízou!";
                        break;

                    case status.whitePlayer:
                        winner = "Bílý hráč zvítězil";
                        break;

                    case status.blackPlayer:
                        winner = "Černý hráč zvítězil";
                        break;
                }
            }

            if (e.Cancelled)
            {
                Action enableHistory = () => this.History.Enabled = true;
                Action enablePause = () => this.ButtonPause.Enabled = true;
                History.Invoke(enableHistory);
                ButtonPause.Invoke(enablePause);

                gb.drawBoard();
                MessageBox.Show("Hra byla pozastavena");
                Action setResumeText = () => this.ButtonPause.Text = "Pokračovat";
                pauseButton.Invoke(setResumeText);
            }
            else if (e.Error != null)
            {
                MessageBox.Show(String.Format("Doslo k chybe pri vykonavani vypoctu {0}", e.Error));
            }
            else if (winner != null)
            {
                MessageBox.Show(winner);
                this.pauseButton.Enabled = false;
            }
            else
            {
                this.Activated += this.FriskaDama_Activated;
            }
        }
示例#2
0
        /// <summary>
        ///     Funkce provadejici nacteni hry a zkontrolovani, zda se jedna o korektni ulozeni
        /// </summary>
        /// <param name="filePath">cesta k souboru</param>
        /// <param name="gb">Hraci deska, na niz maji byt zmeny provedeny</param>
        /// <returns>Hraci desku s odehratou hrou</returns>
        public Gameboard loadGame(string filePath, Gameboard gb)
        {
            string  from = "";
            string  to   = "";
            Fairway fwFrom;
            Fairway fwTo;
            var     rules = new Rules();

            gb.Board = gb.newBoard();

            using (XmlReader reader = XmlReader.Create(filePath))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        // nacteme si obtiznost bileho hrace a nastavime
                        case "WHITE":
                            if (reader.Read())
                            {
                                int whitePlayer = Convert.ToInt32(reader.Value.Trim());
                                gb.WhitePlayer = whitePlayer;
                            }
                            break;

                        // nacteme si obtiznost cerneho hrace a nastavime
                        case "BLACK":
                            if (reader.Read())
                            {
                                int blackPlayer = Convert.ToInt32(reader.Value.Trim());
                                gb.BlackPlayer = blackPlayer;
                            }
                            break;

                        // nacteme si zacinajiciho hrace a nastavime
                        case "STARTS":
                            if (reader.Read())
                            {
                                bool startsWhite = Convert.ToBoolean(reader.Value.Trim());
                                gb.StartsWhite = startsWhite;
                            }
                            break;

                        //
                        case "SHOWHELP":
                            if (reader.Read())
                            {
                                bool showHelp = Convert.ToBoolean(reader.Value.Trim());
                                gb.ShowMoveHelp = showHelp;
                            }
                            break;

                        case "FROM":
                            if (reader.Read())
                            {
                                from = reader.Value.Trim();
                            }
                            break;

                        case "TO":
                            if (reader.Read())
                            {
                                to = reader.Value.Trim();
                            }
                            fwFrom = gb.getFigure(from);
                            fwTo   = gb.getFigure(to);
                            rules.generateMoves(gb);
                            rules.makeMove(fwFrom, fwTo, gb, false);
                            gb.addHistory(fwFrom, fwTo);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(gb);
        }
示例#3
0
        private void saveSettingsStartNewGame_Click(object sender, EventArgs e)
        {
            Rules r = new Rules();
            this.gb.Winner = status.free;
            this.mainDialog.cleanHistory();
            this.gb.newBoard();
            bool playingWhite = this.startingPlayerWhite.Checked;
            this.gb.StartsWhite = this.startingPlayerWhite.Checked;
            int whitePlayer = this.whitePlayerHuman.Checked ? 0 : this.whiteComputerDifficulty.Value;
            int blackPlayer = this.blackPlayerHuman.Checked ? 0 : this.blackComputerDifficulty.Value;
            bool showMoveHelp = this.moveHelpYes.Checked;

            mainDialog.enableSettings();

            this.gb.ShowMoveHelp = showMoveHelp;
            this.gb.WhitePlayer = whitePlayer;
            this.gb.BlackPlayer = blackPlayer;
            this.gb.PlayingWhite = playingWhite;

            foreach (Fairway fw in gb.Board)
                fw.Enabled = true;

            r.startGame(gb);
            this.DialogResult = DialogResult.OK;
        }
示例#4
0
        /// <summary>
        /// Funkce provadejici nacteni hry a zkontrolovani, zda se jedna o korektni ulozeni
        /// </summary>
        /// <param name="filePath">cesta k souboru</param>
        /// <param name="gb">Hraci deska, na niz maji byt zmeny provedeny</param>
        /// <returns>Hraci desku s odehratou hrou</returns>
        public Gameboard loadGame(string filePath, Gameboard gb)
        {
            string from = "";
            string to = "";
            Fairway fwFrom;
            Fairway fwTo;
            Rules rules = new Rules();

            gb.Board = gb.newBoard();

            using (XmlReader reader = XmlReader.Create(filePath))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                            // nacteme si obtiznost bileho hrace a nastavime
                            case "WHITE":
                                if (reader.Read())
                                {
                                    int whitePlayer = Convert.ToInt32(reader.Value.Trim());
                                    gb.WhitePlayer = whitePlayer;
                                }
                                break;
                            // nacteme si obtiznost cerneho hrace a nastavime
                            case "BLACK":
                                if (reader.Read())
                                {
                                    int blackPlayer = Convert.ToInt32(reader.Value.Trim());
                                    gb.BlackPlayer = blackPlayer;
                                }
                                break;

                            // nacteme si zacinajiciho hrace a nastavime
                            case "STARTS":
                                if (reader.Read())
                                {
                                    bool startsWhite = Convert.ToBoolean(reader.Value.Trim());
                                    gb.StartsWhite = startsWhite;
                                }
                                break;
                            //
                            case "SHOWHELP":
                                if (reader.Read())
                                {
                                    bool showHelp = Convert.ToBoolean(reader.Value.Trim());
                                    gb.ShowMoveHelp = showHelp;
                                }
                                break;

                            case "FROM":
                                if (reader.Read())
                                    from = (string)reader.Value.Trim();
                                break;

                            case "TO":
                                if (reader.Read())
                                    to = (string)reader.Value.Trim();
                                fwFrom = gb.getFigure(from);
                                fwTo = gb.getFigure(to);
                                rules.generateMoves(gb);
                                rules.makeMove(fwFrom, fwTo, gb, false);
                                gb.addHistory(fwFrom, fwTo);
                                break;

                            default:
                                break;
                        }
                    }
                }
            }

            return gb;
        }