Exemplo n.º 1
0
        public void Update()
        {
            var gameBusiness = new GameBusiness();

            var requestObject = new GameDTO()
            {
                Id   = 1,
                Name = "Game_Updated"
            };

            var result = gameBusiness.Update(requestObject);

            Assert.IsNotNull(result);

            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("Game_Updated", result.Name);

            requestObject = new GameDTO()
            {
                Id   = 500,
                Name = "Game_Updated"
            };

            result = gameBusiness.Update(requestObject);

            Assert.IsNull(result);
        }
Exemplo n.º 2
0
        public void GetRelativeRanking()
        {
            var gameBusiness = new GameBusiness();

            var result = gameBusiness.GetRelativeRanking(10, 2);

            Assert.IsNotNull(result);

            Assert.IsNotNull(result.Count == 5);

            Assert.IsNotNull(result.First().Position == 7 &&
                             result.Last().Position == 12);

            Assert.IsNotNull(result.First().Position < result.Last().Position &&
                             result.First().Score >= result.Last().Score);

            result = gameBusiness.GetRelativeRanking(100, 10);

            Assert.IsNotNull(result.Count == 21);

            Assert.IsNotNull(result.First().Position == 89 &&
                             result.Last().Position == 111);

            Assert.IsNotNull(result.First().Position < result.Last().Position &&
                             result.First().Score >= result.Last().Score);
        }
Exemplo n.º 3
0
        public JsonResult GetLabeledCell(int Id)
        {
            var gameBusiness         = new GameBusiness();
            List <MoveArchive> moves = gameBusiness.GetMoveListByEncounter(Id);

            return(Json(moves, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public HttpResponseMessage GetAbsoluteRanking(int absoluteNumber)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            try
            {
                GameBusiness gameBusiness = new GameBusiness();

                var result = gameBusiness.GetAbsoluteRanking(absoluteNumber);

                if (result != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, result);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, "Not ranking found");
                }
            }
            catch (Exception e)
            {
                Logger.Error("GameController", "Get", e.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected error");
            }

            return response;
        }
Exemplo n.º 5
0
 public JsonResult EncounterUpdate(int eId, int winnerInfo)
 {
     try
     {
         int winnerType;
         var gameBusiness = new GameBusiness();
         if (winnerInfo == 1)
         {
             winnerType = 1;
         }
         else if (winnerInfo == 2)
         {
             winnerType = 2;
         }
         else if (winnerInfo == 3)
         {
             winnerType = 3;
         }
         else
         {
             winnerType = 0;
         }
         gameBusiness.UpdateEncounter(eId, winnerType);
         return(Json(""));
     }
     catch (Exception ex)
     {
         throw new NotSupportedException("Beklenmedik Bir Hata Oluştu !", ex);
     }
 }
Exemplo n.º 6
0
        public HttpResponseMessage Delete(int id)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            try
            {
                GameBusiness gameBusiness = new GameBusiness();

                var result = gameBusiness.Delete(id);

                if (result != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, "Game successfully deleted");
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, "Game not found");
                }
            }
            catch (Exception e)
            {
                Logger.Error("GameController", "Get", e.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected error");
            }

            return response;
        }
        public PlayerModel HostGame(PlayerModel model)
        {
            var business = new GameBusiness();
            var player   = business.HostAGame(model);

            return(player);
        }
Exemplo n.º 8
0
        public HttpResponseMessage Put(GameDTO gameDTO)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            try
            {
                if (ModelState.IsValid)
                {
                    GameBusiness gameBusiness = new GameBusiness();

                    var result = gameBusiness.Update(gameDTO);

                    if (result != null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, "Game successfully updated");
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, "Game not found");
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "The request object doesn't match with the requirement");
                }

            }
            catch (Exception e)
            {
                Logger.Error("GameController", "Get", e.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected error");
            }

            return response;
        }
Exemplo n.º 9
0
 public ActionResult ContinueGame(int Id)
 {
     try
     {
         if (Session["Account"] == null)
         {
             return(RedirectToAction("SingupAndSignin", "Account"));
         }
         else
         {
             var gameBusiness   = new GameBusiness();
             var encounterGame  = gameBusiness.GetEncounterById(Id);
             var game           = gameBusiness.GetGameInfo(encounterGame.GameId);
             var continueGameVM = new ContinueGameViewModel()
             {
                 Game             = game,
                 EncounterArchive = encounterGame
             };
             return(View(continueGameVM));
         }
     }
     catch
     {
         return(RedirectToAction("SingupAndSignin", "Account"));
     }
 }
