예제 #1
0
        public GameManager(PlanesGame game)
        {
            m_game = game;

            m_client = new GameServiceClient();
            m_client.Open();
        }
예제 #2
0
 public static async Task DisplayAlliesAsync(GameServiceClient client, IReadOnlyList <int> allyIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var ally in await GetAlliesAsync(client, allyIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{ally}");
     }
 }
예제 #3
0
 public Models.Game GetByTableId(int tableId)
 {
     using (GameServiceClient proxy = new GameServiceClient()) {
         GameServiceReference.Game game = proxy.GetByTableId(tableId);
         return(GameModelConverter.ConvertFromServiceGameToClientGame(game));
     }
 }
예제 #4
0
        public RPSForm(int chatId, int playerId)
        {
            #region Initialize
            InitializeComponent();
            gameService = new GameServiceClient(new InstanceContext(this));
            //Formating player2 label
            player2_lbl.Text      = "PLAYER2 NOT CONNECTED!";
            player2_lbl.ForeColor = Color.Red;
            //Making the button unclicable
            selectChoice_btn.Enabled = false;

            //diselecting any choice
            choice                   = -1;
            prevChoice               = -1;
            rockChoice_rb.Checked    = false;
            paperChoice_rb.Checked   = false;
            scissorChoice_rb.Checked = false;

            //initialise timer
            timer = new System.Timers.Timer
            {
                Interval            = 1000,  //make timer perform action after 1 second
                AutoReset           = false, //make sure timer wont reset
                SynchronizingObject = (this) //syncronize timer thread with RPSForm thread, in order to allow timer thread to modify RPSForm elements
            };
            #endregion

            gameId        = chatId; //since chatId is unique, gameId will be unique
            this.playerId = playerId;

            gameService.JoinGame(gameId, playerId); //player joins game
        }
예제 #5
0
 public void CreateGAme(Models.Game game)
 {
     using (GameServiceClient proxy = new GameServiceClient()) {
         GameServiceReference.Game serviceGame = GameModelConverter.ConvertFromClientGameToServiceGame(game);
         proxy.CreateGame(serviceGame);
     }
 }
예제 #6
0
        /// <summary>
        /// Débute la game.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var svcClient = new GameServiceClient())
                {
                    GameView gView = new GameView();

                    UserSessionSingleton.Instance.CurrentGameToken =
                        svcClient.CreateGame(
                            UserSessionSingleton.Instance.UserToken.Value,
                            (Guid)tabCurrentRoom.DataContext);

                    gView.Closed      += ShowLobby;
                    gView.GameToken    = UserSessionSingleton.Instance.CurrentGameToken.Value;
                    gView.IsGameMaster = true;
                    gView.Show();

                    _changedRoom = false;
                    _joinedGame  = true;
                    Hide();
                }
            }
            catch
            {
                MessageBox.Show("Un problème s'est produit pour débuter la partie :^(");
            }
        }
예제 #7
0
 public static async Task DisplayNeutralsAsync(GameServiceClient client, IReadOnlyList <int> neutralIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var neutral in await GetNeutralsAsync(client, neutralIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{neutral}");
     }
 }
예제 #8
0
        public static async Task CreateHenchmanAsync(GameServiceClient client)
        {
            var henchman = new Henchman();

            henchman.Name          = ConsoleUtility.GetUserInput("Henchman Name: ");
            henchman.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            henchman.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Henchman: '{henchman.Name}', in gamePackage '{henchman.GamePackageId}' with abilities [{henchman.AbilityIds.Select(x => x.ToString()).Join(", ")}]"))
            {
                await CreateHenchmanAsync(client);

                return;
            }

            var createRequest = new CreateHenchmenRequest();

            createRequest.Henchmen.Add(henchman);
            var createReply = await client.CreateHenchmenAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create henchman: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Henchman '{createReply.Henchmen.First().Name}' was created with Id '{createReply.Henchmen.First().Id}'");
            }
        }
예제 #9
0
        public async void ConnectToClient(string hostName, int port, string playerName,  Color color)
        {
            var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
            binding.ReceiveTimeout = TimeSpan.FromSeconds(30);
            binding.SendTimeout = TimeSpan.FromSeconds(30);

            //TODO: Wire up the callbackHandler...

            _client = new GameServiceClient(
                new InstanceContext(_callbackHandler), 
                binding,
                new EndpointAddress(String.Format("http://{0}:{1}/GameService", hostName, port)));
            _client.Open();

            //Just calling join here locks up...
            PlayerId = await _client.JoinAsync(new Player
            {
                Name = playerName,
                Color = new Service.Contracts.Color 
                {
                    A = color.A,
                    R = color.R,
                    G = color.G,
                    B = color.B
                }
            });

            //TODO: Remove this once the view goes somewhere else...
            MessageBox.Show(String.Format("Player: {0} joined with id: {1}", playerName, PlayerId));
        }
