public void ImportXmlAction(object sender) { var dialog = new OpenFileDialog(); dialog.Title = "Choose the XML file to be imported"; dialog.Filter = "XML|*.xml|All|*.*"; if (dialog.ShowDialog().Value) { try { Board board = Serializer.FromXml <Board>(dialog.FileName); board.Squares = board.Squares.Skip(64).ToObservableCollection(); Chess.Reset(board); PlayerModel1.Reset(); PlayerModel2.Reset(); SetTurnedPlayer(); Message.StartBox(Level.Info, "Your board has successfully been imported and is ready to use", "Export Successful"); } catch (Exception e) { Message.StartBox(Level.Error, e.Message, "Import Error"); return; } } }
public void ImportTxtAction(object sender) { var dialog = new OpenFileDialog(); dialog.Title = "Choose the TXT file to be imported"; dialog.Filter = "Text|*.txt|All|*.*"; if (dialog.ShowDialog().Value) { Board board = null; try { board = Serializer.ImportFromTxt(dialog.FileName); Chess.Reset(board); PlayerModel1.Reset(); PlayerModel2.Reset(); SetTurnedPlayer(); Message.StartBox(Level.Info, "Your board has successfully been imported and is ready to use", "Export Successful"); } catch (Exception e) { Message.StartBox(Level.Error, e.Message, "Import Error"); return; } } }
private void GameOverModel_OnRetry(object sender, EventArgs e) { GameOverModel = null; Chess.Reset(); PlayerModel1.Reset(); PlayerModel2.Reset(); SetTurnedPlayer(); }
private void Player_OnGameOver(object sender, EventArgs e) { var looser = sender as Player; var winner = looser.Color == PlayerModel1.Player.Color ? PlayerModel2.Player : PlayerModel1.Player; GameOverModel = new GameOverViewModel(winner, looser, (e as GameOverEventArgs).GameOver); PlayerModel1.StopTimer(); PlayerModel2.StopTimer(); GameOverModel.OnRetry += GameOverModel_OnRetry; }
private void ChangeTurns() { if (PlayerModel1.Player.IsMyTurn) { PlayerModel1.StopTimer(); PlayerModel2.StartTimer(); PlayerModel1.Player.IsMyTurn = false; PlayerModel2.Player.IsMyTurn = true; } else { PlayerModel2.StopTimer(); PlayerModel1.StartTimer(); PlayerModel2.Player.IsMyTurn = false; PlayerModel1.Player.IsMyTurn = true; } }