public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
        {
            if (id != movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
예제 #2
0
        /// <summary>
        /// ゲームのメインルーチン
        /// </summary>
        /// <param name="player1Id"></param>
        /// <param name="player2Id"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public async Task <Game> GameAsync(
            string player1Id,
            string player2Id,
            string method)
        {
            if (string.IsNullOrEmpty(player2Id))
            {
                player2Id = Const.COM_NAME_DB;
            }

            bool isAIAuto = true;

            if (method == "コンピューター")
            {
                isAIAuto = false;
            }

            Game game = await _context.Game.Where(x =>
                                                  x.Player1Id == player1Id && x.Player2Id == player2Id)
                        .SingleOrDefaultAsync();

            OffenceModeEnum offenceMode = method.GetOffenceMode();

            switch (offenceMode)
            {
            case OffenceModeEnum.Run:
            case OffenceModeEnum.ShortPass:
            case OffenceModeEnum.LongPass:
            case OffenceModeEnum.Pant:
            case OffenceModeEnum.Kick:
            case OffenceModeEnum.Cpu:
                if (offenceMode == OffenceModeEnum.Cpu)
                {
                    int i        = 0;
                    int currentQ = game.CurrentQuarter;
                    while (i < 1000 &&
                           game.CurrentPlayer == 2 &&
                           game.CurrentQuarter == currentQ &&
                           game.RemainSeconds > 0)
                    {
                        i++;
                        offenceMode = _AIThink(game);
                        _Offence(offenceMode, game);
                        if (!isAIAuto)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    _Offence(offenceMode, game);
                }
                _context.Update(game);
                await _context.SaveChangesAsync();

                break;

            case OffenceModeEnum.Empty:
            case OffenceModeEnum.Initialize:
            default:
                if (game != null && offenceMode == OffenceModeEnum.Initialize)
                {
                    _context.Remove(game);
                    game = null;
                }
                if (game == null)
                {
                    game           = InitializeGame();
                    game.Player1Id = player1Id;
                    game.Player2Id = player2Id;
                    _context.Update(game);
                    await _context.SaveChangesAsync();
                }
                break;
            }

            return(game);
        }