Example #1
0
        public static void LeaveGame(this PlayerModel player, NormalGameModel gameModel)
        {
            var _gameModel = gameModel;

            //Tranzakcja dołączenia do gry
            player.User.GameLeaveTransaction(gameModel.Currency, player.Stack);

            //Dołączenie do listy graczy, jesli gracz nie mial rezerwacji i jest to mozliwe
            //_player_book != null &&
            _gameModel.Table.PlayersList.Remove(player);

            //Wysłanie informacji o nowym graczu
            Task.Factory.StartNew(() =>
            {
                foreach (UserModel user in _gameModel.Table.WatchingList)
                {
                    //Pobieramy _client dla user
                    var _c = user.GetClient();

                    //Wysylamy wiadomosc o nowym graczu na danym miejscu
                    //Do wszystkich uzytkownikow obserwujacych stol
                    _c.OnGamePlayerStandup(_gameModel.Table, player);
                }
            });
        }
Example #2
0
 public void OnNormalGameModelUpdate(NormalGameModel table)
 {
     if (OnNormalModeUpdateEvent != null)
     {
         OnNormalModeUpdateEvent(table);
     }
 }
        public NormalModeStackWindow(PokerGameWindow parent)
        {
            InitializeComponent();
            this.parent = parent;
            this.game   = (NormalGameModel)Session.Data.Client.ServiceProxy.GetGameModelByTable(parent.TableModel);

            this.AvailableBallance.Visibility = Visibility.Hidden;

            this.JoinButton.IsEnabled = false;

            this.table_name.Text = this.game.Name;
            this.Blind.Text      = this.game.Table.Stakes;

            this.StackSlider.TickFrequency = (double)this.game.Table.Blind;
            this.StackSlider.Minimum       = (double)this.game.Minimum;
            this.StackSlider.Maximum       = (double)this.game.Maximum;
            this.MinAmount.Text            = CurrencyFormat.Get(
                this.game.Table.Currency, ((decimal)this.StackSlider.Minimum)
                );
            this.StackSlider.Value = this.StackSlider.Maximum;

            this.StackValue.Text = this.StackSlider.Value.ToString();

            //Pobieramy wallet
            Task.Factory.StartNew(() =>
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    wallet = Session.Data.Client.ServiceProxy.GetWallet(this.game.Table.Currency);
                    if (wallet == null)
                    {
                        AvailableBallance.Text = "Brak konta z walutą";
                    }
                    else
                    {
                        AvailableBallance.Text = CurrencyFormat.Get(this.game.Table.Currency, wallet.Available);
                    }

                    if (wallet != null && wallet.Available > this.game.Minimum)
                    {
                        if (wallet.Available < this.game.Maximum)
                        {
                            this.StackSlider.Maximum = (double)wallet.Available;
                        }
                        this.JoinButton.IsEnabled = true;

                        //Tworzymy rezerwacje
                        //Session.Data.Client.ServiceProxy.DoAction(ActionModel.GameActionType.Booking, this.game.Table);
                    }
                    else
                    {
                        this.JoinButton.Content = "Brak funduszy";
                    }

                    this.Loader.Visibility            = Visibility.Hidden;
                    this.AvailableBallance.Visibility = Visibility.Visible;
                }));
            });
        }
 void Instance_OnNormalModeUpdateEvent(NormalGameModel game)
 {
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
     {
         if (game.Table.ID == this.TableModel.ID)
         {
             UpdateInfoLabels(game.Table);
         }
     }));
 }
Example #5
0
        public static void JoinToGame(this PlayerModel player, NormalGameModel gameModel)
        {
            var _gameModel = gameModel;

            //Tranzakcja dołączenia do gry
            player.User.GameJoinTransaction(gameModel.Currency, player.Stack);

            //Dołączenie do listy graczy, jesli gracz nie mial rezerwacji i jest to mozliwe
            _gameModel.Table.PlayersList.Add(player);
        }
