示例#1
0
        public ActionResult Challenge(int opponentId, int versionId)
        {
            Player player = db.Players.Where(p => p.Name == User.Identity.Name).Single();
            Player opponent = db.Players.Find(opponentId);
            // Create Table
            Table newTable = new Table();
            newTable = db.Tables.Add(newTable);
            //newTable.LastUpdateTime = DateTime.Now;
            newTable.Version = db.Versions.Find(versionId);
            newTable.Game = newTable.Version.ParentGame;
            newTable.TableState = (int)TableState.Proposed;
            if (newTable.Version.DevStage == "Alpha")
                newTable.Alpha = true;
            db.SaveChanges();

            // Create Seats
            Seat s1 = new Seat
            {
                PlayerId = player.PlayerID,
                TableId = newTable.TableID,
                Accepted = true,
                Waiting = false
            };
            db.Seats.Add(s1);
            Seat s2 = new Seat
            {
                PlayerId = opponent.PlayerID,
                TableId = newTable.TableID,
                Accepted = false,
                Waiting = false
            };
            db.Seats.Add(s2);

            db.SaveChanges();

            newTable = db.Tables.Where(t => t.TableID == newTable.TableID).Single();

            newTable.GenerateInitialState();
            db.SaveChanges();

            foreach (Seat s in newTable.Seats)
            {
                NotificationsHub.Challenge(db, s, newTable);
            }
            db.SaveChanges();

            return RedirectToAction("Play", new { id = newTable.TableID });
        }
        public ActionResult Test(int id, int numPlayers=2)
        {
            GameVersion version = db.Versions.Find(id);
            Game game = version.ParentGame;

            PlayerIdentity playerIdentity = (PlayerIdentity)User.Identity;
            Player player = db.Players.Where(p => p.Name == playerIdentity.Name).Single();
            if (player.PlayerID != game.CreatorId)
                RedirectToAction("DeveloperProfile", "Home");

            Table newTable = new Table();
            newTable = db.Tables.Add(newTable);
            //newTable.LastUpdateTime = DateTime.Now;
            newTable.Game = db.Games.Single(g => g.Name == game.Name);
            newTable.Version = newTable.Game.Versions.First();
            newTable.TableState = (int)TableState.Proposed;
            newTable.SoloPlayTest = true;
            db.SaveChanges();

            // Create Seats
            for (int i = 0; i < numPlayers; i++)
            {
                Seat s = new Seat
                {
                    PlayerId = player.PlayerID,
                    TableId = newTable.TableID,
                    Accepted = true,
                    Waiting = false
                };
                db.Seats.Add(s);
            }

            db.SaveChanges();

            newTable = db.Tables.Where(t => t.TableID == newTable.TableID).Include("Seats.Deck.CardSets.Card").Single();

            string error = newTable.GenerateInitialState();
            if (error == "")
            {
                db.SaveChanges();
                return RedirectToAction("Play", "Table", new { id = newTable.TableID, playerIndex = 0 });
            }
            else
            {
                db.Tables.Remove(newTable);
                error = error.Replace("<br/>", "\n");
                error = error.Replace("<string>", "Unknown");
                return RedirectToAction("Edit", "GameVersion", new { id = id, initError = error });
            }
        }
        public ActionResult Add(int gameId, int numPlayers)
        {
            Player player = db.Players.Where(p => p.Name == User.Identity.Name).Single();

            // Search database for earliest request with same gameId and numberOfPlayers, but different  playerId
            List<MatchRequest> successfulMatches = db.MatchRequests.OrderBy(matchRequest => matchRequest.RequestTime).Where(matchRequest => matchRequest.GameId == gameId && matchRequest.NumberOfPlayers == numPlayers && matchRequest.PlayerId != player.PlayerID).ToList();
            if (successfulMatches.Count < numPlayers-1)
            {
                MatchRequest m = new MatchRequest { GameId = gameId, NumberOfPlayers = numPlayers, PlayerId = player.PlayerID, RequestTime = DateTime.Now };
                db.MatchRequests.Add(m);
                db.SaveChanges();
                return RedirectToAction("Wait", "Table", new { MatchRequestId = m.MatchRequestID });
            }
            else
            {
                successfulMatches = successfulMatches.GetRange(0, numPlayers-1);

                Game game = db.Games.Find(gameId);

                Table newTable = new Table();
                newTable = db.Tables.Add(newTable);
                //newTable.LastUpdateTime = DateTime.Now;
                newTable.Version = db.Versions.Find(game.LatestRelease.GameVersionID);
                if (newTable.Version.DevStage == "Alpha")
                    newTable.Alpha = true;
                newTable.Game = newTable.Version.ParentGame;
                newTable.TableState = (int)TableState.Proposed;
                db.SaveChanges();

                // Create Seats

                Seat s = new Seat
                {
                    PlayerId = player.PlayerID,
                    TableId = newTable.TableID,
                    Accepted = true,
                    Waiting = false
                };
                db.Seats.Add(s);
                foreach (MatchRequest match in successfulMatches)
                {
                    Seat s2 = new Seat
                    {
                        PlayerId = match.PlayerId,
                        TableId = newTable.TableID,
                        Accepted = true,
                        Waiting = false
                    };
                    db.Seats.Add(s2);
                }

                db.SaveChanges();

                newTable = db.Tables.Where(t => t.TableID == newTable.TableID).Include("Seats.Player").Single();
                newTable.Ranked = true;
                newTable.TableState = (int)TableState.InPlay;

                newTable.GenerateInitialState();

                foreach (Seat seat in newTable.Seats)
                {
                    NotificationsHub.AddMatch(db, seat, newTable);
                }
                db.SaveChanges();

                IConnectionManager connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>();
                dynamic clients = connectionManager.GetClients<WaitingArea>();

                foreach (MatchRequest match in successfulMatches)
                {
                    Player opponent = db.Players.Find(match.PlayerId);
                    clients["WAIT" + opponent.Name + match.MatchRequestID].goToTable(newTable.TableID);
                    db.MatchRequests.Remove(match);
                }

                db.SaveChanges();
                return RedirectToAction("Play", "Table", new { id = newTable.TableID });
            }
        }
