void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.GameResultWnd = ((CardGameClient.GameResultWindow)(target));

            #line 5 "..\..\..\GameResultWindow.xaml"
                this.GameResultWnd.ContentRendered += new System.EventHandler(this.Window_ContentRendered);

            #line default
            #line hidden

            #line 5 "..\..\..\GameResultWindow.xaml"
                this.GameResultWnd.Closed += new System.EventHandler(this.Window_Closed);

            #line default
            #line hidden
                return;

            case 2:
                this.PlaceHolder = ((System.Windows.Controls.Image)(target));
                return;

            case 3:
                this.GameResultLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.LevelLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 5:
                this.ExpLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 6:
                this.ScoreLabel = ((System.Windows.Controls.Label)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 2
0
        public void DoGame()
        {
            try
            {
                while (true)
                {
                    Thread.Sleep(500);

                    var isError = false;

                    App.ProxyMutex.WaitOne();
                    try
                    {
                        game = ServiceProxy.Proxy.getGame(App.NickName);
                    }
                    catch
                    {
                        App.OnException();
                        isError = true;
                    }

                    App.ProxyMutex.ReleaseMutex();

                    if (isError)
                    {
                        App.OnConnectionError();
                        return;
                    }


                    if (game != null)
                    {
                        if (game.gameState == 2 || game.gameState == 3)
                        {
                            foreach (var item in game.firstGamerCards)
                            {
                                Dispatcher.Invoke(new Action(delegate
                                {
                                    if (game.fGamer.nick == App.NickName)
                                    {
                                        if (myCardPlases[item.slot].ThisCard != null && item.IsAttacked &&
                                            !myCardPlases[item.slot]
                                            .ThisCard.IsAttacked)
                                        {
                                            enemyCardPlases[game.lastHitInfo.slot].AnimateTurn(true);
                                            lasthitCard = game.lastHitInfo.slot;
                                            myCardPlases[item.slot].AnimateDmgAdtnl(game.lastHitInfo);
                                        }

                                        myCardPlases[item.slot].ThisCard = item;
                                        myCardPlases[item.slot].Enabled  = item.Enabled;
                                    }
                                    else
                                    {
                                        enemyCardPlases[item.slot].ThisCard = item;
                                    }
                                }));
                            }

                            foreach (var item in game.twoGamerCards)
                            {
                                Dispatcher.Invoke(new Action(delegate
                                {
                                    if (game.fGamer.nick != App.NickName)
                                    {
                                        if (myCardPlases[item.slot].ThisCard != null && item.IsAttacked &&
                                            !myCardPlases[item.slot]
                                            .ThisCard.IsAttacked)
                                        {
                                            enemyCardPlases[game.lastHitInfo.slot].AnimateTurn(true);
                                            lasthitCard = game.lastHitInfo.slot;
                                            myCardPlases[item.slot].AnimateDmgAdtnl(game.lastHitInfo);
                                        }

                                        myCardPlases[item.slot].ThisCard = item;
                                        myCardPlases[item.slot].Enabled  = item.Enabled;
                                    }
                                    else
                                    {
                                        enemyCardPlases[item.slot].ThisCard = item;
                                    }
                                }));
                            }

                            Dispatcher.Invoke(new Action(delegate
                            {
                                if (game.currUsr == App.NickName)
                                {
                                    menuTop.btnText = "Ваш\nХод";

                                    boardGrid.IsEnabled = true;

                                    foreach (var item in myCardPlases.Values)
                                    {
                                        if (item.ContainsCard && item.ThisCard.Enabled)
                                        {
                                            item.Enabled = true;
                                        }
                                    }
                                }
                                else
                                {
                                    menuTop.btnText = "Ход\nсоперника";

                                    /* if (!known)
                                     * {
                                     *   lasthitCard = -1;
                                     *   known = true;
                                     * }*/

                                    boardGrid.IsEnabled = false;

                                    foreach (var item in myCardPlases.Values)
                                    {
                                        item.Enabled = false;
                                    }
                                }
                            }));
                        }
                        else if (game.gameState == 4)
                        {
                            foreach (var item in game.firstGamerCards)
                            {
                                Dispatcher.Invoke(new Action(delegate
                                {
                                    if (game.fGamer.nick == App.NickName)
                                    {
                                        if (myCardPlases[item.slot].ThisCard != null && item.IsAttacked &&
                                            !myCardPlases[item.slot]
                                            .ThisCard.IsAttacked)
                                        {
                                            enemyCardPlases[game.lastHitInfo.slot].AnimateTurn(true);
                                            lasthitCard = game.lastHitInfo.slot;
                                            myCardPlases[item.slot].AnimateDmgAdtnl(game.lastHitInfo);
                                        }

                                        myCardPlases[item.slot].ThisCard = item;
                                        myCardPlases[item.slot].Enabled  = item.Enabled;
                                    }
                                    else
                                    {
                                        enemyCardPlases[item.slot].ThisCard = item;
                                    }
                                }));
                            }

                            foreach (var item in game.twoGamerCards)
                            {
                                Dispatcher.Invoke(new Action(delegate
                                {
                                    if (game.fGamer.nick != App.NickName)
                                    {
                                        if (myCardPlases[item.slot].ThisCard != null && item.IsAttacked &&
                                            !myCardPlases[item.slot]
                                            .ThisCard.IsAttacked)
                                        {
                                            enemyCardPlases[game.lastHitInfo.slot].AnimateTurn(true);
                                            lasthitCard = game.lastHitInfo.slot;
                                            myCardPlases[item.slot].AnimateDmgAdtnl(game.lastHitInfo);
                                        }

                                        myCardPlases[item.slot].ThisCard = item;
                                        myCardPlases[item.slot].Enabled  = item.Enabled;
                                    }
                                    else
                                    {
                                        enemyCardPlases[item.slot].ThisCard = item;
                                    }
                                }));
                            }

                            Dispatcher.Invoke(new Action(delegate
                            {
                                App.InGame = false;

                                GameResultWindow grw = null;

                                if (game.currUsr == App.NickName)
                                {
                                    grw = new GameResultWindow("Победа!", game.WinGamerReward.NewLevel,
                                                               game.WinGamerReward.Exp,
                                                               game.WinGamerReward.Score, game.WinGamerReward.NewCard);
                                }
                                else
                                {
                                    grw = new GameResultWindow("Поражение!", game.LooseGamerReward.NewLevel,
                                                               game.LooseGamerReward.Exp,
                                                               game.LooseGamerReward.Score, game.LooseGamerReward.NewCard);
                                }

                                App.WindowList.Add(grw.Name, grw);

                                grw.ShowDialog();

                                (App.WindowList["LobbyWnd"] as LobbyScreen).OnGameEnd();

                                //Hide();
                                //Close();
                            }));

                            Thread.Sleep(200);

                            Dispatcher.Invoke(new Action(delegate { App.WindowList["LobbyWnd"].Show(); }));

                            Thread.Sleep(1000);

                            Dispatcher.Invoke(new Action(delegate { Hide(); }));

                            return;
                        }
                        else if (game.gameState == 5)
                        {
                            Dispatcher.Invoke(new Action(delegate
                            {
                                App.InGame = false;
                                var grw    = new GameResultWindow("Победа!", game.WinGamerReward.NewLevel,
                                                                  game.WinGamerReward.Exp,
                                                                  game.WinGamerReward.Score, game.WinGamerReward.NewCard);

                                App.WindowList.Add(grw.Name, grw);

                                grw.ShowDialog();

                                (App.WindowList["LobbyWnd"] as LobbyScreen).OnGameEnd();

                                //Hide();
                                //Close();
                            }));

                            Thread.Sleep(200);

                            Dispatcher.Invoke(new Action(delegate { App.WindowList["LobbyWnd"].Show(); }));

                            Thread.Sleep(1000);

                            Dispatcher.Invoke(new Action(delegate { Hide(); }));

                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
            catch (Exception exc)
            {
                Dispatcher.Invoke(new Action(delegate
                {
                    MessageBox.Show(exc.Message, "Критическая ошибка!");
                    App.isConnected = false;
                    App.dumpException(exc);
                    Application.Current.Shutdown();
                }));
            }
        }