コード例 #1
0
        public bool PlayDrawCard(Player player)
        {
            if (!CanDraw(player))
            {
                return(false);
            }

            var cardDrew = DrawCard();

            AddCardToHand(player, cardDrew);

            Plays.Add(new Play()
            {
                CardNumber           = cardDrew,
                PlayedLocationNumber = -1,
                Draw         = true,
                PlayerHand   = player.Hand,
                PlayerNumber = player.PlayerNumber,
                TurnNumber   = TurnNumber
            });

            CheckForAllDeadCards();

            NextTurn();
            return(true);
        }
コード例 #2
0
        public void Load(string file)
        {
            if (File.Exists(file))
            {
                XDocument doc = XDocument.Load(file);

                XElement elemPresentation = doc.Element("Presentation");

                Plays.Clear();

                if (elemPresentation != null)
                {
                    Name = elemPresentation.Attribute("Name").Value;

                    XElement elemFiles = elemPresentation.Element("Files");
                    if (elemFiles != null)
                    {
                        foreach (XElement elem in elemFiles.Elements("File"))
                        {
                            PresentationPlay play = new PresentationPlay();

                            play.ReadXML(elem);

                            Plays.Add(play);
                        }
                    }
                }
            }
        }
コード例 #3
0
 public void AddPlay(Play play)
 {
     if (Plays == null)
     {
         Plays = new List <Play>();
     }
     Plays.Add(play);
 }
コード例 #4
0
        public Presentation(string name, List <PresentationPlay> pPlays)
        {
            Name = name;

            Plays.Clear();

            foreach (PresentationPlay pPlay in pPlays)
            {
                Plays.Add(pPlay);
            }
        }
コード例 #5
0
 private void CheckOutPlayers()
 {
     foreach (Player player in TeamAOnCourt)
     {
         _playFactory.NewPlay(player, false);
         _playFactory.ChoosePlayType(PlayType.CheckOut);
         Plays.Add(_playFactory.GetPlays().First());
         _playFactory.Clear();
     }
     foreach (Player player in TeamBOnCourt)
     {
         _playFactory.NewPlay(player, true);
         _playFactory.ChoosePlayType(PlayType.CheckOut);
         Plays.Add(_playFactory.GetPlays().First());
         _playFactory.Clear();
     }
 }
コード例 #6
0
        public void AddPlay(Play play)
        {
            Plays.Add(play);
            if (!Scores.ContainsKey(play.Alley))
            {
                Scores.Add(play.Alley, new Painel(play.Alley, play.Date));
            }
            var score = GetPainel(play.Alley);

            if (!score.Players.Any(p => p.Name == play.Name))
            {
                score.Players.Add(new Player()
                {
                    Name = play.Name
                });
            }
            score.LastGame = play.Date;
            score.Players.AddPlay(play);
        }
コード例 #7
0
        public bool PlayLocation(Player player, int location, int card)
        {
            if (!CanPlay(location, card, player))
            {
                return(false);
            }

            RemoveCardFromHand(player, card);
            FillLocation(player, location);

            if (location.Equals(HighestPlayable))
            {
                DetermineHighestPlayable();
            }

            Plays.Add(new Play()
            {
                CardNumber           = card,
                PlayedLocationNumber = location,
                Draw         = false,
                PlayerHand   = player.Hand,
                PlayerNumber = player.PlayerNumber,
                TurnNumber   = TurnNumber
            });

            if (CheckWinCondition(location, player))
            {
                Won           = true;
                WinningPlayer = CurrentPlayer;
            }
            else
            {
                CheckForAllDeadCards();
            }

            NextTurn();
            return(true);
        }
コード例 #8
0
 private void FlushPlay()
 {
     Plays.Add(_playFactory.GetPlays().Last());
     _playFactory.Clear();
 }
