상속: ViewModelBase
예제 #1
0
        private void InitGame()
        {
#if CLIENTLOG
            TextWriterTraceListener twtl = new TextWriterTraceListener(System.IO.Path.Combine(Directory.GetCurrentDirectory(), AppDomain.CurrentDomain.FriendlyName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".txt"));
            twtl.Name = "TextLogger";
            twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

            ConsoleTraceListener ctl = new ConsoleTraceListener(false);
            ctl.TraceOutputOptions = TraceOptions.DateTime;

            Trace.Listeners.Add(twtl);
            Trace.Listeners.Add(ctl);
            Trace.AutoFlush = true;

            Trace.WriteLine("Log starting");
#endif

            _game = new RoleGame(1);
            foreach (var g in GameEngine.Expansions.Values)
            {
                _game.LoadExpansion(g);
            }
#if NETWORKING
            ClientNetworkUiProxy activeClientProxy = null;
            for (int i = 0; i < numberOfHeros; i++)
#else
            for (int i = 0; i < 8; i++)
#endif
            {
                Player player = new Player();
                player.Id = i;
                _game.Players.Add(player);
                if (i == 1)
                {
                    player.IsFemale = true;
                }
                else
                {
                    player.IsMale = true;
                }
            }
#if NETWORKING
            _game.GameClient = NetworkClient;
#else
            _game.GlobalProxy = new GlobalDummyProxy();
#endif
            GameViewModel gameModel = new GameViewModel();
            gameModel.Game = _game;
            gameModel.MainPlayerSeatNumber = MainSeat;
            gameView.DataContext = gameModel;
            _game.NotificationProxy = gameView;
            List<ClientNetworkUiProxy> inactive = new List<ClientNetworkUiProxy>();
            for (int i = 0; i < _game.Players.Count; i++)
            {
                var player = gameModel.PlayerModels[i].Player;                
#if NETWORKING
                var proxy = new ClientNetworkUiProxy(
                            new AsyncUiAdapter(gameModel.PlayerModels[i]), NetworkClient, i == 0);
                proxy.HostPlayer = player;
                proxy.TimeOutSeconds = 15;
                if (i == 0)
                {
                    activeClientProxy = proxy;
                }
                else
                {
                    inactive.Add(proxy);
                }
#else
                var proxy = new AsyncUiAdapter(gameModel.PlayerModels[i]);
#endif
                _game.UiProxies.Add(player, proxy);
            }
#if NETWORKING
            _game.GlobalProxy = new GlobalClientUiProxy(_game, activeClientProxy, inactive);
#endif
        }
예제 #2
0
        private void InitGame()
        {
            if (NetworkClient != null)
            {
                var pkt = NetworkClient.Receive();
                Trace.Assert(pkt is ConnectionResponse);
                if ((pkt as ConnectionResponse).Settings.GameType == GameType.Pk1v1) _game = new Pk1v1Game();
                if ((pkt as ConnectionResponse).Settings.GameType == GameType.RoleGame) _game = new RoleGame();
                
                if (pkt is ConnectionResponse)
                {
                    _game.Settings = ((ConnectionResponse)pkt).Settings;
                    NetworkClient.SelfId = ((ConnectionResponse)pkt).SelfId;
                }
                else
                {
                    return;
                }
            }
            if (hasSeed != null)
            {
                _game.RandomGenerator = new Random((int)hasSeed);
                _game.IsPanorama = true;
            }
            Game.CurrentGameOverride = _game;
            if (_networkClient == null)
            {
                _game.Settings = new GameSettings();
                _game.Settings.Accounts = new List<Account>();
                _game.Settings.NumberOfDefectors = 1;
                _game.Settings.NumHeroPicks = 3;
                _game.Settings.DualHeroMode = false;
                _game.Settings.TotalPlayers = 8;
                _game.Settings.TimeOutSeconds = 15;
                for (int i = 0; i < 8; i++)
                {
                    _game.Settings.Accounts.Add(new Account() { UserName = "******" + i });
                }

            }

            ClientNetworkProxy activeClientProxy = null;
            if (NetworkClient != null)
            {
                for (int i = 0; i < _game.Settings.TotalPlayers; i++)
                {
                    Player player = new Player();
                    player.Id = i;
                    _game.Players.Add(player);
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    Player player = new Player();
                    player.Id = i;
                    _game.Players.Add(player);
                }
            }

            if (NetworkClient != null)
            {
                _game.GameClient = NetworkClient;
            }
            else
            {
                _game.GlobalProxy = new GlobalDummyProxy();
            }
            GameViewModel gameModel = new GameViewModel();
            gameModel.Game = _game;
            if (NetworkClient != null)
            {
                gameModel.MainPlayerSeatNumber = NetworkClient.SelfId >= _game.Players.Count ? 0 : NetworkClient.SelfId;
            }
            else
            {
                gameModel.MainPlayerSeatNumber = 0;
            }

            _game.NotificationProxy = gameView;
            List<ClientNetworkProxy> inactive = new List<ClientNetworkProxy>();
            for (int i = 0; i < _game.Players.Count; i++)
            {
                var player = gameModel.PlayerModels[i].Player;
                if (NetworkClient != null)
                {
                    var proxy = new ClientNetworkProxy(
                                new AsyncProxyAdapter(gameModel.PlayerModels[i]), NetworkClient);
                    proxy.HostPlayer = player;
                    proxy.TimeOutSeconds = _game.Settings.TimeOutSeconds;
                    if (i == 0)
                    {
                        activeClientProxy = proxy;
                    }
                    else
                    {
                        inactive.Add(proxy);
                    }
                    _game.UiProxies.Add(player, proxy);
                }
                else
                {
                    var proxy = new AsyncProxyAdapter(gameModel.PlayerModels[i]);
                    _game.UiProxies.Add(player, proxy);
                }
            }
            if (NetworkClient != null)
            {
                _game.ActiveClientProxy = activeClientProxy;
                _game.GlobalProxy = new GlobalClientProxy(_game, activeClientProxy, inactive);
                _game.UpdateUiAttachStatus();
            }
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                gameView.DataContext = gameModel;
                if (BackwardNavigationService != null && !ViewModelBase.IsDetached)
                {
                    BackwardNavigationService.Navigate(this);
                    BackwardNavigationService = null;
                }
            });
            _game.Run();
        }
