Exemplo n.º 1
0
 /// <summary>
 /// Constructeur de sérialisation.
 /// </summary>
 /// <param name="info"></param>
 /// <param name="ctxt"></param>
 public Save(SerializationInfo info, StreamingContext ctxt)
 {
     Board         = (LogicBoard)info.GetValue("Board", typeof(LogicBoard));
     CurrentPlayer = (Player)info.GetValue("CurrentPlayer", typeof(Player));
     Player2       = (Player)info.GetValue("Player2", typeof(Player));
     turn          = (int)info.GetValue("Turn", typeof(int));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructeur avec paramètres
 /// </summary>
 /// <param name="b"></param>
 /// <param name="current"></param>
 /// <param name="other"></param>
 /// <param name="t"></param>
 public Save(LogicBoard b, Player current, Player other, int t)
 {
     Board         = b;
     CurrentPlayer = current;
     Player2       = other;
     turn          = t;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Chargement d'une partie sérlialisée
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loadClick(object sender, RoutedEventArgs e)
        {
            save = null;
            OpenFileDialog dgl = new OpenFileDialog();

            dgl.DefaultExt = ".xml";
            dgl.Filter     = "XML Documents (.xml)|*.xml";

            DialogResult result = dgl.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                string file = dgl.FileName;

                stream = System.IO.File.Open(file, System.IO.FileMode.Open);
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                save = (Save)bformatter.Deserialize(stream);
                stream.Close();

                logicBoard = save.Board;
                playerTurn = save.turn;

                if (playerTurn % 2 == 0)
                {
                    blackPlayer = save.CurrentPlayer;
                    whitePlayer = save.Player2;
                }
                else
                {
                    whitePlayer = save.CurrentPlayer;
                    blackPlayer = save.Player2;
                }

                System.Windows.MessageBox.Show("Chargement réussi");

                loadFromLogicBoard();
                NotifyPropertyChanged("BlackScore");
                NotifyPropertyChanged("WhiteScore");
                NotifyPropertyChanged("CurrentTurn");
            }
            else
            {
                System.Windows.MessageBox.Show("Chargement échoué, pas de fichier spécifié");
            }
        }
Exemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            lbIABlack.ItemsSource = tournamentPlayers;
            lbIAWhite.ItemsSource = tournamentPlayers;
            mainTimer             = new DispatcherTimer();
            mainTimer.Interval    = new TimeSpan(0, 0, 0, 0, 50); // chaque 100ms
            // Chargement du board
            logicBoard = new LogicBoard();
            logicBoard.fillBoard();
            loadFromLogicBoard();
            DataContext = this;
            mainTimer   = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 1)
            };

            //Timer principal pour les 2 horloges
            mainTimer.Tick += (sender, args) =>
            {
                whitePlayer.tick();
                blackPlayer.tick();

                NotifyPropertyChanged("WhiteTimeLeft");
                NotifyPropertyChanged("BlackTimeLeft");

                if (IsGameFinished())
                {
                    NotifyPropertyChanged("BlackScore");
                    NotifyPropertyChanged("WhiteScore");
                    NotifyPropertyChanged("CurrentTurn");
                    EndGame();
                }
            };
            mainTimer.Start();
            RestartGame();

            MenuFindIA_Click(null, null);
        }