Example #1
0
        private void OnRefresh(object obj)
        {
            var sb = new StringBuilder();

            sb.Append("\n");
            sb.Append(GameModule.LoggedUser != null ? GameModule.LoggedUser.Name : "Guest");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append(string.Format("{0} {1}", _gameTable.CurrentPlayer.Color, _gameTable.CurrentPlayer.Name));
            sb.Append("\n");
            sb.Append(_gameTable.GetFen());
            InfoText = sb.ToString();
        }
Example #2
0
        private void SaveGame()
        {
            if (GameModule.LoggedUser != null)
            {
                var nameView = new NameGameToSaveView();
                var res      = nameView.ShowDialog();
                if (res.HasValue && res.Value)
                {
                    var game = new Persistance.SavedGameInfo
                    {
                        Comment   = nameView.GameName.Text,
                        Id        = Guid.NewGuid().ToString(),
                        LastSaved = DateTime.Now,
                        Fen       = _gameTable.GetFen()
                    };
                    GameModule.LoggedUser.SaveGame(game);
                    _eventAggregator.GetEvent <MessageEvent>().Publish(
                        new MessageInfo(
                            4000,
                            string.Format("Game: '{0}' Saved!", game.Fen)
                            )
                        );
                }
                return;
            }
            var saveFileDialog = GetDialog <Microsoft.Win32.SaveFileDialog>();
            var dialogResult   = saveFileDialog.ShowDialog();

            if (dialogResult.HasValue && dialogResult.Value)
            {
                var path = saveFileDialog.FileName;
                using (var fileWriter = new StreamWriter(path))
                {
                    fileWriter.WriteLine(_gameTable.GetFen());
                }
            }
        }
Example #3
0
        public void Act(IGameTable gameTable)
        {
            _gameTable = gameTable;
            var result       = Gateway.GenerateMove(gameTable.GetFen(), gameTable.Difficulty);
            var fromPosition = new Position(result.FromRank, result.FromFile);
            var toPosition   = new Position(result.ToRank, result.ToFile);
            var promotedTo   = result.PromotedTo;

            _gameTable.SetSelectedPiece(fromPosition);
            _gameTable.ParseInput(toPosition);
            if (promotedTo != ' ')
            {
                _gameTable.GetPieces().First(p => p.CurrentPosition == toPosition).Type = Helper.GetType(promotedTo);
            }
            _eventAggregator.GetEvent <RefreshTableEvent>().Publish(gameTable);
        }
Example #4
0
 private void InitializeRules(IGameTable gameTable)
 {
     _rules = new Dictionary <string, IRule>();
     _rules.Add(RuleNames.Mate, new MateRule(() => gameTable.GetFen()));
     _rules.Add(RuleNames.Chess, new ChessRule(gameTable));
 }