// GET: Games
        public ActionResult Coinflip()
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();

            if ((bool)Session["isLoggedIn"] == false)
            {
                return(RedirectToAction("/Index", "User"));
            }

            var myList = from cg in context.Games
                         where cg.Gametype == Game.GameEnum.Coinflip && cg.GameActive == true
                         orderby cg.Userbets.FirstOrDefault().Wager descending
                         select cg;

            string username = Session["username"].ToString();

            var getUser = from u in context.Users
                          where u.Username == username
                          select u;

            User user = getUser.FirstOrDefault();

            Session["credits"] = user.Credits;

            return(View(myList.ToList()));
        }
        public ActionResult ListCoinflipGames()
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();
            //context.Configuration.ProxyCreationEnabled = false;

            var myList = from cg in context.Games
                         where cg.Gametype == Game.GameEnum.Coinflip && cg.GameActive == true
                         orderby cg.Userbets.FirstOrDefault().Wager descending
                         select cg;

            List <object> takeThisJson = new List <object>();

            if (myList.Count() > 0)
            {
                foreach (var game in myList)
                {
                    var newGame = new
                    {
                        Creater    = game.users.FirstOrDefault().Username,
                        Wager      = game.Userbets.FirstOrDefault().Wager,
                        GameId     = game.Id,
                        ShortDate  = game.Timestamp.ToShortDateString(),
                        ShortTime  = game.Timestamp.ToShortTimeString(),
                        PictureURL = game.users.FirstOrDefault().Picture
                    };
                    takeThisJson.Add(newGame);
                }
            }



            return(Json(new { activeCoinflipGame = takeThisJson },
                        JsonRequestBehavior.AllowGet));
        }