コード例 #9
0
        private void ChoosePlayer(int Id)
        {
            var _player = Players.First(p => p.Id == Id);

            if (!_playFactory.HasPlay)
            {
                SetZeroVisibility();
                SetDefaultButtonsVisibleOnly();
                //_play = NewPlayNow(Players.First(p => p.Id == Id), PossesionTeamB);
                _playFactory.NewPlay(_player, PossesionTeamB);
                InfoText = "Wybierz akcję:";
            }
            else
            {
                //_play.Player = Players.First(p => p.Id == Id);
                _playFactory.ConsecutivePlay(_player, TeamB.Contains(_player));
                foreach (var play in _playFactory.GetPlays())
                {
                    Plays.Add(play);

                    if (play.PlayType == PlayType.CheckIn)
                    {
                        if (TeamABench.Contains(play.Player))
                        {
                            TeamABench.Remove(play.Player);
                            TeamAOnCourt.Add(play.Player);
                        }
                        if (TeamBBench.Contains(play.Player))
                        {
                            TeamBBench.Remove(play.Player);
                            TeamBOnCourt.Add(play.Player);
                        }
                    }
                    if (play.PlayType == PlayType.CheckOut)
                    {
                        if (TeamAOnCourt.Contains(play.Player))
                        {
                            TeamAOnCourt.Remove(play.Player);
                            TeamABench.Add(play.Player);
                        }
                        if (TeamBOnCourt.Contains(play.Player))
                        {
                            TeamBOnCourt.Remove(play.Player);
                            TeamBBench.Add(play.Player);
                        }
                    }
                }
                ;

                if (Plays.Last().PlayType == PlayType.Rebound)
                {
                    PossesionTeamB = Plays.Last().TeamB;
                }
                _playFactory.Clear();

                //switch possesion dla zbiorki nieofensywnej
                InfoText = "Wybierz zawodnika";
                SetDefaultButtonsVisibleOnly();
                SetPlayersVisibility();
            }
        }
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (dgEvents.SelectedIndex == -1)
            {
                return;
            }
            if (btnEdit.Content.ToString() == "Edit")
            {
                var selectedPlay = dgEvents.SelectedItem as PlayByPlayEntry;
                dgEvents.IsEnabled  = false;
                btnSave.IsEnabled   = false;
                btnCancel.IsEnabled = false;
                btnAdd.IsEnabled    = false;
                btnDelete.IsEnabled = false;
                _shotClockTimer.Stop();
                _timeLeftTimer.Stop();
                _savedTimeLeft   = _timeLeft;
                _savedShotClock  = _shotClock;
                _savedAwayActive = AwayActive.ToList();
                _savedAwaySubs   = AwaySubs.ToList();
                _savedHomeActive = HomeActive.ToList();
                _savedHomeSubs   = HomeSubs.ToList();
                _savedAwayPoints = Convert.ToInt32(AwayPoints);
                _savedHomePoints = Convert.ToInt32(HomePoints);
                _savedPeriod     = CurrentPeriod;

                _timeLeft = selectedPlay.TimeLeft;
                updateTimeLeftIndication(_timeLeft);

                _shotClock = selectedPlay.ShotClockLeft;
                updateShotClockIndication(_shotClock);

                AwayActive = new ObservableCollection <PlayerStats>(selectedPlay.Team1PlayerIDs.Select(id => _pst[id]).ToList());
                AwaySubs   =
                    new ObservableCollection <PlayerStats>(
                        _bse.PBSList.Where(pbs => pbs.TeamID == _t1ID && !selectedPlay.Team1PlayerIDs.Contains(pbs.PlayerID))
                        .Select(pbs => _pst[pbs.PlayerID])
                        .ToList());
                HomeActive = new ObservableCollection <PlayerStats>(selectedPlay.Team2PlayerIDs.Select(id => _pst[id]).ToList());
                HomeSubs   =
                    new ObservableCollection <PlayerStats>(
                        _bse.PBSList.Where(pbs => pbs.TeamID == _t2ID && !selectedPlay.Team2PlayerIDs.Contains(pbs.PlayerID))
                        .Select(pbs => _pst[pbs.PlayerID])
                        .ToList());

                lstAwayActive.ItemsSource = AwayActive;
                lstAwaySubs.ItemsSource   = AwaySubs;
                lstHomeActive.ItemsSource = HomeActive;
                lstHomeSubs.ItemsSource   = HomeSubs;

                sortPlayerLists();

                cmbEventType.SelectedItem = PlayByPlayEntry.EventTypes[selectedPlay.EventType];
                txtEventDesc.Text         = selectedPlay.EventDesc;
                cmbPlayer1.SelectedItem   = PlayersComboList.Single(item => item.ID == selectedPlay.Player1ID);
                cmbPlayer2.SelectedItem   = selectedPlay.Player2ID != -1
                                              ? PlayersComboList2.Single(item => item.ID == selectedPlay.Player2ID)
                                              : null;
                cmbLocationShotDistance.SelectedItem = selectedPlay.EventType != PlayByPlayEntry.ShotAttemptEventType
                                                           ? PlayByPlayEntry.EventLocations[selectedPlay.Location]
                                                           : ShotEntry.ShotDistances[selectedPlay.ShotEntry.Distance];
                txtLocationDesc.Text       = selectedPlay.LocationDesc;
                cmbShotOrigin.SelectedItem = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType
                                                 ? ShotEntry.ShotOrigins[selectedPlay.ShotEntry.Origin]
                                                 : null;
                cmbShotType.SelectedItem = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType
                                               ? ShotEntry.ShotTypes[selectedPlay.ShotEntry.Type]
                                               : null;
                chkShotIsMade.IsChecked = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType &&
                                          selectedPlay.ShotEntry.IsMade;
                chkShotIsAssisted.IsChecked = selectedPlay.EventType == PlayByPlayEntry.ShotAttemptEventType &&
                                              selectedPlay.ShotEntry.IsAssisted;
                AwayPoints    = selectedPlay.T1PTS;
                HomePoints    = selectedPlay.T2PTS;
                CurrentPeriod = selectedPlay.Quarter;

                btnEdit.Content = "Save";
            }
            else
            {
                if (cmbEventType.SelectedIndex == -1 || cmbPlayer1.SelectedIndex == -1 || cmbLocationShotDistance.SelectedIndex == -1)
                {
                    return;
                }
                if (grdShotEvent.IsEnabled && (cmbShotOrigin.SelectedIndex == -1 || cmbShotType.SelectedIndex == -1))
                {
                    return;
                }
                var play = createPlayByPlayEntryFromCurrent();
                Plays.Remove(dgEvents.SelectedItem as PlayByPlayEntry);
                Plays.Add(play);
                Plays.Sort(new PlayByPlayEntryComparerAsc());

                _timeLeft = _savedTimeLeft;
                updateTimeLeftIndication(_timeLeft);
                _shotClock = _savedShotClock;
                updateShotClockIndication(_shotClock);
                AwayActive    = new ObservableCollection <PlayerStats>(_savedAwayActive);
                AwaySubs      = new ObservableCollection <PlayerStats>(_savedAwaySubs);
                HomeActive    = new ObservableCollection <PlayerStats>(_savedHomeActive);
                HomeSubs      = new ObservableCollection <PlayerStats>(_savedHomeSubs);
                AwayPoints    = _savedAwayPoints;
                HomePoints    = _savedHomePoints;
                CurrentPeriod = _savedPeriod;

                lstAwayActive.ItemsSource = AwayActive;
                lstAwaySubs.ItemsSource   = AwaySubs;
                lstHomeActive.ItemsSource = HomeActive;
                lstHomeSubs.ItemsSource   = HomeSubs;

                sortPlayerLists();

                dgEvents.IsEnabled  = true;
                btnSave.IsEnabled   = true;
                btnCancel.IsEnabled = true;
                btnAdd.IsEnabled    = true;
                btnDelete.IsEnabled = true;

                btnEdit.Content = "Edit";
            }
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (cmbEventType.SelectedIndex == -1 || cmbPlayer1.SelectedIndex == -1 || cmbLocationShotDistance.SelectedIndex == -1)
            {
                return;
            }
            if (grdShotEvent.IsEnabled && (cmbShotOrigin.SelectedIndex == -1 || cmbShotType.SelectedIndex == -1))
            {
                return;
            }
            var play = createPlayByPlayEntryFromCurrent();

            if (chkUpdate.IsChecked == true)
            {
                if (play.EventType == PlayByPlayEntry.ShotAttemptEventType)
                {
                    if (play.ShotEntry.IsMade)
                    {
                        if (play.ShotEntry.Distance > 0 && play.ShotEntry.Distance < 5)
                        {
                            if (play.Team1PlayerIDs.Contains(play.Player1ID))
                            {
                                AwayPoints += 2;
                            }
                            else
                            {
                                HomePoints += 2;
                            }
                        }
                        else if (play.ShotEntry.Distance == 5)
                        {
                            if (play.Team1PlayerIDs.Contains(play.Player1ID))
                            {
                                AwayPoints += 3;
                            }
                            else
                            {
                                HomePoints += 3;
                            }
                        }
                    }
                    else
                    {
                        play.ShotEntry.IsAssisted = false;
                    }
                }
                else if (play.EventType == 3)
                {
                    if (play.Team1PlayerIDs.Contains(play.Player1ID))
                    {
                        AwayPoints++;
                    }
                    else
                    {
                        HomePoints++;
                    }
                }
                play.T1PTS = AwayPoints;
                play.T2PTS = HomePoints;
            }
            Plays.Add(play);
            Plays.Sort(new PlayByPlayEntryComparerAsc());
            dgEvents.ItemsSource = Plays;
        }