예제 #10
0
 public static List <OneWayReference.Game> GetAvaivableGames()
 {
     using (var proxy = new GameServiceClient())
     {
         return(proxy.GetAvaivableGames().ToList());
     }
 }
예제 #11
0
 public static User Login(string login, string password)
 {
     using (var proxy = new GameServiceClient())
     {
         return(proxy.Login(login, password));
     }
 }
예제 #12
0
        private static IEnumerable <CardRequirement> GetCardRequirements(GameServiceClient client, XElement element, int gamePackageId)
        {
            foreach (var attribute in element.Attributes())
            {
                var cardRequirements = attribute.Name.LocalName switch
                {
                    "Name" => null,
                    "Area" => null,
                    "Abilities" => null,
                    "HasEpicSide" => null,
                    "SchemeTwistCount" => null,
                    "RequiredTeam" => null,
                    "RequiresSomeOf" => null,
                    "RequiresAlliesNamed" => attribute.Value.Split('|').Select(x => GetCardSetRequirement(client, x, gamePackageId, CardSetType.CardSetAlly)),
                    "RequiresAdversariesNamed" => attribute.Value.Split('|').Select(x => GetCardSetRequirement(client, x, gamePackageId, CardSetType.CardSetAdversary)),
                    "RequiresNeutralsNamed" => attribute.Value.Split('|').Select(x => GetCardSetRequirement(client, x, gamePackageId, CardSetType.CardSetNeutral)),
                    "RequiresHenchmenNamed" => attribute.Value.Split('|').Select(x => GetCardSetRequirement(client, x, gamePackageId, CardSetType.CardSetHenchman)),
                    "RequiresHenchmenWithName" => GetCardGroupRequirement(attribute.Value, CardSetType.CardSetHenchman),
                    "ExtraHeroGroups" => GetAdditionalCardSetsRequirement(client, attribute.Value, CardSetType.CardSetAlly),
                    "ExtraVillainGroups" => GetAdditionalCardSetsRequirement(client, attribute.Value, CardSetType.CardSetAdversary),
                    "ExtraHenchmenGroups" => GetAdditionalCardSetsRequirement(client, attribute.Value, CardSetType.CardSetHenchman),
                    "ExtraMastermindGroups" => GetAdditionalCardSetsRequirement(client, attribute.Value, CardSetType.CardSetMastermind),
                    "ExtraBystanders" => GetAdditionalCardSetsRequirement(client, attribute.Value, CardSetType.CardSetBystander),
                    _ => throw new Exception($"Don't know how to handle {attribute.Name}")
                };

                foreach (var cardRequirement in cardRequirements ?? new CardRequirement[] { })
                {
                    yield return(cardRequirement);
                }
            }
        }
예제 #13
0
        public static async Task CreateAdversaryAsync(GameServiceClient client)
        {
            var adversary = new Adversary();

            adversary.Name          = ConsoleUtility.GetUserInput("Adversary Name: ");
            adversary.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            adversary.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Adversary: '{adversary.Name}', in gamePackage '{adversary.GamePackageId}' with abilities [{adversary.AbilityIds.Select(x => x.ToString()).Join(", ")}]"))
            {
                await CreateAdversaryAsync(client);

                return;
            }

            var createRequest = new CreateAdversariesRequest();

            createRequest.Adversaries.Add(adversary);
            var createReply = await client.CreateAdversariesAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create adversary: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Adversary '{createReply.Adversaries.First().Name}' was created with Id '{createReply.Adversaries.First().Id}'");
            }
        }
