Пример #1
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();
        }
Пример #2
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();
        }
Пример #5
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"));
            }
        }