Beispiel #1
0
        static void Main(string[] args)
        {
            //JOIN GAME
            GameBAL g_bal = new GameBAL();

            try
            {
                var gameURL = g_bal.JoinGame("11", "4");
                Console.WriteLine("game url: {0}", gameURL);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            ////NEW GAME
            //GameBAL g_bal = new GameBAL();
            //try
            //{
            //    var gameURL = g_bal.NewGame(4);
            //    Console.WriteLine("game url: {0}", gameURL);
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}

            ////LOGIN
            //UserBAL u_bal = new UserBAL();
            //try
            //{
            //    var user = u_bal.ValidateUser("Alice", "alice");
            //    if (user == null)
            //        Console.WriteLine("Invalid Credentials");
            //    else
            //        Console.WriteLine("Welcome, {0}!", user.UserName);
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}

            ////REGISTER
            //UserBAL u_bal = new UserBAL();
            //try
            //{
            //    var user = u_bal.AddUser("Eve", "*****@*****.**", "eve");
            //    if (user != null)
            //        Console.WriteLine("User Created");
            //    else
            //        Console.WriteLine("not created.");
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}
        }
Beispiel #2
0
        // Get: Join/{hashedGameId}
        public ActionResult Join(string hashedGameId)
        {
            try
            {
                GameBAL gbal   = new GameBAL();
                var     gameId = gbal.JoinGame(hashedGameId, Session["UserId"].ToString());
                TempData["IsSuccess"] = "success";
                TempData["Message"]   = "You have joined the game.";

                var hub = GlobalHost.ConnectionManager.GetHubContext <GameRoomHub>();
                hub.Groups.Add(Session["UserId"].ToString(), gameId);
                hub.Clients.Group(gameId).addNewMessageToPage(Session["UserName"].ToString() + " joined the game.");
                return(RedirectToAction("Game", "Game", new { hashedGameId = gameId }));
            }
            catch (Exception e)
            {
                TempData["IsSuccess"] = "danger";
                TempData["Message"]   = e.Message;
                ModelState.AddModelError("", e.Message);
                return(RedirectToAction("Index"));
            }
        }