public MainWindowViewModel(IEventAggregator eventAggregator)
 {
     _eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
     GameManager      = new GameManagerModel(_eventAggregator);
     PlaceSymbol      = new RelayCommand(OnPlaceSymbol, x => true);
     NewGame          = new RelayCommand(OnNewGame, x => true);
 }
Beispiel #2
0
        public void GetScore(string player, string RoomID)
        {
            GameModel game  = GameManagerModel.GetInstance().GetGame(RoomID);
            string    score = game.GetPlayer(player).Points.ToString();

            Clients.Caller.sendScore(score);
        }
        public void LoadManagers()
        {
            if (GameManagerModels.Count != 0)
            {
                GameManagerModels.Clear();
            }

            gmInfo = GameManagersInformation.Instance();
            gmInfo.Load();
            List <GameManager> gmList = gmInfo.GameManagersList.ToList();

            foreach (var manager in gmList)
            {
                GameManagerModels.Add(new GameManagerModel(manager));
            }
            if (gmList.Count != 0)
            {
                SelectedGameManagerModel = GameManagerModels.First();
            }
            else
            {
                try
                {
                    SelectedGameManagerModel = new GameManagerModel(new GameManager());
                }
                catch (Exception e)
                {
                    MessageBox.Show(
                        e.Message,
                        "Error");
                }
            }
        }
        public GameManagerModel AssignSignTypeAsWinner(GameManagerModel model, SignType type)
        {
            model.VictorSign = type;
            model.IsRunning  = false;

            return(model);
        }
        public GameManagerModel DeclareDraw(GameManagerModel model)
        {
            model.UIScript.ShowCanvas(model.VictorSign);
            model.IsRunning = false;

            return(model);
        }
Beispiel #6
0
        public ActionResult JoinRoom(NewRoomModel newRoom)
        {
            ViewBag.RoomID   = newRoom.ID;
            ViewBag.Nickname = newRoom.Nickname;
            GameManagerModel gameModel = GameManagerModel.GetInstance();

            ViewBag.Players = gameModel.GetGame(newRoom.ID).PlayerNickNames.Values;
            return(View("NewRoom"));
        }
        public void DeclareWinner(GameManagerModel model)
        {
            if (model.VictorSign == SignType.DEFAULT)
            {
                return;
            }

            model.UIScript.ShowCanvas(model.VictorSign);
        }
        public GameManagerModel NewRound(GameManagerModel model)
        {
            if (model.PlayerTurnCompleted && model.ComputerTurnCompleted && model.IsRunning)
            {
                model.PlayerTurnCompleted   = false;
                model.ComputerTurnCompleted = false;
            }

            return(model);
        }
Beispiel #9
0
        public GameManagerModel CheckIfAreaIsAvailable(GameManagerModel model, AreaScript areaScript)
        {
            if (areaScript.Model.Type != SignType.DEFAULT)
            {
                return(model);
            }

            areaScript.UpdateSign(SignType.COMPUTER_SIGN);
            model.ComputerTurnCompleted = true;
            return(model);
        }
        public GameManagerModel CheckAreaSignType(GameManagerModel model, AreaScript script)
        {
            if (script.Model.Type != SignType.DEFAULT)
            {
                return(model);
            }

            model.PlayerTurnCompleted = true;
            script.UpdateSign(SignType.PLAYER_SIGN);
            return(model);
        }
        public GameManagerModel CheckForAreaObject(GameManagerModel model, GameObject collision)
        {
            if (collision.layer != LayerMask.NameToLayer("Area"))
            {
                return(model);
            }

            AreaScript script = collision.GetComponent <AreaScript>();

            return(CheckAreaSignType(model, script));
        }
Beispiel #12
0
        public GameManagerModel BlockPlayerRow(GameManagerModel model, WinningRowModel row)
        {
            AreaScript area1 = model.Areas.Find(x => x.transform.position == row.FirstPos).GetComponent <AreaScript>();
            AreaScript area2 = model.Areas.Find(x => x.transform.position == row.SecondPos).GetComponent <AreaScript>();
            AreaScript area3 = model.Areas.Find(x => x.transform.position == row.ThirdPos).GetComponent <AreaScript>();

            model = CheckIfAreaIsAvailable(model, area1);
            model = CheckIfAreaIsAvailable(model, area2);
            model = CheckIfAreaIsAvailable(model, area3);

            return(model);
        }
        public GameManagerModel CreateGrid(GameManagerModel model)
        {
            model = DestroyAreas(model);

            foreach (Vector3 pos in model.GridPos)
            {
                GameObject newArea = _spawnService.SpawnWithNoRotation(model.Area, pos);
                newArea.name = string.Format("Area ({0}, {1})", pos.y, pos.x);
                model.Areas.Add(newArea);
            }

            return(model);
        }
        public GameManagerModel CheckVictoryCondition(GameManagerModel model)
        {
            if (!model.IsRunning)
            {
                return(model);
            }

            model = CheckSignType(model, SignType.PLAYER_SIGN);
            model = CheckSignType(model, SignType.COMPUTER_SIGN);

            DeclareWinner(model);

            return(model);
        }
