예제 #1
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);
        }
예제 #2
0
        public ActionResult ChosenGame(int gameID)
        {
            TempData["Play"] = true;
            PlayGameVM playGame = Game.SelectGame(gameID);

            playGame.AllGames = Game.GetMyGames((int)Session["ID"]);
            return(View("PlayGame", playGame));
        }
예제 #3
0
        private void AddScore(PlayGameVM playGame, int userProfileID)
        {
            var game = Game.GetGameByID(playGame.GameID);

            game.Score     += (playGame.Word.Length * 5);
            game.LastLetter = playGame.Word[(playGame.Word.Length - 1)].ToString();
            NextTurn(game, userProfileID);
        }
예제 #4
0
        public ActionResult PlayGame()
        {
            TempData["Play"] = false;
            PlayGameVM playGame = new PlayGameVM()
            {
                AllGames = Game.GetMyGames((int)Session["ID"])
            };

            return(View(playGame));
        }
예제 #5
0
        public void AddWord(PlayGameVM playGame, int userProfileID)
        {
            WordBankVM wordBank = new WordBankVM()
            {
                Words  = playGame.Word,
                GameID = playGame.GameID
            };

            AddScore(playGame, userProfileID);
            WordBank.AddWordBank(wordBank);
        }
예제 #6
0
 public ActionResult PlayGame(PlayGameVM playGame)
 {
     if (ModelState.IsValid)
     {
         if (WordBank.NewWord(playGame.Word, playGame.GameID))
         {
             Game.AddWord(playGame, (int)Session["ID"]);
             return(RedirectToAction("PlayGame", "Game", new { area = "" }));
         }
         else
         {
             Game.WinLoss(playGame, (int)Session["ID"]);
             return(RedirectToAction("PlayGame", "Game", new { area = "" }));
         }
     }
     else
     {
         return(View("PlayGame"));
     }
 }
        public IActionResult PlayGame(int id, string command, string buffer)
        {
            var _playgame = new PlayGameVM
            {
                GameID = id.ToString().Trim()
            };

            //Check to see if the player has an active game
            string _InstanceID = HttpContext.Session.GetString("InstanceID");

            if (_InstanceID == "-1") // If no active game then crete a new game
            {
                var gameMove = _adventureController.NewGameByID(id);
                HttpContext.Session.SetString("InstanceID", gameMove.InstanceID.ToString());
                _playgame.Buffer       = "";
                _playgame.RoomName     = gameMove.RoomName;
                _playgame.Message      = gameMove.RoomMessage;
                _playgame.Items        = gameMove.ItemsMessage;
                _playgame.HealthReport = "Good To Go!";
                _playgame.GamerTag     = gameMove.PlayerName;

                return(View("playgame", _playgame));
            }

            // clean up the command
            if (command == null)
            {
                command = "";
            }
            else
            {
                var clen = command.Length;
                if (clen > 64)
                {
                    clen = 64;
                }
                command = command.Substring(0, clen); // limit the input length
            }

            var move = new GameMove
            {
                Move       = command,
                InstanceID = _InstanceID
            };

            var gmr = _adventureController.GameMove(move);

            // Set the Instance ID in the session
            HttpContext.Session.SetString("InstanceID", gmr.InstanceID.ToString());

            // map the game move result to the output view model
            _playgame.RoomName     = gmr.RoomName;
            _playgame.Message      = gmr.RoomMessage;
            _playgame.Items        = gmr.ItemsMessage;
            _playgame.HealthReport = gmr.HealthReport;
            _playgame.GamerTag     = gmr.PlayerName;

            // add the command to the buffer. The greater than below is the command prompt
            string newbuffer;

            newbuffer        = buffer + "\r\n>" + command + "\r\n";
            _playgame.Buffer = newbuffer;

            return(View("playgame", _playgame));
        }