示例#4
0
        public void ConfirmProposal(int id, string name)
        {
            Proposal proposal = activeProposals.Find(p => p.ProposalID == id);
            if (proposal != null)
            {
                proposal.Confirm(name);
                if (proposal.Final == true)
                {
                    // Create game
                    // NOTE: GAME CREATION DOES NOT BELONG IN LOBBY CODE

                    // Create Table
                    Table newTable = new Table();
                    newTable = db.Tables.Add(newTable);
                    //newTable.LastUpdateTime = DateTime.Now;
                    string gameName = proposal.gameName.Replace("*","");
                    newTable.Game = db.Games.Single(g => g.Name == gameName);
                    newTable.Version = newTable.Game.Versions.Single(v => v.GameVersionID == proposal.versionId);
                    newTable.TableState = (int)TableState.Proposed;
                    if (newTable.Version.DevStage == "Alpha")
                        newTable.Alpha = true;
                    db.SaveChanges();

                    // Create Seats
                    foreach (string playerName in proposal.PlayerNames)
                    {
                        Player p = db.Players.Where(pl => pl.Name == playerName).Single();
                        Seat s = new Seat
                        {
                            PlayerId = p.PlayerID,
                            TableId = newTable.TableID,
                            Accepted = true,
                            Waiting = false
                        };
                        db.Seats.Add(s);
                    }

                    db.SaveChanges();

                    newTable = db.Tables.Where(t => t.TableID == newTable.TableID).Single();

                    newTable.GenerateInitialState();
                    db.SaveChanges();

                    activeProposals.Remove(proposal);

                    // Redirect plyaers to game
                    foreach (string playerName in proposal.PlayerNames)
                    {
                        Clients["LOBBY_"+playerName].beginGame(newTable.TableID);
                    }
                }
                else
                {
                    UpdateClients(proposal,null);
                }
            }
            return;
        }
示例#5
0
        public SeatViewModel(Seat seat)
        {
            Table t = seat.Table;
            Game g = t.Game;

            tableId = t.TableID;
            gameName = g.Name;
            linkText = "View";
            if (seat.Waiting == true && (TableState)(t.TableState)==TableState.InPlay)
                linkText = "Your Move";
            if (seat.Waiting == true && (TableState)(t.TableState) == TableState.Proposed)
                linkText = "Accept";

            cancellable = false;
            if (seat.Accepted == false && (TableState)(t.TableState) == TableState.Proposed)
                cancellable = true;

            //if(seat.Table.LastUpdateTime
              //  forceWin = true;

            List<String> opponentNames = t.Seats.Where(s => s != seat).Select(s => s.Player.Name).ToList();
            formattedOpponentNames = opponentNames[0];
            if (opponentNames.Count > 1)
            {
                for (int i = 1; i < opponentNames.Count - 1; i++)
                {
                    formattedOpponentNames += ", " + opponentNames[i];
                }

                formattedOpponentNames += " and " + opponentNames.Last();
            }
            status = "(" + (TableState)(t.TableState) + ")";
        }