Exemple #1
0
        public async Task <IActionResult> Finalise2(int id, [Bind("Id,ActiveTeamNS,Value,Challenge,Contra,Kaput,NorthSouthPoints,EastWestPoints,NorthSouthExtras,EastWestExtras,NorthSouthScore,EastWestScore,MatchBId")] GameB game)
        {
            if (id != game.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(game);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameExists(game.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                Response.Redirect("/../../MatchesB/CompleteGame/" + id);
                errorView = new ErrorViewModel();
                return(View("Error", errorView));
            }
            return(View(game));
        }
Exemple #2
0
        public async Task ShootEventB(string id)
        {
            HttpResponse response = Response;

            response.Headers.Add("Content-Type", "text/event-stream");

            for (var i = 0; true; ++i)
            {
                GameB game = _context.GameB.AsNoTracking().Where(m => m.MatchBId == id).OrderByDescending(g => g.Id).Take(1)
                             .Include(g => g.HandInPlay).ThenInclude(h => h.Cards)
                             .ToList()[0];

                if (game.HandInPlay == null)
                {
                    await response
                    .WriteAsync($"data:0\n\n");
                }
                else
                {
                    await response
                    .WriteAsync($"data:" + game.HandInPlay.Cards.Count().ToString() + "\n\n");
                }

                sMessage = "";

                await Task.Delay(3000);
            }
            response.Body.Flush();
        }
Exemple #3
0
        public async Task <IActionResult> CompleteGame(string id)
        {
            var match = _context.MatchB.Include(o => o.Games).Include(o => o.North).Include(o => o.South).Include(o => o.East).Include(o => o.West).Include(m => m.Games).Include(m => m.LastHand)
                        .FirstOrDefault(m => m.Id == id);

            match.LastHand.Cards = _context.CardB.Where(c => c.HandBId == match.LastHand.Id).OrderBy(c => c.Sequence).ToList();

            GameB game = _context.GameB.Where(m => m.MatchBId == match.Id).OrderByDescending(g => g.Id).Take(1)
                         .Include(o => o.NorthHand).Include(o => o.SouthHand).Include(o => o.EastHand).Include(o => o.WestHand)
                         .Include(o => o.HandInPlay)
                         .Include(o => o.NorthSouthHandResult)
                         .Include(o => o.EastWestHandResult)
                         .ToList()[0];

            game.Status = "Completed";

            GameB newGame = new GameB();

            match.Games.Add(newGame);
            match.LastHand.Cards.Clear();
            _context.SaveChanges();

            if (game.Dealer.Id == game.North.Id)
            {
                newGame.Dealer = game.East;
            }
            else
            {
                if (game.Dealer.Id == game.East.Id)
                {
                    newGame.Dealer = game.South;
                }
                else
                {
                    if (game.Dealer.Id == game.South.Id)
                    {
                        newGame.Dealer = game.West;
                    }
                    else
                    {
                        newGame.Dealer = game.North;
                    }
                }
            }
            newGame.North  = match.North;
            newGame.South  = match.South;
            newGame.East   = match.East;
            newGame.West   = match.West;
            newGame.Type   = "";
            newGame.Value  = 0;
            newGame.Status = "Dealing";
            match          = _context.MatchB.FirstOrDefault(m => m.Id == id);
            _context.SaveChanges();
//            Response.Redirect("/../../Matches/Play/" + id);
            Response.Redirect("/../../MatchesB/Play?id=" + id + "&deal=true");
            errorView = new ErrorViewModel();
            return(View("Error", errorView));
        }
Exemple #4
0
        public async Task <IActionResult> SetFirstDealerTempData(string MatchId, string FirstDealer)
        {
            MatchB match = new MatchB();

            match       = _context.MatchB.Include(o => o.Games).Include(p => p.North).Include(p => p.South).Include(p => p.East).Include(p => p.West).FirstOrDefault(m => m.Id == MatchId);
            match.Games = new List <GameB>();
            GameB game = new GameB();

            game.Id     = 0;
            game.Dealer = _context.Player.FirstOrDefault(p => p.Id == FirstDealer);
            game.North  = match.North;
            game.South  = match.South;
            game.East   = match.East;
            game.West   = match.West;
            if (game.Dealer.Id == game.North.Id)
            {
                game.NextPlayer = game.East;
            }
            else
            {
                if (game.Dealer.Id == game.East.Id)
                {
                    game.NextPlayer = game.South;
                }
                else
                {
                    if (game.Dealer.Id == game.South.Id)
                    {
                        game.NextPlayer = game.West;
                    }
                    else
                    {
                        game.NextPlayer = game.North;
                    }
                }
            }
            game.Type   = "";
            game.Value  = 0;
            game.Status = "Dealing";
            match       = _context.MatchB.FirstOrDefault(m => m.Id == MatchId);
            match.Games.Add(game);
            match.LastHand       = new HandB();
            match.LastHand.Id    = match.Id;
            match.LastHand.Cards = new List <CardB>();
            _context.SaveChanges();

            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            string UUID = currentUser.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            ViewBag.Dealer = FirstDealer;
            ViewBag.Player = UUID;
            Response.Redirect("/../../MatchesB/Play/" + MatchId);
            return(View("MatchPlay", match));
        }
Exemple #5
0
        // POST: Games/Edit/5
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
//        [HttpPost]
//        [ValidateAntiForgeryToken]
        public async Task <IActionResult> Finalise(int Id, int NorthSouthScore, int EastWestScore, int NorthSouthExtras, int EastWestExtras)
        {
            GameB game = _context.GameB.Where(m => m.Id == Id).OrderByDescending(g => g.Id).Take(1)
                         .ToList()[0];

            game.NorthSouthScore  = NorthSouthScore;
            game.EastWestScore    = EastWestScore;
            game.NorthSouthExtras = NorthSouthExtras;
            game.EastWestExtras   = EastWestExtras;

            try
            {
                _context.Update(game);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(game.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            MatchB match = _context.MatchB.Where(m => m.Id == game.MatchBId).Take(1)
                           .ToList()[0];

            match.NorthSouthScore = match.NorthSouthScore + NorthSouthScore;
            match.EastWestScore   = match.EastWestScore + EastWestScore;

            try
            {
                _context.Update(match);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            Response.Redirect("/../../MatchesB/CompleteGame/" + game.MatchBId);
            errorView = new ErrorViewModel();
            return(View("Error", errorView));
        }
Exemple #6
0
        public async Task <IActionResult> FinaliseGame(string id)
        {
            var match = _context.MatchB.Include(o => o.Games).Include(o => o.North).Include(o => o.South).Include(o => o.East).Include(o => o.West).Include(o => o.LastHand)
                        .ThenInclude(h => h.Cards)
                        .FirstOrDefault(m => m.Id == id);

            GameB game = _context.GameB.Where(m => m.MatchBId == id).OrderByDescending(g => g.Id).Take(1)
                         .Include(o => o.North).Include(o => o.South).Include(o => o.East).Include(o => o.West)
                         .Include(o => o.NorthSouthHandResult).ThenInclude(q => q.Cards)
                         .Include(o => o.EastWestHandResult).ThenInclude(q => q.Cards)
                         .ToList()[0];

            game.Status = "Finalising";

            _context.SaveChanges();

            return(View("Finalise", game));
        }
Exemple #7
0
        public async Task ShootEvent(string id)
        {
            var response = Response;

            response.Headers.Add("Content-Type", "text/event-stream");

            for (var i = 0; true; ++i)
            {
                GameB game = _context.GameB.AsNoTracking().Where(m => m.MatchBId == id).OrderByDescending(g => g.Id).Take(1)
                             .ToList()[0];

                await response
                .WriteAsync($"data:" + game.Status + "\r\r");

                await Task.Delay(100);
            }
            response.Body.Flush();
        }
Exemple #8
0
        public GameB Collect(GameB game, string move = "")
        {
            var match = _context.MatchB
                        .FirstOrDefault(m => m.Id == game.MatchBId);

            if (true)
            //                if (move == "collect")
            {
                if (match.LastHand == null)
                {
                    match.LastHand       = new HandB();
                    match.LastHand.Id    = match.Id;
                    match.LastHand.Cards = new List <CardB>();
                }
                else
                {
                    match.LastHand.Cards.Clear();
                }
                foreach (var card in game.HandInPlay.Cards)
                {
                    var _card = new CardB();
                    _card.Id        = Guid.NewGuid().ToString();
                    _card.Colour    = card.Colour;
                    _card.Value     = card.Value;
                    _card.Sequence  = card.Sequence;
                    _card.Seniority = card.Seniority;
                    match.LastHand.Cards.Add(_card);
                    if ((game.NextPlayer.Id == game.North.Id) || (game.NextPlayer.Id == game.South.Id))
                    {
                        game.NorthSouthPoints = game.NorthSouthPoints + CardValue(game.Type, _card);
                    }
                    else
                    {
                        game.EastWestPoints = game.EastWestPoints + CardValue(game.Type, _card);
                    }
                }
                if ((game.NextPlayer.Id == game.North.Id) || (game.NextPlayer.Id == game.South.Id))
                {
                    if (game.NorthHand.Cards.Count == 0)
                    {
                        game.NorthSouthPoints = game.NorthSouthPoints + 10;
                    }
                }
                else
                {
                    if (game.NorthHand.Cards.Count == 0)
                    {
                        game.EastWestPoints = game.EastWestPoints + 10;
                    }
                }
                game.Status = "Playing";
                if ((game.HighCardPlayer.Id == game.North.Id) || (game.HighCardPlayer.Id == game.South.Id))
                {
                    if (game.NorthSouthHandResult == null)
                    {
                        game.NorthSouthHandResult       = new HandB();
                        game.NorthSouthHandResult.Id    = Guid.NewGuid().ToString();
                        game.NorthSouthHandResult.Cards = new List <CardB>();
                    }
                    foreach (CardB card in game.HandInPlay.Cards)
                    {
                        game.NorthSouthHandResult.Cards.Add(card);
                    }
                    game.HandInPlay.Cards.Clear();
                }
                else
                {
                    if (game.EastWestHandResult == null)
                    {
                        game.EastWestHandResult       = new HandB();
                        game.EastWestHandResult.Id    = Guid.NewGuid().ToString();
                        game.EastWestHandResult.Cards = new List <CardB>();
                    }
                    foreach (CardB card in game.HandInPlay.Cards)
                    {
                        game.EastWestHandResult.Cards.Add(card);
                    }
                    game.HandInPlay.Cards.Clear();
                }
                if (game.NorthHand.Cards.Count == 0)
                {
                    game.Status = "Finalising";
                }
            }
            return(game);
        }
Exemple #9
0
        public async Task <IActionResult> Play(string id, string move = "", string cardSuit = "", string cardValue = "")
        {
            CardB playedCard = new CardB();

            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            string UUID = currentUser.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            if (UUID == null)
            {
                errorView = new ErrorViewModel();
                ModelState.AddModelError(string.Empty, "You are not logged in. ");
                errorView.RequestId     = "0x10018000";
                errorView.RequestString = "You are not logged in. ";
                return(View("Error", errorView));
            }

            var match = _context.MatchB.Include(o => o.Games).Include(o => o.North).Include(o => o.South).Include(o => o.East).Include(o => o.West).Include(o => o.LastHand)
                        .ThenInclude(h => h.Cards)
                        .FirstOrDefault(m => m.Id == id);

            match.Games = _context.GameB.OrderBy(o => o.Id).Where(g => g.MatchBId == match.Id).ToList();

            match.LastHand.Cards = _context.CardB.Where(c => c.HandBId == match.LastHand.Id).OrderBy(c => c.Sequence).ToList();

            GameB game = _context.GameB.Where(m => m.MatchBId == match.Id).OrderByDescending(g => g.Id).Take(1)
                         .Include(o => o.North).Include(o => o.South).Include(o => o.East).Include(o => o.West)
                         .Include(o => o.NorthHand).Include(o => o.SouthHand).Include(o => o.EastHand).Include(o => o.WestHand)
                         .Include(o => o.HandInPlay)
                         .Include(o => o.OpenCards).ThenInclude(q => q.Cards)
                         .Include(o => o.NorthSouthHandResult).ThenInclude(q => q.Cards)
                         .Include(o => o.EastWestHandResult).ThenInclude(q => q.Cards)
                         .ToList()[0];

            if ((game.Status == "Dealing") || (game.Status == "Finalising") || (game.Status == "Bidding"))
            {
                Response.Redirect("/../../MatchesB/Play/" + id);
                errorView = new ErrorViewModel();
                return(View("Error", errorView));
            }

            if (game.OpenCards == null)
            {
                game.OpenCards       = new HandB();
                game.OpenCards.Id    = Guid.NewGuid().ToString();
                game.OpenCards.Cards = new List <CardB>();
            }
            game.NorthHand.Cards = _context.CardB.Where(c => c.HandBId == game.NorthHand.Id).OrderBy(c => c.Seniority).ToList();
            game.SouthHand.Cards = _context.CardB.Where(c => c.HandBId == game.SouthHand.Id).OrderBy(c => c.Seniority).ToList();
            game.EastHand.Cards  = _context.CardB.Where(c => c.HandBId == game.EastHand.Id).OrderBy(c => c.Seniority).ToList();
            game.WestHand.Cards  = _context.CardB.Where(c => c.HandBId == game.WestHand.Id).OrderBy(c => c.Seniority).ToList();

            if (game.HandInPlay == null)
            {
                game.HandInPlay       = new HandB();
                game.HandInPlay.Id    = Guid.NewGuid().ToString();
                game.HandInPlay.Cards = new List <CardB>();
            }
            else
            {
                game.HandInPlay.Cards = _context.CardB.Where(c => c.HandBId == game.HandInPlay.Id).OrderBy(c => c.Sequence).ToList();
            }

            if (move == "")
            {
                ViewBag.Player = UUID;
                ViewBag.Dealer = game.Dealer.Id;

                return(View("GameProgress", match));
            }

            if (move == "collect")
            {
                Collect(game, move);
                _context.SaveChanges();
                sMessage = "Move";

                if (game.NorthHand.Cards.Count + game.SouthHand.Cards.Count + game.EastHand.Cards.Count + game.WestHand.Cards.Count == 0)
                {
                    Response.Redirect("/../../GamesB/FinaliseGame/" + id);

                    //                    Response.Redirect("/../../MatchesB/CompleteGame/" + id);

                    errorView = new ErrorViewModel();
                    return(View("Error", errorView));
                }
            }

            if (move == "Move")
            {
                if (game.NextPlayer.Id == game.North.Id)
                {
                    foreach (CardB card in game.NorthHand.Cards)
                    {
                        if ((card.Colour == cardSuit) & (card.Value == cardValue))
                        {
                            playedCard = card;
                            if (game.HandInPlay.Cards.Count == 0)
                            {
                                playedCard.Sequence = 1;
                            }
                            else
                            {
                                playedCard.Sequence = game.HandInPlay.Cards.Max(m => m.Sequence) + 1;
                            }
                        }
                    }
                    game.HandInPlay.Cards.Add(playedCard);
                    game.NorthHand.Cards.Remove(playedCard);

                    if (game.HandInPlay.Cards.Count == 1)
                    {
                        game.HighCardPlayer = game.NextPlayer;
                        game.HighCard       = playedCard;
                    }
                    else
                    {
                        if (cardSuit == game.Type)
                        {
                            if (game.HighCard.Colour == game.Type)
                            {
                                if (TrumpCardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.North;
                                }
                            }
                            else
                            {
                                game.HighCard       = playedCard;
                                game.HighCardPlayer = game.North;
                            }
                        }
                        else
                        {
                            if (game.HighCard.Colour == cardSuit)
                            {
                                if (CardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.North;
                                }
                            }
                        }
                    }
                }

                if (game.NextPlayer.Id == game.South.Id)
                {
                    foreach (CardB card in game.SouthHand.Cards)
                    {
                        if ((card.Colour == cardSuit) & (card.Value == cardValue))
                        {
                            playedCard = card;
                            if (game.HandInPlay.Cards.Count == 0)
                            {
                                playedCard.Sequence = 1;
                            }
                            else
                            {
                                playedCard.Sequence = game.HandInPlay.Cards.Max(m => m.Sequence) + 1;
                            }
                        }
                    }
                    game.HandInPlay.Cards.Add(playedCard);
                    game.SouthHand.Cards.Remove(playedCard);

                    if (game.HandInPlay.Cards.Count == 1)
                    {
                        game.HighCardPlayer = game.NextPlayer;
                        game.HighCard       = playedCard;
                    }
                    else
                    {
                        if (cardSuit == game.Type)
                        {
                            if (game.HighCard.Colour == game.Type)
                            {
                                if (TrumpCardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.South;
                                }
                            }
                            else
                            {
                                game.HighCard       = playedCard;
                                game.HighCardPlayer = game.South;
                            }
                        }
                        else
                        {
                            if (game.HighCard.Colour == cardSuit)
                            {
                                if (CardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.South;
                                }
                            }
                        }
                    }
                }

                if (game.NextPlayer.Id == game.East.Id)
                {
                    foreach (CardB card in game.EastHand.Cards)
                    {
                        if ((card.Colour == cardSuit) & (card.Value == cardValue))
                        {
                            playedCard = card;
                            if (game.HandInPlay.Cards.Count == 0)
                            {
                                playedCard.Sequence = 1;
                            }
                            else
                            {
                                playedCard.Sequence = game.HandInPlay.Cards.Max(m => m.Sequence) + 1;
                            }
                        }
                    }
                    game.HandInPlay.Cards.Add(playedCard);
                    game.EastHand.Cards.Remove(playedCard);

                    if (game.HandInPlay.Cards.Count == 1)
                    {
                        game.HighCardPlayer = game.NextPlayer;
                        game.HighCard       = playedCard;
                    }
                    else
                    {
                        if (cardSuit == game.Type)
                        {
                            if (game.HighCard.Colour == game.Type)
                            {
                                if (TrumpCardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.East;
                                }
                            }
                            else
                            {
                                game.HighCard       = playedCard;
                                game.HighCardPlayer = game.East;
                            }
                        }
                        else
                        {
                            if (game.HighCard.Colour == cardSuit)
                            {
                                if (CardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.East;
                                }
                            }
                        }
                    }
                }

                if (game.NextPlayer.Id == game.West.Id)
                {
                    foreach (CardB card in game.WestHand.Cards)
                    {
                        if ((card.Colour == cardSuit) & (card.Value == cardValue))
                        {
                            playedCard = card;
                            if (game.HandInPlay.Cards.Count == 0)
                            {
                                playedCard.Sequence = 1;
                            }
                            else
                            {
                                playedCard.Sequence = game.HandInPlay.Cards.Max(m => m.Sequence) + 1;
                            }
                        }
                    }
                    game.HandInPlay.Cards.Add(playedCard);
                    game.WestHand.Cards.Remove(playedCard);

                    if (game.HandInPlay.Cards.Count == 1)
                    {
                        game.HighCardPlayer = game.NextPlayer;
                        game.HighCard       = playedCard;
                    }
                    else
                    {
                        if (cardSuit == game.Type)
                        {
                            if (game.HighCard.Colour == game.Type)
                            {
                                if (TrumpCardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.West;
                                }
                            }
                            else
                            {
                                game.HighCard       = playedCard;
                                game.HighCardPlayer = game.West;
                            }
                        }
                        else
                        {
                            if (game.HighCard.Colour == cardSuit)
                            {
                                if (CardValueGreaterThan(cardValue, game.HighCard.Value))
                                {
                                    game.HighCard       = playedCard;
                                    game.HighCardPlayer = game.West;
                                }
                            }
                        }
                    }
                }

                sMessage = "Move";

                if (game.HandInPlay.Cards.Count == 4)
                {
                    game.NextPlayer = game.HighCardPlayer;
                    game            = Collect(game);
                    _context.SaveChanges();
                    if (game.NorthHand.Cards.Count == 0)
                    {
                        //                        Response.Redirect("/../../MatchesB/CompleteGame/" + id);
                        Response.Redirect("/../../GamesB/FinaliseGame/" + id);
                        errorView = new ErrorViewModel();
                        return(View("Error", errorView));
                    }
                }
                else
                {
                    if (game.NextPlayer.Id == game.North.Id)
                    {
                        game.NextPlayer = game.East;
                    }
                    else
                    {
                        if (game.NextPlayer.Id == game.East.Id)
                        {
                            game.NextPlayer = game.South;
                        }
                        else
                        {
                            if (game.NextPlayer.Id == game.South.Id)
                            {
                                game.NextPlayer = game.West;
                            }
                            else
                            {
                                if (game.NextPlayer.Id == game.West.Id)
                                {
                                    game.NextPlayer = game.North;
                                }
                            }
                        }
                    }
                }

                _context.SaveChanges();
                Response.Redirect("/../../GamesB/Play/" + id);
            }

            ViewBag.Player = UUID;
            ViewBag.Dealer = game.Dealer.Id;

            return(View("GameProgress", match));
        }
Exemple #10
0
        public GameB DealB(GameB game)
        {
            IList <CardB> deck = new List <CardB>();
            CardB         x;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    x    = new CardB();
                    x.Id = Guid.NewGuid().ToString();
                    switch (i)
                    {
                    case 0:
                        x.Colour    = "Spades";
                        x.Seniority = 100;
                        break;

                    case 1:
                        x.Colour    = "Clubs";
                        x.Seniority = 300;
                        break;

                    case 2:
                        x.Colour    = "Diamonds";
                        x.Seniority = 200;
                        break;

                    case 3:
                        x.Colour    = "Hearts";
                        x.Seniority = 400;
                        break;
                    }
                    switch (j)
                    {
                    case 0:
                        x.Value     = "Ace";
                        x.Seniority = x.Seniority + 14;
                        break;

                    case 1:
                        x.Value     = "Jack";
                        x.Seniority = x.Seniority + 11;
                        break;

                    case 2:
                        x.Value     = "Queen";
                        x.Seniority = x.Seniority + 12;
                        break;

                    case 3:
                        x.Value     = "King";
                        x.Seniority = x.Seniority + 13;
                        break;

                    default:
                        x.Value     = (j + 3).ToString();
                        x.Seniority = x.Seniority + j;
                        break;
                    }
                    x.SeniorityTrump = x.Seniority;
                    if (x.Value == "9")
                    {
                        x.SeniorityTrump = x.SeniorityTrump + 10;
                    }
                    if (x.Value == "Jack")
                    {
                        x.SeniorityTrump = x.SeniorityTrump + 20;
                    }
                    deck.Add(x);
                }
            }

            deck = deck.OrderBy(a => Guid.NewGuid()).ToList();

            GameB _game = game;
            int   n     = 0;
            int   q     = 8;

            _game.NorthHand       = new HandB();
            _game.NorthHand.Id    = Guid.NewGuid().ToString();
            _game.NorthHand.Cards = new List <CardB>();
            for (int j = 0; j < q; j++)
            {
                _game.NorthHand.Cards.Add(deck[n]);
                n++;
            }

            _game.SouthHand       = new HandB();
            _game.SouthHand.Id    = Guid.NewGuid().ToString();
            _game.SouthHand.Cards = new List <CardB>();
            for (int j = 0; j < q; j++)
            {
                _game.SouthHand.Cards.Add(deck[n]);
                n++;
            }

            _game.NorthSouthHandResult    = new HandB();
            _game.NorthSouthHandResult.Id = Guid.NewGuid().ToString();

            _game.EastHand       = new HandB();
            _game.EastHand.Id    = Guid.NewGuid().ToString();
            _game.EastHand.Cards = new List <CardB>();
            for (int j = 0; j < q; j++)
            {
                _game.EastHand.Cards.Add(deck[n]);
                n++;
            }

            _game.WestHand       = new HandB();
            _game.WestHand.Id    = Guid.NewGuid().ToString();
            _game.WestHand.Cards = new List <CardB>();
            for (int j = 0; j < q; j++)
            {
                _game.WestHand.Cards.Add(deck[n]);
                n++;
            }

            _game.EastWestHandResult    = new HandB();
            _game.EastWestHandResult.Id = Guid.NewGuid().ToString();

            return(_game);
        }
Exemple #11
0
        // GET: Matches/Play/5
        public async Task <IActionResult> Play(string id, bool deal = false, string bid = "", string type = "", int value = 0, bool challenge = false, bool contra = false, bool kaput = false)
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            string UUID = currentUser.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            if (UUID == null)
            {
                errorView = new ErrorViewModel();
                ModelState.AddModelError(string.Empty, "You are not logged in. ");
                errorView.RequestId     = "0x10018000";
                errorView.RequestString = "You are not logged in. ";
                return(View("Error", errorView));
            }

            var match = _context.MatchB.Include(o => o.Games).Include(o => o.North).Include(o => o.South).Include(o => o.East).Include(o => o.West).Include(o => o.LastHand)
                        .ThenInclude(o => o.Cards)
                        .FirstOrDefault(m => m.Id == id);

            GameB game = _context.GameB.Where(m => m.MatchBId == match.Id).OrderByDescending(g => g.Id).Take(1)
                         .Include(o => o.NorthHand).Include(o => o.SouthHand).Include(o => o.EastHand).Include(o => o.WestHand)
                         .ToList()[0];

            if ((game.Status == "Playing") || (game.Status == "Collecting") || (game.Status == "Offer"))
            {
                Response.Redirect("/../../GamesB/Play/" + id);
                errorView = new ErrorViewModel();
                return(View("Error", errorView));
            }

            if (!(game.NorthHand == null))
            {
                game.NorthHand.Cards = _context.CardB.Where(c => c.HandBId == game.NorthHand.Id).OrderBy(c => c.Seniority).ToList();
                game.SouthHand.Cards = _context.CardB.Where(c => c.HandBId == game.SouthHand.Id).OrderBy(c => c.Seniority).ToList();
                game.EastHand.Cards  = _context.CardB.Where(c => c.HandBId == game.EastHand.Id).OrderBy(c => c.Seniority).ToList();
                game.WestHand.Cards  = _context.CardB.Where(c => c.HandBId == game.WestHand.Id).OrderBy(c => c.Seniority).ToList();
            }

            /* ********************************** Dealing ************************************* */

            if (deal)
            {
                if (game.Status == "Dealing")
                {
                    game        = DealB(game);
                    game.Status = "Bidding";
                    game.Type   = "All-Pass";
                    if (game.Dealer.Id == game.North.Id)
                    {
                        game.NextPlayer = game.East;
                    }
                    if (game.Dealer.Id == game.East.Id)
                    {
                        game.NextPlayer = game.South;
                    }
                    if (game.Dealer.Id == game.South.Id)
                    {
                        game.NextPlayer = game.West;
                    }
                    if (game.Dealer.Id == game.West.Id)
                    {
                        game.NextPlayer = game.North;
                    }
                    deal = false;
                    _context.SaveChanges();
                    Response.Redirect("/../../MatchesB/Play/" + id);
                    errorView = new ErrorViewModel();
                    return(View("Error", errorView));
                }
            }

            /* **************************** Bidding Process *********************************** */

            if ((game.Status == "Bidding") & ((UUID == game.NextPlayer.Id) || ((UUID == game.Dealer.Id) & ((bid == "reject") || (bid == "accept")))))
            {
                _context.SaveChanges();
            }

            if (bid == "order")
            {
                if (!(game.Status == "Bidding"))
                {
                    ViewBag.Message = "Order has already been placed, go to game.";
                }
                else
                {
                    if (UUID == game.North.Id || UUID == game.South.Id)
                    {
                        game.ActiveTeamNS = true;
                    }
                    else
                    {
                        game.ActiveTeamNS = false;
                    }
                    game.Challenge        = challenge;
                    game.Contra           = contra;
                    game.Kaput            = kaput;
                    game.EastWestPoints   = 0;
                    game.NorthSouthPoints = 0;
                    game.Status           = "Playing";
                    game.Type             = type;
                    game.Value            = value;
                    _context.SaveChanges();
                    Response.Redirect("/../../GamesB/Play/" + id);
                }
            }
            ViewBag.Dealer = match.Games.OrderByDescending(i => i.Id).FirstOrDefault().Dealer.Id;
            ViewBag.Player = UUID;
            return(View("MatchPlay", match));
        }