예제 #14
0
        private static IEnumerable <SchemeTwistRequirement> GetTwistRequirements(GameServiceClient client, XElement schemeElement)
        {
            foreach (var attribute in schemeElement.Attributes())
            {
                var twistRequirements = attribute.Name.LocalName switch
                {
                    "SchemeTwistCount" => GetSchemeTwistCount(attribute.Value),
                    "Name" => null,
                    "Area" => null,
                    "Abilities" => null,
                    "HasEpicSide" => null,
                    "RequiredTeam" => null,
                    "RequiresSomeOf" => null,
                    "RequiresAlliesNamed" => null,
                    "RequiresAdversariesNamed" => null,
                    "RequiresNeutralsNamed" => null,
                    "RequiresHenchmenNamed" => null,
                    "RequiresHenchmenWithName" => null,
                    "ExtraHeroGroups" => null,
                    "ExtraVillainGroups" => null,
                    "ExtraHenchmenGroups" => null,
                    "ExtraMastermindGroups" => null,
                    "ExtraBystanders" => null,
                    _ => throw new Exception($"Don't know how to handle {attribute.Name}")
                };

                foreach (var twistRequirement in twistRequirements ?? new SchemeTwistRequirement[] { })
                {
                    yield return(twistRequirement);
                }
            }
        }
예제 #15
0
 public static async Task DisplayHenchmenAsync(GameServiceClient client, IReadOnlyList <int> henchmanIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var henchman in await GetHenchmenAsync(client, henchmanIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{henchman}");
     }
 }
예제 #16
0
 public static async Task DisplaySchemesAsync(GameServiceClient client, IReadOnlyList <int> schemeIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var scheme in await GetSchemesAsync(client, schemeIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{scheme}");
     }
 }
예제 #17
0
        public static async Task CreateMastermindAsync(GameServiceClient client)
        {
            var mastermind = new Mastermind();

            mastermind.Name          = ConsoleUtility.GetUserInput("Mastermind Name: ");
            mastermind.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            mastermind.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));
            mastermind.HasEpicSide = ConsoleUtility.GetUserInputBool("Has Epic side?");
            mastermind.CardRequirements.AddRange(await CardRequirementUtility.GetCardRequirements(client, mastermind.GamePackageId, true));

            if (!ConsoleUtility.ShouldContinue($"Creating Mastermind: {mastermind}"))
            {
                await CreateMastermindAsync(client);

                return;
            }

            var createRequest = new CreateMastermindsRequest();

            createRequest.Masterminds.Add(mastermind);
            var createReply = await client.CreateMastermindsAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create mastermind: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Mastermind '{createReply.Masterminds.First().Name}' was created with Id '{createReply.Masterminds.First().Id}'");
            }
        }
예제 #18
0
        public static async Task DisplayGamePackageAsync(GameServiceClient client, IReadOnlyList <int> packageIds, string name)
        {
            var packagesRequest = new GetGamePackagesRequest();

            if (packageIds != null && packageIds.Count() != 0)
            {
                packagesRequest.GamePackageIds.AddRange(packageIds);
            }
            else if (!string.IsNullOrWhiteSpace(name))
            {
                packagesRequest.Name = name;
            }
            else
            {
                throw new ArgumentException("Either 'packageId' or 'name' must be non-null");
            }

            packagesRequest.Fields.AddRange(new[] { GamePackageField.Id, GamePackageField.Name, GamePackageField.PackageType, GamePackageField.BaseMap });
            var packagesReply = await client.GetGamePackagesAsync(packagesRequest);

            if (packagesReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine(packagesReply.Status.Message);
            }

            foreach (var gamePackage in packagesReply.Packages)
            {
                ConsoleUtility.WriteLine(gamePackage.ToString());
            }
        }
예제 #19
0
 public void Abort()
 {
     _client.DeliverGameMessageReceived -= ClientDeliverGameMessageReceived;
     _client.UpdateGameListReceived     -= ClientUpdateGameListReceived;
     _client.InnerChannel.Abort();
     _client = null;
 }
예제 #20
0
 public static async Task DisplayMastermindsAsync(GameServiceClient client, IReadOnlyList <int> mastermindIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var mastermind in await GetMastermindsAsync(client, mastermindIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{mastermind}");
     }
 }
