Beispiel #1
0
 async Task InitializeGameAsync()
 {
     if (_gameVM == null)
     {
         _gameVM = await _gameService.GetByIdAsync(new Guid("d66945ca-e9ef-4b5b-8084-35ea568d937c"));
     }
 }
Beispiel #2
0
        public ActionResult AddGame(int sessionId)
        {
            using (var context = new GameContext())
            {
                var session = context.Sessions.SingleOrDefault(s => s.Id == sessionId);

                if (session == null)
                {
                    return(HttpNotFound());
                }

                var model = new GameVM
                {
                    Id            = 0,
                    Name          = "",
                    TeamSize      = 1,
                    TeamAmount    = 0,
                    HasTournament = false,
                    SessionName   = session.Name,
                    SessionId     = session.Id
                };

                return(View(model));
            }
        }
Beispiel #3
0
        public void JoinGame(int gameID, int userProfileID)
        {
            GameVM join = Game.GetGameByID(gameID);

            if (join.PlayerTurn == null)
            {
                join.PlayerTurn = userProfileID;
            }
            if (join.PlayerOne == null)
            {
                join.PlayerOne = userProfileID;
                Game.UpdateGame(join);
            }
            else if (join.PlayerTwo == null)
            {
                join.PlayerTwo = userProfileID;
                Game.UpdateGame(join);
            }
            else if (join.PlayerThree == null)
            {
                join.PlayerThree = userProfileID;
                Game.UpdateGame(join);
            }
            else if (join.PlayerFour == null)
            {
                join.PlayerFour = userProfileID;
                Game.UpdateGame(join);
            }
            else
            {
                join.PlayerFive = userProfileID;
                Game.UpdateGame(join);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the MainWindow view
 /// </summary>
 public MainWindow(GameVM game)
 {
     _gameVM     = game;
     DataContext = _gameVM;
     XamlReader.Load(this);
     _gameVM.PropertyChanged += _gameVM_PropertyChanged;
 }
Beispiel #5
0
        public void WinLoss(PlayGameVM playGame, int userProfileID)
        {
            foreach (var player in playGame.Players)
            {
                if (player != null)
                {
                    if (userProfileID == player.UserProfileID)
                    {
                        player.Wins         += 1;
                        player.OverAllScore += playGame.Score;
                        UserProfile.UpdateUserProfile(player);
                    }
                    else
                    {
                        player.Losses += 1;
                        UserProfile.UpdateUserProfile(player);
                    }
                }
            }
            GameVM game = Game.GetGameByID(playGame.GameID);

            game.Score      = 0;
            game.LastLetter = GetLetter();
            game.PlayerTurn = NextTurnLeave(game, userProfileID);
            Game.UpdateGame(game);
            WordBank.DeleteWordBank(game.GameID);
        }
Beispiel #6
0
        public ActionResult Index(int id = 0)
        {
            var  name        = User.Identity.Name;
            Room currentRoom = _roomsManager.GetRoomById(id);

            if (currentRoom == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            currentRoom.MarkUserAsActive(new User()
            {
                Name = name
            });
            var currentGame = currentRoom.Game;

            if (name == currentRoom.Owner.Name)
            {
                _roomsManager.AddUserToRoom(new User()
                {
                    Name = name
                }, id);
            }
            lock (currentGame)
            {
                GameVM vm = GameVM.From(currentGame, currentRoom.Owner.Name);
                if (currentGame.CurrentPlayer != null)
                {
                    vm.IsPlayerTurn = currentGame.CurrentPlayer.Name == name;
                }
                _roomsManager.SaveChanges(currentGame);
                return(View(vm));
            }
        }
Beispiel #7
0
        public void TestNextQuestion()
        {
            // Arrange
            _questions = new List <Question>();
            _questions.Add(new Question()
            {
                Id = 1, Description = "TestQuestionOne"
            });
            _questions.Add(new Question()
            {
                Id = 2, Description = "TestQuestionTwo"
            });

            _quiz = new Quiz()
            {
                Name = "TestQuiz", Questions = _questions
            };
            _gameVM = new GameVM(_quiz);

            // Act
            var firstId          = _gameVM.CurrentQuestion.Id;
            var firstId_expected = 1;

            _gameVM.NextQuestion();

            var secondId          = _gameVM.CurrentQuestion.Id;
            var secondId_expected = 2;

            // Assert
            Assert.AreEqual(firstId, firstId_expected);
            Assert.AreEqual(secondId, secondId_expected);
        }
Beispiel #8
0
        public MainWindow()
        {
            InitializeComponent();

            myGame           = new GameVM();
            this.DataContext = myGame;
        }
Beispiel #9
0
        public bool UpdateGame(GameVM vm)
        {
            using (PlayContext context = new PlayContext())
            {
                try
                {
                    Game     game = context.Games.Single(x => x.ID == vm.Game.ID);
                    Location loc  = new Entities.Location();

                    game.Name        = vm.Game.Name;
                    game.Type        = vm.Game.Type;
                    game.Description = vm.Game.Description;
                    game.Start       = vm.Game.Start;
                    game.End         = vm.Game.End;
                    game.Modified    = DateTime.Now;

                    loc.Name        = vm.Game.Location.Name;
                    loc.Coordinates = CreatePoint(vm.Latitude, vm.Longitude);

                    game.Location = loc;

                    context.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            string cmd = GetCommandFromMenu();

            // if user did not start or join a game
            if (cmd == null)
            {
                return;
            }

            //MessageBox.Show("Command to send " + cmd);

            // then we have a command to send.
            // create async communicator. send the command, get response for join or start.
            // if unsuccessfull, prompt the user with a message, and return
            // if successfull, unlink the event of asyncComm, send the communicator to
            // the GameModel, and show it.

            // successfully created a game. pass the handle to the GameModel and start.
            try
            {
                using (GameModel gmod = new GameModel(cmd))
                    using (GameVM gvm = new GameVM(gmod))
                    {
                        GameView gv = new GameView(gvm);
                        gv.ShowDialog();
                    }
            }
            catch (GameNotStartedException e)
            {
                MessageBox.Show(e.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #11
0
        public ActionResult Join([Bind(Include = "GameID")] RefreshDTO dto)
        {
            var  name        = User.Identity.Name;
            int  id          = dto.GameID;
            Room currentRoom = _roomsManager.GetRoomById(id);

            if (currentRoom == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            currentRoom.MarkUserAsActive(new User()
            {
                Name = name
            });
            var currentGame = currentRoom.Game;

            lock (currentGame)
            {
                GameVM vm = GameVM.From(currentGame, currentRoom.Owner.Name);
                _roomsManager.AddUserToRoom(new User()
                {
                    Name = name
                }, id);
                currentRoom.TryStartGame();
                return(Refresh(dto));
            }
        }
Beispiel #12
0
        public GameV()
        {
            int num  = 3;
            int sNum = 2;
            int rNum = 3;

            gameVM = new GameVM(num, rNum, sNum);
            InitializeComponent();
            DataContext           = gameVM;
            myCitadel.DataContext = gameVM.GamePlayerList[sNum - 1];
            switch (num)
            {
            case 2:
                upCitadel.DataContext = gameVM.GamePlayerList[2 - sNum];
                break;

            case 3:
                leftCitadel.DataContext  = gameVM.GamePlayerList[sNum % 3];
                rightCitadel.DataContext = gameVM.GamePlayerList[(sNum + 1) % 3];
                break;

            case 4:
                leftCitadel.DataContext  = gameVM.GamePlayerList[sNum % 4];
                upCitadel.DataContext    = gameVM.GamePlayerList[(sNum + 1) % 4];
                rightCitadel.DataContext = gameVM.GamePlayerList[(sNum + 2) % 4];
                break;
            }
        }
Beispiel #13
0
        public void JoinRandom(Object sender, EventArgs e)
        {
            if (Games.Count >= 10)
            {
                MessageBox.Show("You are not allowed to play in more than ten games simultaneously. Please finish some games before starting new ones.");
            }

            SystemTray.ProgressIndicator.IsVisible = true;
            Context.JoinGame(Player.Name, game =>
                             Dispatcher.BeginInvoke(() =>
            {
                var settings = IsolatedStorageSettings.ApplicationSettings;
                var gameVm   = new GameVM(game);
                Games.Add(gameVm);

                settings["games"] = Games.ToArray();
                SystemTray.ProgressIndicator.IsVisible = false;
                OpenGame(gameVm);
            })
                             , () =>
                             Dispatcher.BeginInvoke(() =>
            {
                SystemTray.ProgressIndicator.IsVisible = false;
                MessageBox.Show("Failed to join a challenge. Please try again.");
            })
                             );
        }
Beispiel #14
0
        public async Task<ActionResult> Edit(GameVM gameVM)
        {
            try
            {
                string accessToken = await GetAccessToken();

                using (var client = new HttpClient())
                {
                    client.BaseAddress = url;
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Add the Authorization header with the AccessToken.
                    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);

                    var content = JsonConvert.SerializeObject(gameVM);
                    var buffer = System.Text.Encoding.UTF8.GetBytes(content);
                    var byteContent = new ByteArrayContent(buffer);
                    byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    // make the request
                    HttpResponseMessage response = await client.PostAsync("games/save", byteContent);

                    string jsonString = await response.Content.ReadAsStringAsync();
                    var responseData = JsonConvert.DeserializeObject<GameVM>(jsonString);
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Beispiel #15
0
        public GameV(int num, int roomNum, int seatNum)
        {
            gameVM      = new GameVM(num, roomNum, seatNum);
            DataContext = gameVM;
            InitializeComponent();
            myCitadel.DataContext = gameVM.GamePlayerList[seatNum - 1];
            switch (num)
            {
            case 2:
                upCitadel.DataContext   = gameVM.GamePlayerList[2 - seatNum];
                leftCitadel.Visibility  = Visibility.Collapsed;
                rightCitadel.Visibility = Visibility.Collapsed;
                break;

            case 3:
                leftCitadel.DataContext  = gameVM.GamePlayerList[seatNum % 3];
                rightCitadel.DataContext = gameVM.GamePlayerList[(seatNum + 1) % 3];
                upCitadel.Visibility     = Visibility.Collapsed;
                break;

            case 4:
                leftCitadel.DataContext  = gameVM.GamePlayerList[seatNum % 4];
                upCitadel.DataContext    = gameVM.GamePlayerList[(seatNum + 1) % 4];
                rightCitadel.DataContext = gameVM.GamePlayerList[(seatNum + 2) % 4];
                break;
            }
        }
Beispiel #16
0
        public ActionResult Refresh([Bind(Include = "GameID")] RefreshDTO dto)
        {
            var  name        = User.Identity.Name;
            int  id          = dto.GameID;
            Room currentRoom = _roomsManager.GetRoomById(id);

            if (currentRoom == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            currentRoom.MarkUserAsActive(new User()
            {
                Name = name
            });
            var currentGame = currentRoom.Game;

            lock (currentGame)
            {
                GameVM vm = GameVM.From(currentGame, currentRoom.Owner.Name);
                if (currentGame.CurrentPlayer != null)
                {
                    vm.IsPlayerTurn = currentGame.CurrentPlayer.Name == name;
                }
                JsonResult result = new JsonResult {
                    Data = JsonConvert.SerializeObject(vm)
                };
                return(result);
            }
        }
Beispiel #17
0
        public void Setup(object sender, EventArgs args)
        {
            var gameId   = NavigationContext.QueryString["game"];
            var settings = IsolatedStorageSettings.ApplicationSettings;

            Player = settings["player"] as PlayerVM;

            Context.GetGame(gameId, game =>
                            Dispatcher.BeginInvoke(() =>
            {
                Game = new GameVM(game);

                if (Game.Host == Player)
                {
                    BindHost();
                }
                else
                {
                    BindClient();
                }

                BindChangingProperties();
                BindChangedProperties();
            })
                            , () => { });
        }
Beispiel #18
0
        public ActionResult Index()
        {
            if (HttpContext.Session["Matrix"] == null)
            {
                matrix = Logic.InitializeMatrix();
                HttpContext.Session["Matrix"] = matrix;
                HttpContext.Session["Score"]  = 0;
                HttpContext.Session["Result"] = 0;
            }
            else
            {
                matrix = (int[, ])HttpContext.Session["Matrix"];
                score  = (int)HttpContext.Session["Score"];
                result = (int)HttpContext.Session["Result"];
            }


            GameVM game = new GameVM();

            game.Matrix     = matrix;
            game.Score      = score;
            game.hasBeenWon = false;
            game.isGameOver = false;
            game.Result     = result;

            IsWon(game);

            return(View(game));
        }
Beispiel #19
0
        public GameWindow(GameDifficulty difficulty)
        {
            InitializeComponent();
            gameVM      = new GameVM(difficulty);
            DataContext = gameVM;

            ShowSudokuSquares();
        }
Beispiel #20
0
 public async static Task CountDownTimerAsync(GameVM model)
 {
     for (int i = 30; i > 1; i--)
     {
         model.MultiButtonText = i.ToString();
         await Task.Delay(1000);
     }
 }
Beispiel #21
0
 public NewGame(GameVM gameVM)
 {
     XamlReader.Load(this);
     _gameVM          = gameVM;
     new_game_options = new NewGameOptionsVM(gameVM);
     DataContext      = new_game_options;
     BindControls();
 }
Beispiel #22
0
 public MainForm()
 {
     _gameVM    = new GameVM();
     ClientSize = new Size(600, 400);
     Content    = new MainWindow(_gameVM);
     CreateMenuToolBar();
     Title = "Pulsar4X";
 }
Beispiel #23
0
 public void AddGame(GameVM game, int userProfileID)
 {
     game.Active     = true;
     game.PlayerTurn = userProfileID;
     game.PlayerOne  = userProfileID;
     game.LastLetter = GetLetter();
     Game.AddGame(game);
 }
Beispiel #24
0
 /// <summary>
 /// Initializes a new instance of the MainWindow view
 /// </summary>
 public MainWindow(GameVM gameVM)
 {
     _gameVM     = gameVM;
     DataContext = _gameVM;
     XamlReader.Load(this);
     _gameVM.PropertyChanged             += GameVMPropertyChanged;
     _gameVM.TimeControl.PropertyChanged += _timeControl_PropertyChanged;
 }
Beispiel #25
0
 public NewGame(GameVM _game)
 {
     XamlReader.Load(this);
     game             = _game;
     new_game_options = new NewGameOptionsVM();
     DataContext      = new_game_options;
     BindControls();
 }
        public void Initialise(GameVM gameVM, StarSystem starSys)
        {
            IconableEntitys.Clear();
            IconableEntitys.AddRange(starSys.SystemManager.GetAllEntitiesWithDataBlob <PositionDB>(gameVM.CurrentAuthToken));
            SystemSubpulse = starSys.SystemManager.ManagerSubpulses;
            starSys.SystemManager.GetAllEntitiesWithDataBlob <NewtonBalisticDB>(gameVM.CurrentAuthToken);

            OnPropertyChanged(nameof(IconableEntitys));
        }
        public IGameVM CreateInstance(Difficulty difficulty)
        {
            var gameBoardVM = _gameBoardVMFactory.CreateInstance(difficulty);
            var tools = _toolVMFactory.CreateTools(gameBoardVM);

            var gameVM = new GameVM(gameBoardVM, tools);

            return gameVM;
        }
Beispiel #28
0
 public ClientConnectCMD(GameVM gameVM)
 {
     ID = "Connect";
     //Image = Icon.FromResource("Pulsar4X.CrossPlatformUI.Resources.Icons.Connect.ico");
     MenuText    = "Connect";
     ToolBarText = "Connect";
     //Shortcut = Keys.F5;
     _gameVM = gameVM;
 }
 private GameVM FillPlayers(GameVM game)
 {
     game.PlayersID[0] = game.PlayerOne;
     game.PlayersID[1] = game.PlayerTwo;
     game.PlayersID[2] = game.PlayerThree;
     game.PlayersID[3] = game.PlayerFour;
     game.PlayersID[4] = game.PlayerFive;
     return(game);
 }
Beispiel #30
0
 public LoadGame(GameVM gameVM)
 {
     ID          = "Loadgame";
     Image       = Icon.FromResource("Pulsar4X.CrossPlatformUI.Resources.Icons.NewGame.ico");
     MenuText    = "Load Game";
     ToolBarText = "Load Game";
     Shortcut    = Keys.F5;
     _gameVM     = gameVM;
 }
Beispiel #31
0
        public ColonyScreenView(GameVM gameVM) : this()
        {
            this.gameVM = gameVM;

            ColonySelection.DataContext = gameVM.Colonys;
            //ColonySelection.SelectedKeyChanged += SetViewModel;
            gameVM.Colonys.SelectionChangedEvent += SetViewModel;
            SetViewModel(0, 0);
        }