예제 #3
0
 public PlayerViewModel(Player player, GameViewModel game, bool isPlayable)
     : this()
 {
     Player = player;
     GameModel = game;
     IsPlayable = isPlayable;
 }
예제 #4
0
 public PlayerViewModel(Player player, GameViewModel game)
     : this()
 {
     Player = player;
     GameModel = game;
 }
예제 #5
0
        private void InitGame()
        {
#if DEBUG
            TextWriterTraceListener twtl = new TextWriterTraceListener(System.IO.Path.Combine(Directory.GetCurrentDirectory(), AppDomain.CurrentDomain.FriendlyName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".txt"));
            twtl.Name = "TextLogger";
            twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

            ConsoleTraceListener ctl = new ConsoleTraceListener(false);
            ctl.TraceOutputOptions = TraceOptions.DateTime;

            Trace.Listeners.Add(twtl);
            Trace.Listeners.Add(ctl);
            Trace.AutoFlush = true;

            Trace.WriteLine("Log starting");
#endif
            _game = new RoleGame();
            Game.CurrentGameOverride = _game;
            _game.Settings = NetworkClient.Receive() as GameSettings;
            Trace.Assert(_game.Settings != null);
            NetworkClient.SelfId = (int)NetworkClient.Receive();
            foreach (var g in GameEngine.Expansions.Values)
            {
                _game.LoadExpansion(g);
            }
#if NETWORKING
            ClientNetworkUiProxy activeClientProxy = null;
            for (int i = 0; i < _game.Settings.TotalPlayers; i++)
#else
            for (int i = 0; i < 8; i++)
#endif
            {
                Player player = new Player();
                player.Id = i;
                _game.Players.Add(player);
            }
#if NETWORKING
            _game.GameClient = NetworkClient;
#else
            _game.GlobalProxy = new GlobalDummyProxy();
#endif
            GameViewModel gameModel = new GameViewModel();
            gameModel.Game = _game;
            gameModel.MainPlayerSeatNumber = NetworkClient.SelfId >= _game.Players.Count ? 0 : NetworkClient.SelfId;
            
            _game.NotificationProxy = gameView;
            List<ClientNetworkUiProxy> inactive = new List<ClientNetworkUiProxy>();
            for (int i = 0; i < _game.Players.Count; i++)
            {
                var player = gameModel.PlayerModels[i].Player;                
#if NETWORKING
                var proxy = new ClientNetworkUiProxy(
                            new AsyncUiAdapter(gameModel.PlayerModels[i]), NetworkClient, i == 0);
                proxy.HostPlayer = player;
                proxy.TimeOutSeconds = _game.Settings.TimeOutSeconds;
                if (i == 0)
                {
                    activeClientProxy = proxy;
                }
                else
                {
                    inactive.Add(proxy);
                }
#else
                var proxy = new AsyncUiAdapter(gameModel.PlayerModels[i]);
#endif
                _game.UiProxies.Add(player, proxy);
            }            
#if NETWORKING
            _game.GlobalProxy = new GlobalClientUiProxy(_game, activeClientProxy, inactive);
            _game.IsUiDetached = _game.IsUiDetached;
#endif
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {                
                gameView.DataContext = gameModel;
                if (BackwardNavigationService != null && !ViewModelBase.IsDetached)
                {
                    BackwardNavigationService.Navigate(this);
                    BackwardNavigationService = null;
                }
            });
            _game.Run();            
        }