Example #6
0
        /// <summary>
        /// Dołącza do trybu normlanego
        /// </summary>
        /// <param name="table"></param>
        /// <param name="stack"></param>
        public void DoJoinNormalMode(NormalGameModel game, int placeID, decimal stack)
        {
            NormalGameModel gameModel = this.GameList.Get <NormalGameController>().Where(g => g.GameModel.ID == game.ID).
                                        Select(g => g.GameModel).
                                        FirstOrDefault();

            var user          = ClientModel.GetUser(CurrentClient);
            var wallet_player = user.User.GetWallet(gameModel.Table.Currency);

            //Sprawdzamy czy użytgkownik ma minimum funduszy do wejścia do gry
            if (wallet_player.Available < gameModel.Minimum && stack > wallet_player.Available)
            {
                throw new ApplicationException("Brak środków na koncie.");
            }
            //Czy uzytkownik siedzi juz przy stole
            if (gameModel.Table.PlayersList.Where(c => c.User.ID == user.User.ID).Select(c => c).FirstOrDefault() != null)
            {
                throw new ApplicationException("Siedzisz już przy tym stole.");
            }

            //Za dużo graczy
            if (gameModel.Table.PlayersList.Count() >= gameModel.Table.Seats)
            {
                throw new ApplicationException("Stół jest pełny.");
            }

            //Wyznacza automatyczne miejsce przy stole
            if (placeID == PlayerModel.AUTO_SEAT)
            {
                placeID = gameModel.Table.FreeSeats().ElementAt(0);
            }

            //Czy numer miejsca jest poprawny
            if (placeID > gameModel.Table.Seats - 1 || placeID < 0)
            {
                throw new ApplicationException("Wybrano niepoprawną lokalizację miejsca.");
            }

            //Tworzymy gracza
            PlayerModel _player = new PlayerModel()
            {
                Table    = gameModel.Table,
                User     = (UserModel)user,
                Stack    = stack,
                TimeBank = gameModel.Table.TimeBankOnStart,
                Seat     = placeID
            };

            _player.JoinToGame(gameModel);
        }
Example #7
0
        public static void OpenGameWindow(NormalGameModel game)
        {
            /**
             * Sprawdz czy stol uruchomiony
             * jesli tak podswietl go jesli nie - utworz nowe okno stolu
             * */
            if (Application.Current.Windows.OfType <PokerGameWindow>().Any(w => w.TableModel.ID == game.Table.ID))
            {
                return;
            }

            PokerGameWindow gameWindow = new PokerGameWindow(game.Table);

            //gameWindow.Owner = MainWindow.Instance;
            gameWindow.Show();
        }
        /// <summary>
        /// Ustawia model gry
        /// </summary>
        /// <param name="gameModel"></param>
        public void SetGameModel(NormalGameModel gameModel)
        {
            this.GameModel = gameModel;
            //Tworzymy stół do gry na podstawie normalgamemodel
            this.GameModel.Table = InitializeTable();

            //Tworzymy obiekt gry
            this.Game = new Game();
            this.Game.Initialize(GameModel.Table);

            //Zmiana graczy
            this.GameModel.Table.PlayersList.CollectionChanged += new NotifyCollectionChangedEventHandler(
                (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                GameModel.Table.Players = GameModel.Table.PlayersList.Count();

                foreach (ClientModel user in PokerService.Instance.Clients)
                {
                    if (GameModel is NormalGameModel)
                    {
                        user.ClientProxy.OnNormalGameModelUpdate((NormalGameModel)this.GameModel);
                    }
                }
            });

            //Zmiana obserwatorów gry
            this.GameModel.Table.WatchingList.CollectionChanged += new NotifyCollectionChangedEventHandler(
                (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                GameModel.Table.Watching = GameModel.Table.WatchingList.Count();

                foreach (ClientModel user in PokerService.Instance.Clients)
                {
                    if (GameModel is NormalGameModel)
                    {
                        user.ClientProxy.OnNormalGameModelUpdate((NormalGameModel)GameModel);
                    }
                }
            });


            //Przypisano nową rękę do gry
            this.Game.OnAfterBaseStartEvent += (game) =>
            {
                foreach (ClientModel user in PokerService.Instance.Clients)
                {
                    if (GameModel is NormalGameModel)
                    {
                        if (user.User.IsOnline())
                        {
                            user.ClientProxy.OnNormalGameModelUpdate((NormalGameModel)GameModel);
                        }
                    }
                }
            };

            //Inicjalizujemy wyrzucanie nieaktywnych graczy z gier normalnych
            this.Game.OnBeforeGameStartEvent += (game) =>
            {
                //Zmienia status graczy ktorzy stracili poieniadze na dontplay
                AllInRemove(game);

                //Usuwa osoby ktore wyszly z gry
                RemoveLeavers(game);

                //Aktualizujemy dane stołu dla obserwatorów
                foreach (UserModel user in this.Game.GameTableModel.WatchingList.ToList())
                {
                    var client = PokerService.Instance.Clients.FirstOrDefault(u => u.User.ID == user.ID);
                    client.ClientProxy.OnNormalGameModelUpdate((NormalGameModel)this.GameModel);
                }
            };
        }
 public NormalGameController(NormalGameModel gameModel)
 {
     this.SetGameModel(gameModel);
 }
