public async Task <IActionResult> Create(NewGameViewModel newGameVM) { try { if (ModelState.IsValid) { var game = _mapper.Map <Game>(newGameVM); var user = _mapper.Map <User>(newGameVM); _context.Games.Add(game); await _context.SaveChangesAsync(); user.GameId = game.GameId; user.UserIsHost = true; _context.Users.Add(user); await _context.SaveChangesAsync(); var cookieOptions = new CookieOptions { Expires = DateTime.UtcNow.AddDays(1) }; Response.Cookies.Append("user", user.ToJsonBase64String(), cookieOptions); return(Ok(Url.Action("Start", "Game", new { id = game.GameId }))); } return(PartialView("_NewGamePartial", newGameVM)); } catch (Exception ex) { _logger.LogError(ex, $"An exception occurred in {MethodBase.GetCurrentMethod().Name}"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public NewGamePage(string gameId = null) { InitializeComponent(); _vm = App.IOC.NewGame; BindingContext = _vm; _gameId = gameId; }
public void GetMatchListTest() { //Arrange var hometeamid = new DataSeedService <Team>(Client).Create(new Team { Name = "HomeTeam", Players = new List <string> { "HomePlayerName" } }); var awayteamid = new DataSeedService <Team>(Client).Create(new Team { Name = "AwayTeam", Players = new List <string> { "AwayPlayerName" } }); var newgame = new NewGameViewModel( Client, new DataSeedService <Match>(Client), new DataSeedService <Team>(Client), new DataSeedService <Location>(Client), new DataSeedService <Umpire>(Client)); var match = newgame.AddMatch(hometeamid, awayteamid, "10", "Richmod,VA", "PrimUmpire", "SecondUmpire"); //Act var matches = _listViewModel.Matches; //Assert matches.Count.Should().BeGreaterOrEqualTo(1); }
public GameViewModel() { m_mainViewModel = new MainMenuViewModel(this); m_mainViewModel.OnOpenNewGameCommand += MainViewModel_OnOpenNewGameCommand; m_mainViewModel.OnOpenOptionsCommand += MainViewModel_OnOpenOptionsCommand; m_mainViewModel.OnLoadGameCommand += MainViewModel_OnLoadGameCommand; m_newGameViewModel = new NewGameViewModel(this); m_newGameViewModel.OnCloseNewGameCommand += NewGameViewModel_OnCloseNewGameCommand; m_newGameViewModel.OnStartGameCommand += NewGameViewModel_OnStartGameCommand; m_newGameViewModel.OnDisplayDurationChange += NewGameViewModel_OnDisplayDurationChange; m_newGameViewModel.OnPlayerCountChange += NewGameViewModel_OnPlayerCountChange; m_newGameViewModel.OnSessionNameChange += NewGameViewModel_OnSessionNameChange; m_newGameViewModel.OnSearchedCountChange += NewGameViewModel_OnSearchedCountChange;; m_optionsViewModel = new OptionsViewModel(this); m_optionsViewModel.OnCloseOptionsCommand += OptionsViewModel_OnCloseOptionsCommand; m_syllablesInputViewModel = new SyllablesInputViewModel(this); m_syllablesInputViewModel.OnAcceptCommand += SyllablesViewModel_OnAcceptCommand; m_incommingTransmissionViewModel = new IncommingTransmissionViewModel(this); m_incommingTransmissionViewModel.OnWaitTimePassed += IncommingTransmissionViewModel_OnWaitTimePassed; m_endScreenViewModel = new EndScreenViewModel(this); m_endScreenViewModel.OnOKCommand += EndScreenViewModel_OnOKCommand; CurrentDisplayedMenu = m_mainViewModel; }
/// <summary> /// News the game. /// </summary> /// <returns>The view.</returns> public ViewResult NewGame() { this.game = new Game(); var viewModel = new NewGameViewModel(); return(this.View(viewModel)); }
public string UpdateFromDb(Func <GameInfoModel, bool> func) { List <GameInfoModel> list = this.dbContext.GameInfoModel.Where(func).ToList();//item => item.GameStatus != 8 foreach (GameInfoModel gameInfoModel in list) { //如果日志不是空的 if (!string.IsNullOrEmpty(gameInfoModel.loginfo)) { NewGameViewModel newGameViewModel = new NewGameViewModel() { dropHour = 72, IsAllowLook = gameInfoModel.IsAllowLook, isHall = gameInfoModel.isHall, IsRandomOrder = gameInfoModel.IsRandomOrder, IsRotatoMap = gameInfoModel.IsRotatoMap, IsSocket = false, IsTestGame = gameInfoModel.IsTestGame == 1, jinzhiFaction = gameInfoModel.jinzhiFaction, MapSelction = gameInfoModel.MapSelction, Name = gameInfoModel.name }; GameMgr.CreateNewGame(gameInfoModel.userlist.Split('|'), newGameViewModel, out GaiaGame result); // GameMgr.CreateNewGame(gameInfoModel.name, gameInfoModel.userlist.Split('|'), out GaiaGame result, gameInfoModel.MapSelction, isTestGame: gameInfoModel.IsTestGame == 1 ? true : false,version:gameInfoModel.version); GaiaGame gg = GameMgr.GetGameByName(gameInfoModel.name); //gg.dbContext = this.dbContext; gg.GameName = gameInfoModel.name; if (gameInfoModel.saveState == 0) { gg.dbContext = this.dbContext; gg.IsSaveToDb = true; gameInfoModel.saveState = 1; } gg.UserActionLog = gameInfoModel.loginfo.Replace("|", "\r\n"); gg = GameMgr.RestoreGame(gameInfoModel.name, gg); //是否应该结束 if (this.FinishGame(gameInfoModel, gg)) { this.dbContext.GameInfoModel.Update(gameInfoModel); //没有找到任何的种族信息 if (!this.dbContext.GameFactionModel.Any(item => item.gameinfo_id == gameInfoModel.Id)) { //保存种族信息 DbGameSave.SaveFactionToDb(this.dbContext, gg, gameInfoModel); } else { //总局计分问题,需要重新计算 #if DEBUG DbGameSave.SaveFactionToDb(this.dbContext, gg, gameInfoModel); #endif } } //GameMgr.DeleteOneGame(gameInfoModel.name); } } this.dbContext.SaveChanges(); return("success"); }
public ActionResult NewGame(NewGameViewModel model) { var namesArray = model.Names .Split(new[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries) .Select(n => n.Trim()); string gameKey = _host.CreateNewGame(namesArray, model.NumberOfPlayers, model.ChosenCards, model.UseProsperty); return(this.RedirectToAction(x => x.ViewPlayers(gameKey))); }
public IActionResult New([FromBody] NewGameViewModel newGameViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _gameService.NewGame(newGameViewModel.BotCount); return(Ok()); }
public ActionResult New() { var gameGenres = _context.GameGenres.ToList(); var viewModel = new NewGameViewModel { GameGenres = gameGenres, }; return(View("New", viewModel)); }
public ActionResult New(NewGameViewModel viewModel) { //Validation - number must be 4 digits var newGame = this.gameService.NewGame(viewModel.Number); var gameViewModel = this.viewModelFactory.CreateGameViewModel(newGame.Id); return(View("Game", gameViewModel)); }
public IActionResult NewGame(NewGameViewModel ngvm) { Pokemon p = pokemonRepo.GetById(ngvm.PokemonId); if (homeRepo.LinkPokemonToAccount(ngvm.PokemonId, (int)HttpContext.Session.GetInt32("AccountID"))) { return(RedirectToAction("Index", "Gevecht")); } return(View()); }
public NewGameViewModel NewGameViewModel() { teamService = teamService ?? SetTeamService(); locationService = locationService ?? LocationService(); umpireService = umpireService ?? UmpireService(); if (newgameViewModel == null) { newgameViewModel = new NewGameViewModel(Client, matchService, teamService, locationService, umpireService); } return(newgameViewModel); }
private void InitializeViewModel() { if (_viewModel == null) { _viewModel = ForView.Unwrap <NewGameViewModel>(DataContext); if (_viewModel != null) { _viewModel.HideNewGame += HideNewGame; } } }
public ActionResult NewGame(NewGameViewModel viewModel) { if (this.ModelState.IsValid) { this.game.Start(viewModel.PlayerName); return(this.RedirectToAction("PlayGame")); } return(this.View(viewModel)); }
public void NewGame() { // delete cache of last game if (File.Exists(SESSION_CACHE_FILE)) { File.Delete(SESSION_CACHE_FILE); } // show new game dialog var dlg = new NewGameView(); var dlgContext = new NewGameViewModel(dlg); dlg.DataContext = dlgContext; var result = dlg.ShowDialog(); if (result == true) { // init new game session with user inputs from dialog var humanPlayer = new UIChessPlayer(dlgContext.DrawingSide); var artificialPlayer = new ArtificialChessPlayer(dlgContext.DrawingSide.Opponent(), dlgContext.Difficulty); _session = dlgContext.DrawingSide == ChessColor.White ? new ChessGameSession(humanPlayer, artificialPlayer) : new ChessGameSession(artificialPlayer, humanPlayer); _player = humanPlayer; _session.BoardChanged += boardChanged; Board.UpdatePieces(ChessBitboard.StartFormation); // tell the player which side he draws if he choose random side if (dlgContext.SelectedDrawingSideMode == DrawingSideMode.Random) { MessageBox.Show($"You draw the { dlgContext.DrawingSide.ToString() } pieces!", "Random Side Selection", MessageBoxButton.OK, MessageBoxImage.Information); } // update status bar Status.InitNewGame(); // start the game session in a background thread (async) Task.Run(() => { // play game (until one player loses) var final = _session.ExecuteGame(); // update status bar var finalStatus = ChessDrawSimulator.Instance.GetCheckGameStatus(_session.Board, _session.Game.LastDraw); Status.FinishGame(finalStatus); // reset game session Board.UpdateIsEnabled(false); }); } // make the chess board inactive unless a game session is active updateIsBoardActive(); }
public async Task <JsonResult> JoinGame(int id) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.Id == id); if (gameInfoModel != null) { //如果包括自己 if (this.User.Identity.Name == null) { jsonData.info.state = 400; jsonData.info.message = "没有登陆"; } else if (gameInfoModel.userlist.Contains(string.Format("|{0}|", this.User.Identity.Name))) { jsonData.info.state = 400; jsonData.info.message = "已经加入"; } else { gameInfoModel.userlist = gameInfoModel.userlist + this.User.Identity.Name + "|"; //判断是否满足人数,正式开始游戏 string[] username = gameInfoModel.userlist.Trim('|').Split('|'); if (username.Length == gameInfoModel.UserCount) { gameInfoModel.round = 0; NewGameViewModel newGameViewModel = new NewGameViewModel() { IsAllowLook = gameInfoModel.IsAllowLook, IsRandomOrder = gameInfoModel.IsRandomOrder, IsRotatoMap = gameInfoModel.IsRotatoMap, IsTestGame = gameInfoModel.IsTestGame == 1, MapSelction = gameInfoModel.MapSelction, Name = gameInfoModel.name, jinzhiFaction = gameInfoModel.jinzhiFaction, }; //创建游戏 GaiaGame gaiaGame; this.CreateGame(username, newGameViewModel, out gaiaGame); } this.dbContext.GameInfoModel.Update(gameInfoModel); this.dbContext.SaveChanges(); jsonData.info.state = 200; jsonData.info.message = "成功"; } } return(new JsonResult(jsonData)); }
public IActionResult NewGame() { Game game = new Game(); //DataManager.AddTeam(game.Code, game.Teams[0].TeamName); var viewModel = new NewGameViewModel() { GameCode = game.Code }; HttpContext.Session.SetString("GameCode", "TONIS"); HttpContext.Session.SetInt32("TeamCount", 0); return(View(viewModel)); }
public void ShouldInitializeWithAllFiguresSet() { // Given var expectedChessFigures = Enum.GetValues(typeof(FigureType)).Cast <FigureType>().ToArray(); // When var newGameViewModel = new NewGameViewModel(_playerViewModelFactory); newGameViewModel.Initialize(); // Then var actualChessFigures = newGameViewModel.Figures.ToArray(); Assert.IsTrue(expectedChessFigures.SequenceEqual(actualChessFigures)); }
public NewGameViewModel PokemonToNewGame(List <Pokemon> pokemon) { NewGameViewModel ngvm = new NewGameViewModel(); List <NewGameViewModel> viewModels = new List <NewGameViewModel>(); foreach (Pokemon tempPok in pokemon) { NewGameViewModel temp = new NewGameViewModel(); temp.Pokemon = PokemonViewModelConvert.PokemonToPokemonViewModel(tempPok); temp.Image = System.Convert.ToBase64String(tempPok.Uiterlijk); viewModels.Add(temp); } ngvm.RandomPokemon = viewModels.ToArray(); return(ngvm); }
public IActionResult NewGame() { if (HttpContext.Session.GetInt32("AccountID") == null) { return(RedirectToAction("Login", "Account")); } NewGameConvert pngc = new NewGameConvert(); List <int> allIds = homeRepo.GetAllId(); List <int> randomInts = homeRepo.XRandNum(allIds, 3); List <Pokemon> randomPok = homeRepo.GetPokemonWithIds(randomInts); NewGameViewModel ngvm = pngc.PokemonToNewGame(randomPok); return(View(ngvm)); }
public ActionResult NewGame(NewGameViewModel Model) { int gameId = 0; using (var data = new MakaoEntities()) { var game = new Game { NumOfPlayers = Model.NumOfPlayers, StartDate = DateTime.Now }; data.Games.Add(game); data.SaveChanges(); gameId = game.Id; } return(RedirectToAction("Players", "Home", new { Id = gameId })); }
public IActionResult NewGame(NewGameViewModel model) { if (ModelState.IsValid) { using (var db = new BlocXChangeDBContext()) { if (db.Games.FirstOrDefault(u => u.GameID == model.GameID) != null) // ID 중복 확인 { ModelState.AddModelError("", "다른 ID를 사용해주세요"); return(View(model)); } // ID 미 중복시 string newGameKey = RandomKey.GetRandomKey(6); while (db.Games.FirstOrDefault(u => u.GameKey == newGameKey) != null) { newGameKey = RandomKey.GetRandomKey(6); } Game newGame = new Game { GameID = model.GameID, GamePassword = model.GamePassword, GameKey = newGameKey, InitialTime = DateTime.Now, SuspendedTicks = 0 }; db.Games.Add(newGame); var GenData = new GenerateGameData(newGame); foreach (var i in GenData.GetStocks()) // 주가 데이터 생성 { db.Stocks.Add(i); } foreach (var i in GenData.GetFluctuations()) // 주가 변동 데이터 생성 { db.Fluctuations.Add(i); } db.SaveChanges(); HttpContext.Session.SetString("GAME_MASTER_KEY", newGameKey); return(Redirect("Play/?GameKey=" + newGameKey)); } } return(View(model)); }
public void ShouldGiveFigureTo1Player(FigureType expectedFigure) { // Given var newGameViewModel = new NewGameViewModel(_playerViewModelFactory); newGameViewModel.Initialize(); newGameViewModel.SelectedFigure = expectedFigure; // When newGameViewModel.GiveFigureToPlayer1Command.Execute(); newGameViewModel.GiveFigureToPlayer2Command.Execute(); // Then Assert.IsTrue(newGameViewModel.Player1.Figures.Last() == expectedFigure); Assert.IsTrue(newGameViewModel.Player2.Figures.Last() == expectedFigure); }
public ActionResult NewGame() { //this.Response.Cache.SetNoStore(); this.Response.Cache.SetCacheability(HttpCacheability.NoCache); var model = new NewGameViewModel(); model.CardsToChooseFrom = CardFactory.OptionalCardsForBank.OrderBy(c => c).ToList(); var random = new Random(); model.ChosenCards = model.CardsToChooseFrom.OrderBy(x => random.Next(100)).Take(10).ToList(); return(View(model)); }
public ActionResult CreateGame(NewGameViewModel viewModel) { if (!ModelState.IsValid) { return(View("CreateGame", viewModel)); } var player = _cookieManager.ExtractPlayerFromCookie(Request); var game = _gameFactory.Create(viewModel.Name); game.AddPlayer(player); game.StartGame(); _gameRepository.Add(game); return(RedirectToAction("Index", "Game", new { id = game.Id })); }
public void ShowNewGameDialog() { var gameRequest = new GameRequest(_gameSize); var newGameViewModel = new NewGameViewModel(); newGameViewModel.FromModel(gameRequest); var newGameWindow = new NewGameWindow(); newGameWindow.DataContext = newGameViewModel; if (newGameWindow.ShowDialog() == true) { var game = _factory.CreateGame(gameRequest); var gameModel = new GameModel(game, _defaultTimeToThink); _mainViewModel.FromModel(gameModel); } }
public ActionResult Edit(int id) { var game = _context.Games.SingleOrDefault(c => c.Id == id); if (game == null) { return(HttpNotFound()); } var viewModel = new NewGameViewModel(game) { GameGenres = _context.GameGenres.ToList(), Files = _context.Files.ToList() }; return(View("New", viewModel)); }
/// <summary> /// 创建游戏,从内存 /// </summary> private GaiaGame CreateGame(string[] username, NewGameViewModel model, out GaiaGame result) { //删除空白玩家 username = username.Where(x => !string.IsNullOrEmpty(x)).ToArray(); //随机排序 if (model.IsRandomOrder) { username = this.RandomSortList <string>(username).ToArray(); } //创建游戏 bool create = GameMgr.CreateNewGame(username, model, out result, _userManager: _userManager); if (!string.IsNullOrEmpty(model.jinzhiFaction)) { var list = new List <Faction>() { new Terraner(null), new Lantida(null), new Hive(null), new HadschHalla(null), new BalTak(null), new Geoden(null), new Gleen(null), new Xenos(null), new Ambas(null), new Taklons(null), new Firaks(null), new MadAndroid(null), new Itar(null), new Nevla(null) }; result.JinzhiFaction = new List <Faction>(); foreach (string name in model.jinzhiFaction.Split(',')) { result.JinzhiFaction.Add(list.Find(fac => fac.FactionName.ToString() == name)); } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="NewGameWindow"/> class. /// </summary> public NewGameWindow() { try { InitializeComponent(); errorLogViewModel = new ErrorLogViewModel(); newGameViewModel = new NewGameViewModel(); optionsViewModel = new OptionsViewModel(); this.Height = optionsViewModel.VerticalScaleNumber; this.Width = optionsViewModel.HorizontalScaleNumber; firstMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.FirstMapPath); secondMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.SecondMapPath); thirdMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.ThirdMapPath); fourthmapMap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.ForthMapPath); fifthmap_Diff.IsEnabled = newGameViewModel.FindMap(newGameViewModel.FifthMapPath); } catch { } }
/// <summary> /// 创建游戏 /// </summary> /// <param name="username"></param> /// <param name="model"></param> /// <param name="result"></param> /// <returns></returns> public static bool CreateNewGame(string[] username, NewGameViewModel model, out GaiaGame result, bool isSaveGame = false, UserManager <ApplicationUser> _userManager = null) { bool create = CreateNewGame(model.Name, username, out result, model.MapSelction, isTestGame: model.IsTestGame, isSocket: model.IsSocket, IsRotatoMap: model.IsRotatoMap, version: 4); if (_userManager != null) { //用户列表 List <UserGameModel> listUser = new List <UserGameModel>(); //判断用户不存在 foreach (var item in username) { var user = _userManager.FindByNameAsync(item); if (user.Result == null) { //ModelState.AddModelError(string.Empty, item + "用户不存在"); //return View("NewGame"); result = null; return(false); } else { listUser.Add(new UserGameModel() { username = item, isTishi = true, paygrade = user.Result.paygrade, scoreUserStart = user.Result.scoreUser, }); } } //赋值用户信息 result.UserGameModels = listUser; } result.dropHour = model.dropHour; if (isSaveGame) { } return(create); }