Exemplo n.º 10
0
        public JsonResult GetOngoingGameList()
        {
            try
            {
                var gameBusiness    = new GameBusiness();
                var playerId        = Convert.ToInt32(Session["AccountId"]);
                var ongoingGameList = gameBusiness.OngoingGameList(playerId);
                List <OngoingGameViewModel> OngoingGameVMList = new List <OngoingGameViewModel>();

                for (int i = 0; i < ongoingGameList.Count; i++)
                {
                    OngoingGameViewModel OngoingGameVM = new OngoingGameViewModel();
                    var game = gameBusiness.GetGameInfo(ongoingGameList[i].GameId);

                    OngoingGameVM.GameName      = game.GameName;
                    OngoingGameVM.OngoingGameId = ongoingGameList[i].Id;
                    if (ongoingGameList[i].EncounterType == 1)
                    {
                        OngoingGameVM.EncounterTypeName = "Bilgisayara Karşı";
                    }
                    else if (ongoingGameList[i].EncounterType == 2)
                    {
                        OngoingGameVM.EncounterTypeName = "Oyuncuya Karşı";
                    }
                    OngoingGameVMList.Add(OngoingGameVM);
                }

                return(Json(OngoingGameVMList, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex, "Devam Eden Oyun Listesi Getirilemedi !"));
            }
        }