Beispiel #15
0
        private void HandleTransitionTimer(string roomId)
        {
            GameModel game        = GameManagerModel.GetInstance().GetGame(roomId);
            string    newQuestion = game.GetQuestion();

            if (newQuestion == null)
            {
                Clients.Group(roomId).endGame();
            }
            else
            {
                Clients.Group(roomId).newQuestion(newQuestion);
            }
        }
        public GameManagerModel DestroyAreas(GameManagerModel model)
        {
            foreach (GameObject area in model.Areas)
            {
                GameObject.Destroy(area);
            }

            model.Areas.Clear();
            model.VictorSign            = SignType.DEFAULT;
            model.IsRunning             = true;
            model.PlayerTurnCompleted   = false;
            model.ComputerTurnCompleted = false;
            return(model);
        }
Beispiel #17
0
        public ActionResult EditGame(int idGame)
        {
            using (var context = new FcDeHoekContext())
            {
                GameManagerModel manageModel;

                if (idGame == 0)
                {
                    manageModel = new GameManagerModel
                    {
                        Games = new List <GameModel> {
                            new GameModel()
                        },
                        Teams            = context.Teams.ToList(),
                        CompetitionTypes = eCompetitionType.GetAllCompetitionTypes(),
                        AddAnother       = false
                    };
                }
                else
                {
                    var game = GameQueries.GetById(context, idGame);
                    manageModel = new GameManagerModel
                    {
                        Games = new List <GameModel> {
                            new GameModel
                            {
                                AwayTeam      = game.GameAwayTeam.Name,
                                Competition   = game.GameCompetition.Description,
                                Forfait       = game.Forfait,
                                GoalsHomeTeam = game.GoalsHomeTeam,
                                GoalsAwayTeam = game.GoalsAwayTeam,
                                GameResult    = 0,
                                HomeTeam      = game.GameHomeTeam.Name,
                                IdAwayTeam    = game.IdAwayTeam,
                                IdCompetition = game.IdCompetition,
                                IdGame        = game.IdGame,
                                IdHomeTeam    = game.IdHomeTeam,
                                MatchDay      = game.MatchDate
                            }
                        },
                        Teams            = context.Teams.ToList(),
                        CompetitionTypes = eCompetitionType.GetAllCompetitionTypes(),
                        AddAnother       = false
                    };
                }

                return(View("Detail", manageModel));
            }
        }
Beispiel #18
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            // The order of this is important
            RouteTable.Routes.MapHubs();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            GameManagerModel.GetInstance();
        }
        public GameManagerModel ClickEvent(GameManagerModel model)
        {
            if (Input.GetMouseButtonDown(0) && model.IsRunning && !model.PlayerTurnCompleted)
            {
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

                if (hit.collider != null)
                {
                    model = CheckForAreaObject(model, hit.collider.gameObject);
                }
            }

            return(model);
        }
Beispiel #20
0
        public GameManagerModel ComputerAction(GameManagerModel model)
        {
            if (!model.PlayerTurnCompleted || !model.IsRunning)
            {
                return(model);
            }

            // 1 - If the player nearly has a row completed, block it.
            model = CheckForPlayerWin(model);

            // 2 - Select a random area to mark.
            model = MarkRandomArea(model);

            return(model);
        }
Beispiel #21
0
        public ActionResult StartGame(StartGameModel startGame)
        {
            ViewBag.Player         = startGame.PlayerName;
            ViewBag.RoomID         = startGame.RoomID;
            ViewBag.QuestionNumber = 1;
            ViewBag.Question       = startGame.Question;
            GameManagerModel gameModel = GameManagerModel.GetInstance();

            try
            {
                ViewBag.Players = gameModel.GetGame(startGame.RoomID).PlayerNickNames.Values;
            }
            catch (Exception) { }
            return(View());
        }
Beispiel #22
0
        public void JoinRoom(string nickname, string roomID)
        {
            GameManagerModel gameManager = GameManagerModel.GetInstance();
            GameModel        game        = gameManager.GetGame(roomID);

            if (game == null)
            {
                Clients.Caller.throwExeption();
            }
            else
            {
                game.AddPlayer(new PlayerModel(nickname, Context.ConnectionId));
                Clients.Caller.submitJoinRoomForm();
            }
        }
Beispiel #23
0
        void Update()
        {
            // 1 - Player turn.
            GameManagerModel = _gameManagerService.ClickEvent(GameManagerModel);
            GameManagerModel = _gameManagerService.CheckVictoryCondition(GameManagerModel);
            GameManagerModel = _gameManagerService.CheckDrawCondition(GameManagerModel);

            // 2 - Computer turn.
            GameManagerModel = _aiService.ComputerAction(GameManagerModel);
            GameManagerModel = _gameManagerService.CheckVictoryCondition(GameManagerModel);
            GameManagerModel = _gameManagerService.CheckDrawCondition(GameManagerModel);

            // 3 - New Round.
            GameManagerModel = _gameManagerService.NewRound(GameManagerModel);
        }