예제 #21
0
        private void ConnectToServer()
        {
            ClientCallback callback = new ClientCallback();

            try
            {
                GameServiceClient client = new GameServiceClient(
                    new InstanceContext(callback));
                username = tbfName.Text.Trim();
                client.ClientConnected(username);

                ChatWindow mainWindow = new ChatWindow();
                mainWindow.Client   = client;
                mainWindow.Callback = callback;
                mainWindow.Username = username;
                mainWindow.Title    = username;
                this.Close();
                mainWindow.Show();
            }
//            catch (FaultException<UserExistsFault> ex)
            catch (FaultException ex)
            {
                MessageBox.Show("this user already connected!",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
//                MessageBox.Show(ex.Detail.Message);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #22
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)//单击登录按钮引发的事件
        {
            if (textBoxUserName.Text == null)
            {
                MessageBox.Show("请输入用户名!");
            }
            else if (passwordbox.Password.ToString() != "123456")
            {
                MessageBox.Show("密码不正确!");
            }
            else
            {
                this.Cursor = Cursors.Wait;
                userName    = textBoxUserName.Text;
                InstanceContext context = new InstanceContext(this);
                client = new GameServiceReference.GameServiceClient(context);

                serviceTextBlock.Text = "服务端地址:" + client.Endpoint.ListenUri.ToString();
                try
                {
                    client.Login(textBoxUserName.Text, passwordbox.Password, id++);
                    ChangeState(btnLogin, false, btnLogout, true);
                    client.sendQuestion(id - 1, 1);
                    this.Id = id - 1;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("与服务端连接失败:" + ex.Message);
                    return;
                }

                this.Cursor = Cursors.Arrow;
            }
        }
예제 #23
0
 public static async Task CreateItemAsync(GameServiceClient client, string[] args)
 {
     if (args.FirstOrDefault() == "t")
     {
         await CreateTeamAsync(client);
     }
     else if (args.FirstOrDefault() == "h")
     {
         await CreateHenchmanAsync(client);
     }
     else if (args.FirstOrDefault() == "n")
     {
         await CreateNeutralAsync(client);
     }
     else if (args.FirstOrDefault() == "al")
     {
         await CreateAllyAsync(client);
     }
     else if (args.FirstOrDefault() == "ad")
     {
         await CreateAdversaryAsync(client);
     }
     else if (args.FirstOrDefault() == "m")
     {
         await MastermindUtility.CreateMastermindAsync(client);
     }
     else if (args.FirstOrDefault() == "s")
     {
         await SchemeUtility.CreateSchemeAsync(client);
     }
     else
     {
         ConsoleUtility.WriteLine("Must supply the type of item you want to create. (t|h|ad|n|al|m|s)");
     }
 }
예제 #24
0
        private static async ValueTask <IReadOnlyList <Ability> > CreateAbilities(GameServiceClient client, IReadOnlyList <GamePackage> packages)
        {
            ConsoleUtility.WriteLine("Creating abilities");

            var existingAbilities = await AbilityUtility.GetAbilitiesAsync(client, null);

            if (existingAbilities.Any())
            {
                return(existingAbilities);
            }

            var doc = XDocument.Load(@"C:\Users\Ryan\SkyDrive\code\LegendaryGameStarter\LegendaryGameModel2\Abilities\Abilities.xml");

            var request = new CreateAbilitiesRequest();

            request.Abilities.AddRange(doc.Root.Elements("Ability").Select(ability =>
            {
                var gamePackage = packages.First(x => x.Name.Equals(ability.Element("Source").Value, StringComparison.OrdinalIgnoreCase));
                return(new Ability {
                    Name = ability.Element("Name").Value, Description = ability.Element("Description").Value, GamePackage = gamePackage
                });
            }));

            var result = await client.CreateAbilitiesAsync(request);

            ConsoleUtility.WriteLine($"Status: {result.Status.Code}: {result.Status.Message}");

            return(result.Abilities);
        }
예제 #25
0
        public static async Task CreateSchemeAsync(GameServiceClient client)
        {
            var scheme = new Scheme();

            scheme.Name          = ConsoleUtility.GetUserInput("Scheme Name: ");
            scheme.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            scheme.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));
            scheme.HasEpicSide = ConsoleUtility.GetUserInputBool("Has Epic side?");
            scheme.CardRequirements.AddRange(await CardRequirementUtility.GetCardRequirements(client, scheme.GamePackageId, true));
            scheme.TwistRequirements.AddRange(TwistRequirementUtility.GetTwistRequirements(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Scheme: {scheme}"))
            {
                await CreateSchemeAsync(client);

                return;
            }

            var createRequest = new CreateSchemesRequest();

            createRequest.Schemes.Add(scheme);
            var createReply = await client.CreateSchemesAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create scheme: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Scheme '{createReply.Schemes.First().Name}' was created with Id '{createReply.Schemes.First().Id}'");
            }
        }
예제 #26
0
        public static async Task CreateNeutralAsync(GameServiceClient client)
        {
            var neutral = new Neutral();

            neutral.Name          = ConsoleUtility.GetUserInput("Neutral Name: ");
            neutral.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            if (!ConsoleUtility.ShouldContinue($"Creating Neutral: '{neutral.Name}', in gamePackage '{neutral.GamePackageId}'"))
            {
                await CreateNeutralAsync(client);

                return;
            }

            var createRequest = new CreateNeutralsRequest();

            createRequest.Neutrals.Add(neutral);
            var createReply = await client.CreateNeutralsAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create neutral: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Neutral '{createReply.Neutrals.First().Name}' was created with Id '{createReply.Neutrals.First().Id}'");
            }
        }
