Пример #1
0
 public ArtViewModel(Game game, GameArt art)
 {
     Art = art;
     Visitors = game.VisitorByLocation(TypeLocationMap.TypeToLocation[art.Type]);
     VisitorTypeNames = Visitors.Select(v => v.Type.ToString()).ToArray();
     SetTicketStrings(art);
 }
Пример #2
0
 public ActionResult Create(Game newGame)
 {
     if (ModelState.IsValid)
     {
         using (var galleristContext = new GalleristComponentsDbContext())
         {
             newGame.CreatedTime = DateTime.Now;
             galleristContext.Games.Add(newGame);
             using (var identityContext = new ApplicationDbContext())
             {
                 //add me to the game
                 newGame.Players.Add(new Player
                 {
                     UserId = identityContext.Users.First(m => m.UserName == User.Identity.Name).Id,
                     UserName = User.Identity.Name,
                     IsHost = true
                 });
             }
             galleristContext.SaveChanges();
             return Redirect("/Game/List"); //redirect to actual game might be better for demo purposes
         }
     }
     else
     {
         return View(newGame);
     }
 }
        public List<ArtType> TypeOrder = new List<ArtType> { ArtType.digital, ArtType.photo, ArtType.sculpture, ArtType.painting }; //reputation tile rows

        #endregion Fields

        #region Constructors

        public InternationalMarketViewModel(string userName, Game game)
        {
            IsActivePlayer = FormHelper.IsActivePlayer(userName, game);
            IsValidActionState = game.CurrentTurn.CurrentAction.State == GameActionState.InternationalMarket;

            Game = game;

            SetTiles(game);
            SetAuctionLocations(userName, game);
        }
        public AuctionLocationViewModel(string userName, Game game, string column, string row)
        {
            IsActivePlayer = FormHelper.IsActivePlayer(userName, game);
            IsValidActionState = game.CurrentTurn.CurrentAction.State == GameActionState.InternationalMarket;

            Game = game;
            Column = column;
            Row = row;
            SetActionLocation(row, column);
            SetAuctionClass(ActionLocation);
        }
        public ArtistColonyViewModel(string userName, Game game)
        {
            FormAction = game.CurrentTurn.CurrentAction.State == GameActionState.ArtistColony ? GameActionState.ArtBuy : GameActionState.Promote;
            IsActivePlayer = FormHelper.IsActivePlayer(userName, game);
            IsValidActionState = game.CurrentTurn.CurrentAction.State == GameActionState.ArtistColony || game.CurrentTurn.CurrentAction.State == GameActionState.MediaCenter;

            Game = game;

            SetArtistLists(game);
            SetViewStrings(game);
            SetArtList(game);
        }
Пример #6
0
 public static void GetActionForm(this HtmlHelper Html, string partialViewPath, Game game, GameActionState state, string location, object model = null)
 {
     string partialView;
     if (model != null)
         partialView = Html.Partial(partialViewPath,model).ToString();
     else
         partialView = Html.Partial(partialViewPath).ToString();
     using (Html.BeginForm("TakeGameAction", "Game", new { id = game.Id, gameAction = state, actionLocation = location }, FormMethod.Post, new { role = "form" }))
     {
         string inner = Html.AntiForgeryToken().ToString() + InsertSubmitElement(partialView);
         Html.ViewContext.Writer.Write(inner);
     }
 }
 private void SetArtistLists(Game game)
 {
     foreach (ArtistCategory category in new List<ArtistCategory> { ArtistCategory.blue, ArtistCategory.red })
     {
         var result = new List<GameArtist>();
         foreach (ArtType type in ArtTypeList)
         {
             var artist = game.Artists.Where(a => a.ArtType == type && a.Category == category).First();
             result.Add(artist);
         }
         if (category == ArtistCategory.blue) BlueArtists = result;
         else RedArtists = result;
     }
 }
 private void SetAuctionLocations(string userName, Game game)
 {
     var rowHeader = new List<string> { "money-1", "money-2", "money-3" }; //the css class for the row header (displays the appropriate amount of money)
     var result = new List<List<AuctionLocationViewModel>>();
     foreach (string row in AuctionRows)
     {
         var rowList = new List<AuctionLocationViewModel>();
         foreach (GameReputationTileLocation column in Columns)
         {
             rowList.Add(new AuctionLocationViewModel(userName, game, column.ToString(), row));
         }
         result.Add(rowList);
     }
     AuctionLocations = rowHeader.Zip(result, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
 }
        public SalesOfficeViewModel(string userName, Game game)
        {
            IsActivePlayer = FormHelper.IsActivePlayer(userName, game);

            var actionManager = new ActionContextInvoker(game);
            DrawIsValidActionState = actionManager.IsValidTransition(GameActionState.ContractDraw);
            DraftIsValidActionState = actionManager.IsValidTransition(GameActionState.ContractDraft);

            Game = game;
            DrawState = GameActionState.ContractDraw;

            AllContracts = game.GetContractDecks();
            DrawCount = AllContracts[GameContractLocation.DrawDeck].Count;

            SetDraftContractModels(AllContracts);
        }
        }; //used to get html friendly names to use in id fields, format: { (key) location, (value) { location name, first action, second action }

        #endregion Fields

        #region Constructors

        public ActionSpaceViewModel(string userName, Game game, PlayerLocation location)
        {
            Game = game;
            IsActivePlayer = FormHelper.IsActivePlayer(userName, game);
            IsValidSpace = ValidateSpace(game, location);

            Location = location;
            State = (GameActionState)Enum.Parse(typeof(GameActionState), location.ToString());
            LocationName = HtmlNames[location][0];
            FirstActionName = HtmlNames[location][1];
            SecondActionName = HtmlNames[location][2];

            Color = game.Players.First(p => p.UserName == userName).Color;
            SetGalleristColorClass(game, location);
            SetPushAndPullByLocation(location);
        }