示例#3
0
        // GET: Api
        public ActionResult AmountPaidOut(string callback)
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();
            var TotalWon = from w in context.Winners
                           select w.TotalAmount;

            double wins = 0.00;

            Math.Round(wins, 2);

            foreach (var win in TotalWon)
            {
                //Tar ut credits i valuta
                wins += win;
            }

            if (TotalWon.Count() > 0)
            {
                return(Json(wins, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("No wins found ", JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
        public ActionResult Login()
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();


            string username = Request["inputUsername"];
            string password = Request["inputPassword"];

            var userList = from u in context.Users
                           where u.Username == username.Trim()
                           select u;


            if (userList.Count() == 1)
            {
                if (userList.First().Password == password)
                {
                    Session["isLoggedIn"] = true;
                    Session["username"]   = username;
                    Session["credits"]    = userList.First().Credits;

                    return(RedirectToAction("/Coinflip", "Games"));
                }
                else
                {
                    ViewBag.Wrong = "Wrong username or password";
                } //Right username, wrong password
            }     //No user with inputted username
            else
            {
                //ViewBag.Wrong = "Wrong username or password";
            }
            return(View("Index"));
        }
        public ActionResult PlayCoinflipJson(int?gameId)
        {
            if (gameId != null)
            {
                WinFastLoseFasterContext context = new WinFastLoseFasterContext();

                var gameToPlay = context.Games.Find(gameId);
                if (gameToPlay != null)
                {
                    object takeThisJson;

                    if (gameToPlay.GameActive == true)
                    {
                        User creater = gameToPlay.users.FirstOrDefault();

                        takeThisJson = new
                        {
                            gameId          = gameToPlay.Id,
                            gameActive      = gameToPlay.GameActive,
                            CreaterUsername = creater.Username,
                            CreaterPicture  = creater.Picture,
                            JoinerUsername  = "",
                            JoinerPicture   = "",
                            WinnerUsername  = "",
                            WinnerPicture   = "",
                            Wager           = gameToPlay.Userbets.FirstOrDefault().Wager
                        };
                    }
                    else
                    {
                        User creater = gameToPlay.users.FirstOrDefault();
                        User joiner  = gameToPlay.users.LastOrDefault();
                        User winner  = gameToPlay.Winners.FirstOrDefault().WinningUser;

                        takeThisJson = new
                        {
                            gameId          = gameToPlay.Id,
                            gameActive      = gameToPlay.GameActive,
                            CreaterUsername = creater.Username,
                            CreaterPicture  = creater.Picture,
                            JoinerUsername  = joiner.Username,
                            JoinerPicture   = joiner.Picture,
                            WinnerUsername  = winner.Username,
                            WinnerPicture   = winner.Picture,
                            Wager           = gameToPlay.Userbets.FirstOrDefault().Wager
                        };
                    }

                    return(Json(new { activeCoinflipGame = takeThisJson },
                                JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(RedirectToAction("/Coinflip", "Games"));
            }

            return(RedirectToAction("/Coinflip", "Games"));
        }
示例#6
0
        public ActionResult Bank()
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();

            string loggedInUser = (string)Session["username"];

            var myUserList = from u in context.Users
                             where u.Username == loggedInUser
                             select u;

            User user = myUserList.First();

            string deposit    = Request["deposit"];
            string withdrawal = Request["withdrawal"];

            int d = 0;
            int w = 0;

            int.TryParse(deposit, out d);
            int.TryParse(withdrawal, out w);

            if (!int.TryParse(deposit, out d))
            {
                ViewBag.letter = "Not allowed letters";
            }
            else if (d > 1000)
            {
                ViewBag.tooMuch = "Max amount is 1000";
            }
            else if (d < 1)
            {
                ViewBag.less = "Less then 0 not acceptable";
            }
            else
            {
                user.Deposit += d;
                user.Credits += d;
            }

            if (w > user.Credits)
            {
                ViewBag.tooCredits = "Not enought credits";
            }
            else if (w < 1)
            {
                ViewBag.less = "Less then 0 not acceptable";
            }
            else
            {
                user.Withdrawal += w;
                user.Credits    -= w;
            }

            context.SaveChanges();

            return(RedirectToAction("/Profile", "Profile"));

            //return View();
        }
示例#7
0
        public ActionResult ChangeProfilePicture()
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();

            string username = Session["username"].ToString();

            string newProfilePictureUrl = Request["newProfilePicture"];

            if (string.IsNullOrWhiteSpace(newProfilePictureUrl) == false)
            {
                var getUser = from u in context.Users
                              where u.Username == username
                              select u;

                User user = getUser.FirstOrDefault();

                user.Picture = newProfilePictureUrl;

                context.SaveChanges();
            }


            return(RedirectToAction("/Profile", "Profile"));
        }
        public ActionResult CreateCoinflip()
        {
            WinFastLoseFasterContext context = new WinFastLoseFasterContext();

            string strWager    = Request["TextSum"];
            int    wager       = 0;
            string createrName = (string)Session["username"];


            if (!int.TryParse(strWager, out wager))
            {
                return(RedirectToAction("/Coinflip", "Games"));
            }

            var myUserList = from u in context.Users
                             where u.Username == createrName
                             select u;

            //var myUserList = from u in context.Users
            //                 select u;

            User creater = myUserList.First();

            if (creater.Credits < wager)
            {
                return(RedirectToAction("/Coinflip", "Games"));
            }//User doesn't have enough Credits to create the game

            List <User> user = new List <User>()
            {
                creater
            };

            Game newGame = new Game()
            {
                Timestamp = DateTime.Now, Gametype = Game.GameEnum.Coinflip, GameActive = true, users = user
            };

            context.Games.Add(newGame);
            context.SaveChanges();

            List <Bet> bets = new List <Bet>()
            {
                new Bet {
                    user = creater, game = newGame, Wager = wager
                }
            };

            context.Bets.Add(bets.First());

            creater.Credits   -= bets.First().Wager;
            Session["credits"] = creater.Credits;

            newGame.Userbets = bets;

            context.SaveChanges();


            return(RedirectToAction("PlayCoinflip", "Games", new { gameId = newGame.Id }));
            //return RedirectToAction("Coinflip", "Games");
        }
        public ActionResult JoinCoinflip()
        {
            string strCoinflipGameId = Request["coinflipGameId"];
            string username          = (string)Session["username"];

            Random rnd = new Random();

            int coinflipGameId = 0;

            if (!int.TryParse(strCoinflipGameId, out coinflipGameId))
            {
                return(RedirectToAction("Coinflip", "Games"));
            }//Check if coinflipGameId is int


            WinFastLoseFasterContext context = new WinFastLoseFasterContext();


            var gameJoinList = from g in context.Games
                               where g.Id == coinflipGameId
                               select g;


            Game gameToJoin = gameJoinList.FirstOrDefault();


            var userJoinList = from u in context.Users
                               where u.Username == username
                               select u;



            User creater = gameToJoin.users.FirstOrDefault();
            User joiner  = userJoinList.FirstOrDefault();

            if (creater.Username == joiner.Username)
            {
                return(RedirectToAction("/PlayCoinflip", "Games", new { gameId = gameToJoin.Id }));
            }//Användaren försöker spela mot sig själv, som man inte får.

            List <User> usersToPlay = new List <User>()
            {
                creater, joiner
            };

            List <Bet> bets = gameToJoin.Userbets.ToList();

            int wager = bets.FirstOrDefault().Wager;

            if (joiner.Credits < wager)
            {
                return(RedirectToAction("/Index", "Home"));
            }//joining player doesn't have enough credits to join the coinflip and gets redirected back to home/Index

            if (gameToJoin.GameActive == false)
            {
                return(RedirectToAction("/Coinflip", "Ganes"));
            }//Check if gameActive is false, if so, they can't join it.


            Bet newBet = new Bet()
            {
                game = gameToJoin, user = joiner, Wager = wager
            };

            bets.Add(newBet);

            joiner.Credits -= wager;

            int totalAmount = (int)((bets.First().Wager + bets.Last().Wager));

            List <Winner> winner = new List <Winner>();

            winner.Add(new Winner {
                game = gameToJoin, TotalAmount = (int)((totalAmount) /** 0.97*/)
            });

            if (rnd.Next(101) < 50)
            {
                winner.FirstOrDefault().WinningUser = creater;
                creater.Credits += totalAmount;
            }
            else
            {
                winner.FirstOrDefault().WinningUser = joiner;
                joiner.Credits += totalAmount;
            }

            gameToJoin.Timestamp  = DateTime.Now;
            gameToJoin.GameActive = false;
            gameToJoin.Winners    = winner;
            gameToJoin.users      = usersToPlay;
            gameToJoin.Userbets   = bets;

            //Session["credits"] = joiner.Credits;

            context.Winners.Add(winner.FirstOrDefault());

            context.Bets.Add(newBet);

            context.SaveChanges();


            return(RedirectToAction("PlayCoinflip", "Games", new { gameId = gameToJoin.Id }));
            //return RedirectToAction("/Coinflip", "Games");
            //return View();
        }
示例#10
0
        public ActionResult Register()
        {
            int faults = 0;

            using (WinFastLoseFasterContext context = new WinFastLoseFasterContext())
            {
                Random rnd = new Random();

                List <string> profilePictures = new List <string>()
                {
                    "http://orig04.deviantart.net/77b2/f/2010/215/7/b/43___fsjal_wason__by_ztoonlinkz.png",
                    "http://i0.kym-cdn.com/photos/images/facebook/000/841/850/42c.jpg",
                    "http://i3.kym-cdn.com/photos/images/original/000/013/251/lenny_fsjal.jpg",
                    "http://orig07.deviantart.net/94d2/f/2014/212/8/0/fsjal_squirtle_by_toonstar96-d7t4sie.png",
                    "http://orig11.deviantart.net/4b44/f/2015/304/0/3/the_flash_fsjal___flasjal_by_limedraagon-d9eziqk.jpg",
                    "https://c1.staticflickr.com/5/4098/4806016720_46eed66416.jpg",
                    /*"http://img04.deviantart.net/840f/i/2015/359/f/2/hitler_fsjal_by_gnay12-d9lfrzc.jpg",*/
                    "http://vignette3.wikia.nocookie.net/peido/images/a/a1/Fsjal_spongebob.png/revision/latest?cb=20110801205739",
                    "http://vignette1.wikia.nocookie.net/creepypasta/images/0/09/FSJAL_Link_by_Lucas47_46.jpg/revision/latest?cb=20131113024225",
                    "http://orig11.deviantart.net/4320/f/2015/289/a/6/fsjal_terror_inferno_with_ak_by_gibiart-d9d9sf6.png",
                    "http://orig00.deviantart.net/be69/f/2009/298/5/6/batman_fsjal_by_spidernaruto.jpg",
                    "http://i3.kym-cdn.com/photos/images/newsfeed/000/006/647/iron_man20110724-22047-vhlnn6.png",
                    "http://orig09.deviantart.net/35fd/f/2010/193/5/e/13___fsjal_homer_jay_simpson__by_ztoonlinkz.png",
                    "https://c2.staticflickr.com/4/3312/5833167537_2ab677d082.jpg",
                    "http://orig05.deviantart.net/1b89/f/2011/322/1/0/captain_america_fsjal_by_xian_the_miguel-d4gl5dw.png",
                    "http://orig06.deviantart.net/6a87/f/2013/046/f/2/snorlax_fsjal_by_zunyokingdom-d5v3nfp.jpg",
                    "http://orig01.deviantart.net/d6ca/f/2010/077/0/b/plastic_soldier_fsjal_by_platinumglitchmint.jpg",
                    "http://orig08.deviantart.net/8cbc/f/2010/199/0/6/23___fsjal_yoshi__by_ztoonlinkz.png",
                    "https://pbs.twimg.com/media/BJXYR9sCUAArAO-.jpg"
                };


                string username  = Request["inputUsername"];
                string password  = Request["inputPassword"];
                string password2 = Request["inputRetypePassword"];
                string email     = Request["inputEmail"];
                string checkbox  = Request["inputCheckbox"];



                if (username.Trim().Length < 3)
                {
                    faults++;
                }

                if (username.Trim().Length > 15)
                {
                    faults++;
                }

                if (password.Trim().Length < 6)
                {
                    faults++;
                }

                if (password != password2)
                {
                    faults++;
                }

                if (email.Length == 0)
                {
                    faults++;
                }

                if (checkbox == "false")
                {
                    faults++;
                }

                var userList = from u in context.Users
                               where u.Username == username
                               select u;

                var emailList = from e in context.Users
                                where e.Mail == email
                                select e;

                if (emailList.Count() > 0)
                {
                    //Email is taken.
                    faults++;
                }

                if (userList.Count() > 0)
                {
                    //There's already a user with that username
                    faults++;
                }


                if (faults == 0)
                {
                    User userToAdd = new User()
                    {
                        Username = username.Trim(), Password = password, Mail = email, Credits = 1000, Deposit = 0, Withdrawal = 0, Games = { }, bets = { }
                    };
                    userToAdd.Picture = profilePictures.ElementAt(rnd.Next(profilePictures.Count));

                    context.Users.Add(userToAdd);
                    context.SaveChanges();

                    Session["isLoggedIn"] = true;
                    Session["username"]   = username.Trim();
                    Session["credits"]    = userToAdd.Credits;
                }
            }
            if (faults == 0)
            {
                return(RedirectToAction("/Index", "Home"));
            }
            else
            {
                return(RedirectToAction("/Index", "User"));
            }
        }
示例#11
0
        // GET: Profil
        public ActionResult Profile()
        {
            bool isLoggedIn = (bool)Session["isLoggedIn"];

            if (isLoggedIn)
            {
                WinFastLoseFasterContext context = new WinFastLoseFasterContext();

                string loggedInUser = (string)Session["username"];

                var myUserList = from u in context.Users
                                 where u.Username == loggedInUser
                                 select u;

                User user = myUserList.First();

                Session["credits"] = user.Credits;

                var numberOfWins = from n in context.Winners
                                   where n.WinningUser.Id == user.Id
                                   select n;

                var amountWon = from a in context.Winners
                                where a.WinningUser.Username == user.Username
                                select a.TotalAmount;

                var betAmount = from b in context.Bets
                                where b.user.Username == user.Username
                                select b.Wager;

                var inactiveGames = from a in user.Games
                                    where a.GameActive == false
                                    select a;

                var amountLost = from a in inactiveGames
                                 where a.Winners.FirstOrDefault().WinningUser != user
                                 select a.Userbets.FirstOrDefault().Wager;

                //var winBetAmount = from w in context.Bets
                //                   where w.user.Username == user.Username
                //                   where w.game.Winners == user
                //                   select w.Wager;

                var notActiveGames = from l in user.Games
                                     where l.GameActive != true
                                     select l;

                int matchesLost = notActiveGames.Count() - numberOfWins.Count();

                int    bets      = 0;
                int    won       = 0;
                double loss      = 0.00;
                double wonAmount = 0.00;

                foreach (var bet in betAmount)
                {
                    bets += bet;
                }

                foreach (var wins in amountWon)
                {
                    won       += wins;
                    wonAmount += (wins / 2) /** 0.97*/;
                }

                foreach (var l in amountLost)
                {
                    loss -= l;
                }

                //foreach (var losses in amountLost)
                //{
                //    loss -= losses;
                //}

                List <Game> myGames = new List <Game>();

                foreach (Game game in user.Games.AsEnumerable())
                {
                    myGames.Add(game);
                }

                if (matchesLost == 0)
                {
                    if (numberOfWins.Count() == 0)
                    {
                        ViewBag.WLR = 1;
                    }
                    else
                    {
                        ViewBag.WLR = Math.Round((double)numberOfWins.Count() / 1, 2);
                    }
                }
                else
                {
                    ViewBag.WLR = Math.Round((double)numberOfWins.Count() / matchesLost, 2);
                }

                if (double.IsNaN(ViewBag.WLR))
                {
                    ViewBag.WLR = 1;
                }

                ViewBag.Picture  = user.Picture;
                ViewBag.Username = user.Username;
                ViewBag.Wins     = numberOfWins.Count();
                ViewBag.Loss     = matchesLost;
                ViewBag.Profit   = Math.Round(loss + wonAmount, 0);
                ViewBag.Credits  = user.Credits;

                ViewBag.amountWon     = Math.Round(wonAmount, 0);
                ViewBag.currentUser   = user;
                ViewBag.BetsAmount    = bets;
                ViewBag.Deposit       = user.Deposit;
                ViewBag.Withdrawal    = user.Withdrawal;
                ViewBag.myGames       = user.Games.OrderByDescending(g => g.Timestamp);
                ViewBag.MatchesPlayed = user.Games.Count();
                ViewBag.amountLost    = loss;
            }
            else
            {
                return(RedirectToAction("/Index", "User"));
            }
            return(View());
        }