예제 #27
0
        private async void ServiceCreate_Click(object sender, RoutedEventArgs e)
        {
            ClearData();
            var gameNo = gameNoCBox.SelectedValue as string;

            gameSvc = new GameServiceClient(subKey.Text, gameNo);
            FillActivityAndGameInfo();
        }
 public Client(MultiplayerGame game)
 {
     GameContext = game;
     callBack    = new ClientCallBack(game);
     context     = new InstanceContext(callBack);
     client      = new GameServiceClient(context);
     client.Open();
 }
예제 #29
0
        internal static IEnumerable <SchemeTwistRequirement> GetTwistRequirements(GameServiceClient client)
        {
            List <SchemeTwistRequirement> twistRequirements = new List <SchemeTwistRequirement>();

            twistRequirements.AddRange(GetSingleTwistRequirement(client));

            return(twistRequirements);
        }
예제 #30
0
 protected override void OnStop()
 {
     Log.Info("OnStop Called");
     GameServiceClient.GetContext().Stop();
     SasManager.GetContext().Stop();
     this.FireOnServiceStop();
     Log.Info("OnStop Completed");
 }
예제 #31
0
 public void Start()
 {
     Log.Info("Starting");
     this.OnStart(null);
     GameServiceClient.GetContext().Start();
     SasManager.GetContext().Start();
     Log.Info("Started");
 }
예제 #32
0
 public void BtnLogin_OnClick(object sender, RoutedEventArgs e)
 {
     txtEmailAddress.Text = "*****@*****.**";
     txtPassword.Password = "******";
     if (!string.IsNullOrEmpty(txtEmailAddress.Text) && !string.IsNullOrEmpty(txtPassword.Password))
     {
         var client = new GameServiceClient();
         client.LoginCompleted += client_LoginCompleted;
         client.LoginAsync(txtEmailAddress.Text, txtPassword.Password);
     }
 }
예제 #33
0
        static Program()
        {
            var profile = new PlayerProfile();
            var stats = new PlayerStats();
            var gameList = new List<GameInformation>();
            var gameService = new GameServiceClient();
            var infoService = new InformationServiceClient();
            var state = new BasicObservable<MatchState>(new MatchState());
            infoController = new InformationController(infoService, profile, stats, gameList);
            gameController = new GameController(gameService, state);

            infoController.GetGameList();
        }
예제 #34
0
        public void GetCityCoordinates(string cityCoordinate)
        {
            if (!string.IsNullOrEmpty(cityCoordinate))
            {
                if (AppCache.ApplicationViewModel.UserProfile.City == null)
                {
                    AppCache.ApplicationViewModel.UserProfile.City = new City();
                }
                AppCache.ApplicationViewModel.UserProfile.City.Latitude = cityCoordinate.Split(',')[0].Trim().Replace("(", "");
                AppCache.ApplicationViewModel.UserProfile.City.Longitude = cityCoordinate.Split(',')[1].Trim().Replace(")", "");

                var client = new GameServiceClient();

                client.SaveUserProfileCompleted += client_SaveUserProfileCompleted;
                client.SaveUserProfileAsync("", AppCache.ApplicationViewModel.UserProfile);
            }
        }
예제 #35
0
        private void btnStartBuilding_OnClick(object sender, RoutedEventArgs e)
        {
            var building = lbNewBuildings.pnlBuildings.SelectedItem as Building;
            if (building != null)
            {
                BuildingInCity buildingInCity = new BuildingInCity();
                buildingInCity.Status = BuildingStatuses.InQuery;
                buildingInCity.BuildingId = building.Id;
                buildingInCity.Building = building;

                AppCache.ApplicationViewModel.UserProfile.City.BuildingsInCity.Add(buildingInCity);
                AppCache.ApplicationViewModel.UserProfile.City.BuildingInCityIds.Add(building.Id);

                var client = new GameServiceClient();
                client.SaveBuildingInCityCompleted += client_SaveBuildingInCityCompleted;
                client.SaveBuildingInCityAsync("", buildingInCity);

                buildingViewModel.initGetNewBuildings();
                lbNewBuildings.pnlBuildings.ItemsSource = buildingViewModel.GetNewBuildings;
            }
        }