Example #10
0
        /// <summary>
        /// Informacje o stole
        /// </summary>
        /// <param name="table"></param>
        public void SetNormalModeNote(NormalGameModel normalMode)
        {
            if (normalMode == null)
            {
                return;
            }
            TablePlayerList.Visibility = Visibility.Visible;

            //Ukrywamy loader
            Loader.Visibility = Visibility.Hidden;

            //Wypisujemy informacje o stole
            EventName.Text   = normalMode.Name;
            EventStatus.Text = "Gra stołowa";
            EventNameID.Text = "ID: #" + (normalMode.ID).ToString().PadLeft(8, '0');

            //PlayerList.ItemsSource = normalMode.Table.PlayersList;
            PlayerList.ItemsSource = null;
            PlayerList.ItemsSource = Session.Data.Client.ServiceProxy.GetTablePlayers(normalMode.Table);

            //Usuwamy click handler
            var routedEventHandlers = Helper.GetRoutedEventHandlers(JoinButton, ButtonBase.ClickEvent);

            if (routedEventHandlers != null)
            {
                foreach (var routedEventHandler in routedEventHandlers)
                {
                    JoinButton.Click -= (RoutedEventHandler)routedEventHandler.Handler;
                }
            }

            //Dajemy zmieniony click handler
            JoinButton.Click += new RoutedEventHandler((object sender, RoutedEventArgs e) => {
                Lobby.OpenGameWindow(normalMode);
            });

            //Parsujemy informacje na temat stolu do listy elementow
            TableSideElementList.ItemsSource = null;
            List <TableSideElement> tableSideElementList = new List <TableSideElement>();

            tableSideElementList.Add(
                new TableSideElement()
            {
                Title       = "Ilość graczy:",
                Description = "Zajęte miejsca/Maksymalna ilość miejsc",
                Value       = normalMode.Table.Players + "/" + normalMode.Table.Seats
            }
                );
            tableSideElementList.Add(
                new TableSideElement()
            {
                Title       = "Średni stack:",
                Description = "Ostatnie 15 rozdań",
                Value       = normalMode.Table.AvgPotCurrency
            }
                );
            tableSideElementList.Add(
                new TableSideElement()
            {
                Title       = "Minimalna kwota:",
                Description = "Minimalna kwota wejścia do gry",
                Value       = CurrencyFormat.Get(normalMode.Currency, normalMode.Minimum)
            }
                );

            TableSideElementList.ItemsSource = tableSideElementList;

            //Jeśli nie ma graczy ukrywamy panel
            if (normalMode.Table.Players == 0)
            {
                NoPlayers.Visibility = Visibility.Visible;
            }
            else
            {
                NoPlayers.Visibility = Visibility.Hidden;
            }
        }
Example #11
0
        public Lobby()
        {
            Console.WriteLine("Lobby constructor");

            this.Initialized += (obj, args) =>
            {
                Console.WriteLine("Lobby.Initialized");

                //Zaznaczam ostatnio aktywna zakladke
                LobbyTab.SelectedIndex = Properties.Settings.Default.LastLobbyTab;

                //Aktualizacja statystyk
                PokerClient.Instance.OnGetStatsInfoEvent += Instance_OnGetStatsInfoEvent;

                //Rekalma
                PokerClient.Instance.OnGetAdvertisingEvent += (adv) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        SetAdvertisingLobby(adv);
                    }));
                };

                //Informacja o nowym transferze
                PokerClient.Instance.OnDepositInfoEvent += (transfer) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        if (!Properties.Settings.Default.DontShowDepositWindow)
                        {
                            DepositInfoWindow deposit = new DepositInfoWindow(transfer);
                            deposit.ShowModal(MainWindow.Instance);
                        }
                    }));
                };

                PokerClient.Instance.OnNormalModeUpdateEvent += (game) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        if (NormalModelList == null)
                        {
                            return;
                        }
                        //Aktualizacja elementów listy
                        NormalGameModel item = NormalModelList.FirstOrDefault(t => t.Table.ID == game.Table.ID);

                        if (item != null)
                        {
                            NormalModelList[NormalModelList.IndexOf(item)] = game;
                            NormalGameModeList.Items.Refresh();
                        }
                    }));
                };

                PokerClient.Instance.OnTournamentGameModelUpdateEvent += (game) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        if (NormalModelList == null)
                        {
                            return;
                        }
                        //Aktualizacja elementów listy
                        ITournamentGameModel item = TournamentModelList.FirstOrDefault(t => t.TournamentModel.ID == game.TournamentModel.ID);

                        if (item != null)
                        {
                            TournamentModelList[TournamentModelList.IndexOf(item)] = game;
                            TournamentGameModeList.Items.Refresh();
                        }
                    }));
                };

                PokerClient.Instance.OnTableOpenWindowEvent += (table) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        if (Application.Current.Windows.OfType <PokerGameWindow>().Any(w => w.TableModel.ID == table.ID))
                        {
                            return;
                        }

                        PokerGameWindow gameWindow = new PokerGameWindow(table);
                        gameWindow.Show();
                    }));
                };

                Session.Data.Client.Connected += (e, o) =>
                {
                    Console.WriteLine("OnConnect");
                    RefreshNormalMode();
                    RefreshTournamentMode();
                };

                Session.Data.Client.Disconnected += (e, o) =>
                {
                    Console.WriteLine("OnDisconnect");
                };

                InitializeLobby();
            };

            InitializeComponent();
        }