예제 #6
0
        private void InitGame()
        {
            if (NetworkClient != null)
            {
                var pkt = NetworkClient.Receive();
                Trace.Assert(pkt is ConnectionResponse);
                if ((pkt as ConnectionResponse).Settings.GameType == GameType.Pk1v1)
                {
                    _game = new Pk1v1Game();
                }
                if ((pkt as ConnectionResponse).Settings.GameType == GameType.RoleGame)
                {
                    _game = new RoleGame();
                }

                if (pkt is ConnectionResponse)
                {
                    _game.Settings       = ((ConnectionResponse)pkt).Settings;
                    NetworkClient.SelfId = ((ConnectionResponse)pkt).SelfId;
                }
                else
                {
                    return;
                }
            }
            if (hasSeed != null)
            {
                _game.RandomGenerator = new Random((int)hasSeed);
                _game.IsPanorama      = true;
            }
            Game.CurrentGameOverride = _game;
            if (_networkClient == null)
            {
                _game.Settings                   = new GameSettings();
                _game.Settings.Accounts          = new List <Account>();
                _game.Settings.NumberOfDefectors = 1;
                _game.Settings.NumHeroPicks      = 3;
                _game.Settings.DualHeroMode      = false;
                _game.Settings.TotalPlayers      = 8;
                _game.Settings.TimeOutSeconds    = 15;
                for (int i = 0; i < 8; i++)
                {
                    _game.Settings.Accounts.Add(new Account()
                    {
                        UserName = "******" + i
                    });
                }
            }

            ClientNetworkProxy activeClientProxy = null;

            if (NetworkClient != null)
            {
                for (int i = 0; i < _game.Settings.TotalPlayers; i++)
                {
                    Player player = new Player();
                    player.Id = i;
                    _game.Players.Add(player);
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    Player player = new Player();
                    player.Id = i;
                    _game.Players.Add(player);
                }
            }

            if (NetworkClient != null)
            {
                _game.GameClient = NetworkClient;
            }
            else
            {
                _game.GlobalProxy = new GlobalDummyProxy();
            }
            GameViewModel gameModel = new GameViewModel();

            gameModel.Game = _game;
            if (NetworkClient != null)
            {
                gameModel.MainPlayerSeatNumber = NetworkClient.SelfId >= _game.Players.Count ? 0 : NetworkClient.SelfId;
            }
            else
            {
                gameModel.MainPlayerSeatNumber = 0;
            }

            _game.NotificationProxy = gameView;
            List <ClientNetworkProxy> inactive = new List <ClientNetworkProxy>();

            for (int i = 0; i < _game.Players.Count; i++)
            {
                var player = gameModel.PlayerModels[i].Player;
                if (NetworkClient != null)
                {
                    var proxy = new ClientNetworkProxy(
                        new AsyncProxyAdapter(gameModel.PlayerModels[i]), NetworkClient);
                    proxy.HostPlayer     = player;
                    proxy.TimeOutSeconds = _game.Settings.TimeOutSeconds;
                    if (i == 0)
                    {
                        activeClientProxy = proxy;
                    }
                    else
                    {
                        inactive.Add(proxy);
                    }
                    _game.UiProxies.Add(player, proxy);
                }
                else
                {
                    var proxy = new AsyncProxyAdapter(gameModel.PlayerModels[i]);
                    _game.UiProxies.Add(player, proxy);
                }
            }
            if (NetworkClient != null)
            {
                _game.ActiveClientProxy = activeClientProxy;
                _game.GlobalProxy       = new GlobalClientProxy(_game, activeClientProxy, inactive);
                _game.UpdateUiAttachStatus();
            }
            Application.Current.Dispatcher.Invoke((ThreadStart) delegate()
            {
                gameView.DataContext = gameModel;
                if (BackwardNavigationService != null && !ViewModelBase.IsDetached)
                {
                    BackwardNavigationService.Navigate(this);
                    BackwardNavigationService = null;
                }
            });
            _game.Run();
        }