예제 #36
0
        // actual application start point at the moment
        // MOVE IT SOMEWHERE ELSE? maybe make it static?
        public static void Run()
        {
            // create connection to server and callback
            var instanceContext = new InstanceContext(new ClientCallback());
            proxy = new GameServiceClient(instanceContext);

            mainWindow = new MainWindow();
            gameState = new GameView();
            mainWindow.DataContext = gameState;
            gameState.PropertyChanged += mainWindow.gameState_PropertyChanged;
            mainWindow.Show();

            //create login form
            loginWindow = new LoginWindow();
            loginWindow.Show();         
            
            // create and show main window
            
            loginWindow.Focus();
            mainWindow.IsEnabled = false;

        }
예제 #37
0
        /// <summary>
        /// Débute la game.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var svcClient = new GameServiceClient())
                {
                    GameView gView = new GameView();

                    UserSessionSingleton.Instance.CurrentGameToken =
                        svcClient.CreateGame(
                        UserSessionSingleton.Instance.UserToken.Value,
                        (Guid)tabCurrentRoom.DataContext);

                    gView.Closed += ShowLobby;
                    gView.GameToken = UserSessionSingleton.Instance.CurrentGameToken.Value;
                    gView.IsGameMaster = true;
                    gView.Show();

                    _changedRoom = false;
                    _joinedGame = true;
                    Hide();
                }
            }
            catch
            {
                MessageBox.Show("Un problème s'est produit pour débuter la partie :^(");
            }
        }
예제 #38
0
        private void SaveBuildingButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add to the database. trqbva da se proverqva dali dobavq nov ili redaktira zapis ili trie

            Button btnAction = sender as Button;
            if (btnAction != null)
            {
                var b = btnAction.Tag as Building;
                if (b != null)
                {
                    var client = new GameServiceClient();
                    client.SaveBuildingCompleted += client_SaveBuildingCompleted;
                    client.SaveBuildingAsync("", b);
                }
            }

            //DeleteBuildingTextBoxs();
            BuildingSaveCancelStackPanel.Visibility = Visibility.Collapsed;
            btnBuildingAdd.Visibility = Visibility.Visible;
        }
예제 #39
0
 public GameController(GameServiceClient service, BasicObservable<MatchState> state)
 {
     _service = service;
     gameState = state;
 }
        static void Main(string[] args)
        {
            var service = new GameServiceClient();
            int userGuess;
            string userName = null;
            string userInput = null;
            Console.Title = "WCF Callback Console";

            // Get the user name
            while (String.IsNullOrWhiteSpace(userName))
            {
                Console.WriteLine("What is your name?");
                userName = Console.ReadLine();
            }

            Console.Title += String.Format(" - Player {0}", userName);

            // Register as a client and reference our callback client wrapped inside an instance context.
            try
            {
                Console.Write("Connecting to server... ");
                new GameCallbacksClient(new System.ServiceModel.InstanceContext(new CallMe())).RegisterClient(userName);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed!");
                System.Threading.Thread.Sleep(1000);
                throw e;
            }
            Console.WriteLine("Success!");

            // Event Loop
            do
            {
                Console.WriteLine("Q - Quit\nF - Finish this round\nC - Clear the screen\n# - Guess a number");
                userInput = Console.ReadKey().KeyChar.ToString();
                Console.WriteLine();
                try
                {
                    userGuess = int.Parse(userInput);
                }
                catch (FormatException)
                {
                    userGuess = -1;
                }

                if (userGuess >= 0)
                {
                    Console.WriteLine(service.GuessNumber(userName, userGuess));
                } else {
                    switch(userInput.ToLower())
                    {
                        case "f":
                            service.GuessTheNumber();
                            break;
                        case "c":
                            Console.Clear();
                            break;
                        case "q":
                            Console.WriteLine("Goodbye!");
                            System.Threading.Thread.Sleep(1000);
                            break;
                        default:
                            Console.WriteLine("Invalid Input!");
                            break;
                    }
                }
            } while (userInput.ToLower() != "q");
        }