Пример #11
0
        public PlayViewModel(string userName, Game game)
        {
            Game = game;

            SalesOfficeModel = new SalesOfficeViewModel(userName, game);
            InternationalMarketModel = new InternationalMarketViewModel(userName, game);
            ArtistColonyModel = new ArtistColonyViewModel(userName, game);

            InfluenceTrackModel = new InfluenceTrackViewModel(game);

            SetLocationViewModels(userName, game);
            SetGalleryModels(game);

            SetPlazaCounts(game);

            SetBoardModels(userName, game);
        }
 private void SetTiles(Game game)
 {
     var result = new List<List<ReputationTileViewModel>>();
     foreach ( ArtType row in TypeOrder)
     {
         var rowList = new List<ReputationTileViewModel>();
         foreach(GameReputationTileLocation column in Columns)
         {
             var tile = game.ReputationTiles.FirstOrDefault(r => r.Row == row && r.Column == column);
             if (tile != null)
                 rowList.Add(new ReputationTileViewModel(tile));
             else
                 rowList.Add(null);
         }
         result.Add(rowList);
     }
     Tiles = TypeOrder.Zip(result, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
 }
        public PlayerGalleryViewModel(Game game, PlayerColor color)
        {
            Game = game;
            Color = color;

            HasPlayer = game.Players.Any(p => p.Color == color);
            EmptyGalleryCssClass = HasPlayer ? "" : "unused-gallery-region";
            IsGalleryFirst = color == PlayerColor.yellow || color == PlayerColor.purple;

            GalleryVisitors = game.VisitorByPlayerAndLocation(color, GameVisitorLocation.Gallery);
            GalleryInvestorCount = GalleryVisitors.Where(v => v.Type == VisitorTicketType.investor).Count();
            GalleryCollectorCount = GalleryVisitors.Where(v => v.Type == VisitorTicketType.collector).Count();
            GalleryVipCount = GalleryVisitors.Where(v => v.Type == VisitorTicketType.vip).Count();
            GalleryVisitorCounts = new List<int> { GalleryInvestorCount, GalleryCollectorCount, GalleryVipCount };

            LobbyVisitors = game.VisitorByPlayerAndLocation(color, GameVisitorLocation.Lobby);
            LobbyInvestorCount = LobbyVisitors.Where(v => v.Type == VisitorTicketType.investor).Count();
            LobbyCollectorCount = LobbyVisitors.Where(v => v.Type == VisitorTicketType.collector).Count();
            LobbyVipCount = LobbyVisitors.Where(v => v.Type == VisitorTicketType.vip).Count();
            LobbyVisitorCounts = new List<int> { LobbyInvestorCount, LobbyCollectorCount, LobbyVipCount };
        }
Пример #14
0
        private static GameResponse CheckGameState(Game game, GalleristComponentsDbContext galleristContext)
        {
            var gameResponse = new GameResponse
            {
                Game = game,
                Success = false,
                Message = "",
                Title = ""
            };

            if (game == null || galleristContext == null)
            {
                gameResponse.Title = "Not Found";
                gameResponse.Message = "Sorry but this does not appear to be a valid game.";
                gameResponse.Success = false;
            }
            //nothing bad happened
            else
            {
                gameResponse.Success = true;
            }

            return gameResponse;
        }
 public static ActionContext GetContext(GameActionState state, Game game)
 {
     Type contextType = ActionToContextType[state];
     return (ActionContext)Activator.CreateInstance(contextType, game);
 }
 private bool ValidateSpace(Game game, PlayerLocation location)
 {
     var state = (GameActionState)Enum.Parse(typeof(GameActionState), location.ToString());
     var action = new GameAction { State = state, Location = game.CurrentTurn.CurrentAction.Location };
     var invoker = new ActionContextInvoker(game);
     return invoker.IsValidTransition(action);
 }
 private void SetGalleristColorClass(Game game, PlayerLocation location)
 {
     var playerAtLocation = game.Players.FirstOrDefault(p => p.GalleristLocation == location);
     if (playerAtLocation != null)
     {
         GalleristColorClass = playerAtLocation.Color.ToString() + "-gallerist";
     }
     else
     {
         GalleristColorClass = "";
     }
 }
 private void SetArtList(Game game)
 {
     var result = new List<GameArt>();
     foreach(ArtType type in ArtTypeList)
     {
         var art = game.GetArtFromStack(type);
         result.Add(art);
     }
     Art = result;
 }
 private void SetViewStrings(Game game)
 {
     var result = new Dictionary<GameArtist, string>();
     foreach (GameArtist artist in BlueArtists.Concat(RedArtists))
     {
         var viewString = "~/Views/Game/ArtistColony/ArtistUndiscovered.cshtml";
         if (artist.IsDiscovered)
         {
             viewString = "~/Views/Game/ArtistColony/ArtistDiscovered.cshtml";
         }
         result.Add(artist, viewString);
     }
     ArtistToPartialViewString = result;
 }
Пример #20
0
 private void SetGalleryModels(Game game)
 {
     var result = new List<PlayerGalleryViewModel>();
     foreach (PlayerColor color in TopGalleryOrder )
     {
         result.Add(new PlayerGalleryViewModel(game, color));
     }
     TopGalleryModels = result;
     result = new List<PlayerGalleryViewModel>();
     foreach (PlayerColor color in BottomGalleryOrder)
     {
         result.Add(new PlayerGalleryViewModel(game, color));
     }
     BottomGalleryModels = result;
 }
 public InfluenceTrackViewModel(Game game)
 {
     Spaces = new List<InfluenceSpaceViewModel>();
     for(int i = 0; i<36; i++)
     {
         if (game.Players.Any(p => p.Influence == i))
         {
             var playerColors = game.Players.Where(p => p.Influence == i).Select(p => p.Color).ToList();
             Spaces.Add(new InfluenceSpaceViewModel(i, playerColors));
         }
         else
             Spaces.Add(new InfluenceSpaceViewModel(i));
     }
 }
 public ActionContextInvoker(Game game)
 {
     Game = game;
     _context = ActionContextFactory.GetContext(game.CurrentTurn.CurrentAction.State, game);
 }
Пример #23
0
 public static bool IsValidAction(this GameAction action, Game game)
 {
     var invoker = new ActionContextInvoker(game);
     return invoker.IsValidGameState(action);
 }
Пример #24
0
 private void SetLocationViewModels(string userName, Game game)
 {
     var result = new List<ActionSpaceViewModel>();
     foreach ( PlayerLocation location in ActionList)
     {
         result.Add(new ActionSpaceViewModel(userName, game, location));
     }
     LocationViewModels = result;
 }
Пример #25
0
 private void SetPlazaCounts(Game game)
 {
     var plazaVisitors = game.VisitorByLocation(GameVisitorLocation.Plaza);
     var plazaInvestorCount = plazaVisitors.Where(v => v.Type == VisitorTicketType.investor).Count();
     var plazaCollectorCount = plazaVisitors.Where(v => v.Type == VisitorTicketType.collector).Count();
     var plazaVipCount = plazaVisitors.Where(v => v.Type == VisitorTicketType.vip).Count();
     PlazaVisitorCounts = new List<int> { plazaInvestorCount, plazaCollectorCount, plazaVipCount };
 }
Пример #26
0
 public static bool IsActivePlayer(string userName, Game game)
 {
     return game.CurrentPlayer.UserName == userName;
 }
Пример #27
0
 private void SetBoardModels(string userName, Game game)
 {
     var result = new List<PlayerBoardViewModel>();
     foreach(Player player in game.Players)
     {
         result.Add(new PlayerBoardViewModel(userName, player));
     }
     PlayerBoardModels = result;
 }