Exemplo n.º 11
0
        public JsonResult GetCotinueGame(int Id)
        {
            var gameBusiness = new GameBusiness();
            var encounter    = gameBusiness.GetEncounterById(Id);
            var game         = gameBusiness.GetGameInfo(encounter.GameId);

            return(Json(game, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 12
0
        public object getSegmentList(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string mobileToken = dicParas.ContainsKey("mobileToken") ? dicParas["mobileToken"].ToString() : string.Empty;
                string routerToken = dicParas.ContainsKey("routerToken") ? dicParas["routerToken"].ToString() : string.Empty;
                string groupId     = dicParas.ContainsKey("groupId") ? dicParas["groupId"].ToString() : string.Empty;

                Base_MerchInfo merch = MerchBusiness.GetMerchModel(mobileToken);
                if (merch.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户令牌无效"));
                }

                Base_DeviceInfo router = DeviceBusiness.GetDeviceModel(routerToken);
                if (router.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "控制器令牌无效"));
                }

                Data_GameInfo group = GameBusiness.GetGameInfoModel(Convert.ToInt32(groupId));
                if (group.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "分组参数无效"));
                }

                //分组集合
                var groupList = MerchSegmentBusiness.GetMerchSegmentList().Where(t => t.ParentID == router.ID && t.GroupID == group.GroupID).ToList();

                GroupInfoModel model = new GroupInfoModel();
                model.groupId   = group.GroupID;
                model.groupName = group.GroupName;

                List <Terminal> Terminals = new List <Terminal>();
                foreach (var item in groupList)
                {
                    Terminal        t       = new Terminal();
                    Base_DeviceInfo cDevice = DeviceBusiness.GetDeviceModelById((int)item.DeviceID);
                    t.terminalName  = cDevice.DeviceName ?? cDevice.SN;
                    t.terminalToken = cDevice.Token;
                    t.headAddress   = item.HeadAddress;
                    t.sn            = cDevice.SN;
                    t.deviceType    = ((DeviceTypeEnum)cDevice.DeviceType).ToDescription();
                    t.status        = DeviceStatusBusiness.GetDeviceState(cDevice.Token);

                    Terminals.Add(t);
                }
                model.Terminals = Terminals;

                return(ResponseModelFactory <GroupInfoModel> .CreateModel(isSignKeyReturn, model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="token"></param>
        /// <param name="playerKey"></param>
        /// <param name="nextAction"></param>
        private static void WatchGame(object playerKey)
        {
            var key = playerKey.ToString();

            var game = GameBusiness.GetGame(gameToken, key);

            Console.WriteLine("Me: " + game.Me.HealthPoints + "pv, foe: " + game.Foe.HealthPoints + "pv.");

            nextAction = AiBusiness.GetNextAction(game, lastAction);
        }
Exemplo n.º 14
0
        public void GetAll()
        {
            var gameBusiness = new GameBusiness();

            var result = gameBusiness.GetAll();

            Assert.IsNotNull(result);

            Assert.IsNotNull(result.Count > 1);
        }
Exemplo n.º 15
0
        public void GetById()
        {
            var gameBusiness = new GameBusiness();

            var result = gameBusiness.GetById(1);

            Assert.IsNotNull(result);

            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("Game", result.Name);
        }
Exemplo n.º 16
0
        public ActionResult <RequestResponse> ClousedGame([Bind("rouletteId")] LaunchGame launchGame)
        {
            IGameBusiness   gameBusiness = new GameBusiness(_context);
            RequestResponse response     = gameBusiness.ClousedGame(launchGame.RouletteId);

            if (response.SuccessFul == false)
            {
                return(BadRequest(error: new { error = response.MessageError }));
            }

            return(Content(response.MessageSuccess));
        }
Exemplo n.º 17
0
        public void Delete()
        {
            var gameBusiness = new GameBusiness();

            var result = gameBusiness.Delete(2);

            Assert.IsNotNull(result);

            result = gameBusiness.Delete(-1);

            Assert.IsNull(result);
        }
Exemplo n.º 18
0
        public void Create()
        {
            var gameBusiness = new GameBusiness();

            var requestObject = new GameDTO()
            {
                Id   = 0,
                Name = "Game2"
            };

            gameBusiness.Create(requestObject);
        }
Exemplo n.º 19
0
 public JsonResult GetGameInfo(int Id)
 {
     try
     {
         var gameBuseiness = new GameBusiness();
         var gameInfo      = gameBuseiness.GetGameInfo(Id);
         return(Json(gameInfo, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(ex));
     }
 }
Exemplo n.º 20
0
        public JsonResult GetGameList()
        {
            try
            {
                var gameBusiness = new GameBusiness();
                var gameList     = gameBusiness.GetAllGameList();

                return(Json(gameList, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex, "Beklenmedik Bir Hata Oluştu !"));
            }
        }
Exemplo n.º 21
0
        public JsonResult SaveMove(int eId, int MoveCellx, int MoveCelly, string Value)
        {
            try
            {
                var gameBusiness = new GameBusiness();
                var playerId     = Convert.ToInt32(Session["AccountId"]);
                var returnMove   = gameBusiness.SaveMove(eId, MoveCellx, MoveCelly, Value);

                return(Json(returnMove, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex, "Beklenmedik Bir Hata Oluştur"));
            }
        }
Exemplo n.º 22
0
 internal static Issuse_QueryInfo QueryCurretNewIssuseInfo(string gameCode, string gameType)
 {
     lock (_lckObj_IssuseOffical)
     {
         if (!_issuseOficalDictionary.ContainsKey(gameCode) ||
             _issuseOficalDictionary[gameCode] == null ||
             _issuseOficalDictionary[gameCode].OfficialStopTime < DateTime.Now)
         {
             lock (_lckObj_IssuseOffical2)
             {
                 _issuseOficalDictionary[gameCode] = new GameBusiness().QueryCurrentNewIssuseInfo(gameCode, gameType);
             }
         }
         return(_issuseOficalDictionary[gameCode]);
     }
 }
Exemplo n.º 23
0
        public JsonResult EncounterSave(int Et, int Id)
        {
            try
            {
                var gameBusiness = new GameBusiness();
                var playerId     = Convert.ToInt32(Session["AccountId"]);
                gameBusiness.SaveEncounter(playerId, Et, Id);
                var Encounter = gameBusiness.GetEncounterByPlayerId(playerId, Id);

                return(Json(Encounter, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex, "Beklenmedik Bir Hata Oluştur"));
            }
        }
Exemplo n.º 24
0
        public override void Execute(object parameter)
        {
            if (CanSelect())
            {
                //ConsoleManager.Show();
                //Console.WriteLine("Hello FROM tILES!");

                Pieces = (parameter as BoardVM).Pieces;
                Tiles  = (parameter as BoardVM).Tiles;

                //Pieces.Clear();
                Utils.RedrawTiles();

                foreach (var tile in GameBusiness.selectedTiles)
                {
                    if (tile == cellVM)
                    {
                        GameBusiness.movesForSelectedPiece.Sort(
                            (move1, move2) => - move1.TakenPieces.Count.CompareTo(move2.TakenPieces.Count));

                        foreach (var move in GameBusiness.movesForSelectedPiece)
                        {
                            if (move.FinalLocation.Equals(tile.Location))
                            {
                                foreach (var piece in move.TakenPieces)
                                {
                                    Pieces.Remove(piece);
                                }
                                break;
                            }
                        }

                        GameBusiness.selectedPiece.Piece.PieceLocation = tile.Location;
                        break;
                    }
                }
                GameBusiness.IsKing(GameBusiness.selectedPiece);
                if (GameBusiness.IsFinal(Pieces))
                {
                    BoardVM.CurentWindows.StartNewGame();
                }
                GameBusiness.ChangePlayer();
                (parameter as BoardVM).IsPlayer1 = true;

                GameBusiness.selectedPiece.IsSelected = System.Windows.Media.Colors.Black;
            }
        }
Exemplo n.º 25
0
        public void ShouldWonTheGame()
        {
            var word = new PlayStatus()
            {
                CorrectedLetters = "XXXX",
                Word             = "TEST",
                ErrorsQuantity   = 0
            };

            foreach (var item in new String("Test").ToCharArray())
            {
                word.Shot = item.ToString();
                word      = new GameBusiness(Environment.CurrentDirectory).Play(word);
            }

            Assert.True(word.ErrorsQuantity == 0 && word.Message == "Congratulations, you won the game.");
        }
Exemplo n.º 26
0
        public void ShouldLoseTheGame()
        {
            var word = new PlayStatus()
            {
                CorrectedLetters = "XXXX",
                Word             = "TEST",
                ErrorsQuantity   = 0
            };

            foreach (var item in new String("ABCDEFG").ToCharArray())
            {
                word.Shot = item.ToString();
                word      = new GameBusiness(Environment.CurrentDirectory).Play(word);
            }

            Assert.True(word.ErrorsQuantity == 6 && word.Message == "Sorry, you lose!");
        }
Exemplo n.º 27
0
        /// <summary>
        /// Game played by our AI
        /// </summary>
        private static Game PlayGame(Game game)
        {
            //Create a callback to get the current game state each 100ms
            Timer timer = new Timer(WatchGame, playerKey, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100));

            while (game.Status != GameStatus.FINISHED)
            {
                lastAction = GameBusiness.PlayAndWaitCoolDown(game.Token, playerKey, nextAction);

                game = GameBusiness.GetGame(game.Token, playerKey);
                Console.WriteLine("Me: " + game.Me.HealthPoints + "pv, foe: " + game.Foe.HealthPoints + "pv.");
            }

            timer.Dispose();

            return(game);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 获取当前奖期信息
        /// </summary>
        internal static Issuse_QueryInfo GetCurrentIssuserInfo(string gameCode)
        {
            if (_issuseDictionary.Keys.Contains(gameCode))
            {
                var existIssuse = _issuseDictionary.FirstOrDefault(d => d.Key == gameCode);
                if (existIssuse.Value != null && existIssuse.Value.LocalStopTime > DateTime.Now)
                {
                    return(existIssuse.Value);
                }
            }

            var issuse = new GameBusiness().QueryCurrentIssuseInfo(gameCode);

            _issuseDictionary.Remove(gameCode);
            _issuseDictionary.Add(gameCode, issuse);
            return(issuse);
        }
Exemplo n.º 29
0
        public HttpResponseMessage Get()
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            try
            {
                GameBusiness gameBusiness = new GameBusiness();

                var result = gameBusiness.GetAll();

                response = Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception e)
            {
                Logger.Error("GameController", "Get", e.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Unexpected error");
            }

            return response;
        }
Exemplo n.º 30
0
 public ActionResult PlayGamePage(int Id)
 {
     try
     {
         if (Session["Account"] == null)
         {
             return(RedirectToAction("SingupAndSignin", "Account"));
         }
         else
         {
             var gameBusiness = new GameBusiness();
             var game         = gameBusiness.GetGameInfo(Id);
             return(View(game));
         }
     }
     catch
     {
         return(RedirectToAction("SingupAndSignin", "Account"));
     }
 }