Beispiel #24
0
        public void SendChoice(string player, string playerChoice, string roomId)
        {
            GameModel   game   = GameManagerModel.GetInstance().GetGame(roomId);
            PlayerModel result = game.SendAnswer(player, playerChoice);

            if (result != null)
            {
                Clients.Group(roomId).showResult(result);
                Timer transitionTimer = new Timer(10000);
                transitionTimer.Elapsed  += (source, e) => HandleTransitionTimer(roomId);
                transitionTimer.Enabled   = true;
                transitionTimer.AutoReset = false;
                transitionTimer.Start();
            }
        }
Beispiel #25
0
        public async Task NewRoom(string nickname)
        {
            GameManagerModel gameManager = GameManagerModel.GetInstance();

            Random      random       = new Random();
            int         randomNumber = random.Next(0, 9999);
            string      newID        = randomNumber.ToString("D4");
            GameModel   newGame      = new GameModel(newID, 5); //change to new input textbox!
            PlayerModel newPlayer    = new PlayerModel(nickname, Context.ConnectionId);

            newGame.AddPlayer(newPlayer);
            gameManager.AddGame(newGame);

            await Groups.Add(Context.ConnectionId, newID);

            Clients.Caller.submitNewRoomForm(newID);
        }
Beispiel #26
0
        public ActionResult Save(GameManagerModel model)
        {
            using (var context = new FcDeHoekContext())
            {
                var game = GameQueries.GetById(context, model.Games[0].IdGame);
                if (game == null)
                {
                    game = new Game();
                }

                foreach (var gameModel in model.Games)
                {
                    game.GoalsAwayTeam   = gameModel.GoalsAwayTeam;
                    game.GoalsHomeTeam   = gameModel.GoalsHomeTeam;
                    game.Forfait         = gameModel.Forfait;
                    game.IdCompetition   = gameModel.IdCompetition;
                    game.IdAwayTeam      = gameModel.IdAwayTeam;
                    game.IdHomeTeam      = gameModel.IdHomeTeam;
                    game.IdPostPonedGame = gameModel.IdPostPonedGame;
                    game.IdSeason        = SeasonQueries.GetSeasonByDate(context, gameModel.MatchDay)?.IdSeason ?? SeasonQueries.GetCurrentSeason(context).IdSeason;
                    game.MatchDate       = gameModel.MatchDay;
                    game.NotPlayed       = gameModel.IsPostPoned;

                    context.Games.AddOrUpdate(game);
                    context.SaveChanges();
                }


                if (model.AddAnother)
                {
                    if (model.Games.Count > 1)
                    {
                        return(RedirectToAction("AddMultipleGames", "GameManager", new { idGame = 0 }));
                    }
                    else
                    {
                        return(RedirectToAction("EditGame", "GameManager", new { idGame = 0 }));
                    }
                }


                return(RedirectToAction("Index", "GameManager"));
            }
        }
Beispiel #27
0
        public GameManagerModel MarkRandomArea(GameManagerModel model)
        {
            if (model.ComputerTurnCompleted)
            {
                return(model);
            }

            int areaCount = 0;

            while (model.ComputerTurnCompleted == false && areaCount < model.Areas.Count)
            {
                int        areaIndex  = Random.Range(0, model.Areas.Count);
                AreaScript areaScript = model.Areas[areaIndex].GetComponent <AreaScript>();
                model      = CheckIfAreaIsAvailable(model, areaScript);
                areaCount += 1;
            }

            return(model);
        }
        public GameManagerModel CheckDrawCondition(GameManagerModel model)
        {
            if (!model.IsRunning)
            {
                return(model);
            }

            List <GameObject> list =
                model.Areas.Where(x =>
                                  x.GetComponent <AreaScript>().Model.Type == SignType.DEFAULT
                                  ).ToList();

            if (list.Count == 0)
            {
                model = DeclareDraw(model);
            }

            return(model);
        }
Beispiel #29
0
        public ActionResult EndGame(EndGameModel endGame)
        {
            ViewBag.Player = endGame.Nickname;
            ViewBag.RoomID = endGame.RoomId;
            GameModel   game       = GameManagerModel.GetInstance().GetGame(endGame.RoomId);
            PlayerModel thisPlayer = game.GetPlayer(endGame.Nickname);
            PlayerModel winner     = game.GetWinner();

            if (thisPlayer.NickName.Equals(winner.NickName))
            {
                ViewBag.MostLikely = "You won!";
            }
            else
            {
                ViewBag.MostLikely = "The winner is " + winner.NickName + "!";
            }
            ViewBag.MostPoints = "with " + winner.Points;
            return(View());
        }
Beispiel #30
0
 public ActionResult AddMultipleGames()
 {
     using (var context = new FcDeHoekContext())
     {
         var model = new GameManagerModel
         {
             AddAnother       = false,
             CompetitionTypes = eCompetitionType.GetAllCompetitionTypes(),
             Teams            = context.Teams.ToList(),
             Games            = new List <GameModel>
             {
                 new GameModel(),
                 new GameModel(),
                 new GameModel(),
                 new GameModel()
             }
         };
         return(View(model));
     }
 }