예제 #1
0
 protected ActionContext(Game game, Dictionary <GameActionState, Type> NameToState)
 {
     Game             = game;
     Action           = game.CurrentTurn.CurrentAction;
     this.NameToState = NameToState;
     State            = Game.CurrentTurn.CurrentAction.State;
 }
예제 #2
0
 /// <summary>
 /// The press.
 /// </summary>
 /// <param name="keyPressAmount">
 /// The key press amount.
 /// </param>
 public void Press(int keyPressAmount)
 {
     if (this.state != GameActionState.WaitingForRelease)
     {
         this.amount += keyPressAmount;
         this.state   = GameActionState.Pressed;
     }
 }
예제 #3
0
 public void DoAction(GameActionState state)
 {
     Action = new GameAction {
         State = state, IsExecutable = true, Location = ""
     };
     State = Action.State;
     _state.DoAction(this);
 }
예제 #4
0
    // Action de jeu : essai
    public override bool OnTry(Zone z)
    {
        GameActionState newSon = new GameActionState(sm, cam, game);
        sm.state_change_son(this, newSon);
        newSon.OnTry(z);

        return true;
    }
예제 #5
0
    // Action de jeu : essai
    public override bool OnTry(Zone z)
    {
        GameActionState newSon = new GameActionState(sm, cam, game);

        sm.state_change_son(this, newSon);
        newSon.OnTry(z);

        return(true);
    }
예제 #6
0
 public static void SetCurrentAction(this GameTurn turn, GameActionState state, string location)
 {
     if (turn.CurrentAction != null)
     {
         turn.AddCompletedAction(turn.CurrentAction);
     }
     turn.CurrentAction = new GameAction {
         State = state, Location = location, IsExecutable = true
     };
 }
 public static string Highlight(this Game game, GameActionState state)
 {
     var userId = HttpContext.Current.User.Identity.GetUserId();
     var highlight = "";
     if (game.CurrentTurn.CurrentAction.State == state && game.CurrentPlayer.UserId == userId)
     {
         highlight = "highlight";
     }
     return highlight;
 }
예제 #8
0
        public static void RemovePendingAction(this GameTurn turn, GameActionState state)
        {
            var temp   = turn.PendingActions;
            var action = temp.FirstOrDefault(a => a.State == state);

            if (action != null)
            {
                temp.Remove(action);
            }
            turn.PendingActions = temp;
        }
예제 #9
0
        public static string Highlight(this Game game, GameActionState state)
        {
            var userId    = HttpContext.Current.User.Identity.GetUserId();
            var highlight = "";

            if (game.CurrentTurn.CurrentAction.State == state && game.CurrentPlayer.UserId == userId)
            {
                highlight = "highlight";
            }
            return(highlight);
        }
예제 #10
0
 public bool IsValidTransition(GameActionState state)
 {
     if (Game.CurrentTurn.PendingActions.Any(a => a.State == state))
     {
         var action = new GameAction {
             State = state
         };
         return(IsValidGameState(action));
     }
     return(false);
 }
예제 #11
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);
     }
 }
예제 #12
0
    // Action de jeu : touche
    public override bool OnTouch(Touche t)
    {
        if (sm.state_has_son(this, typeof(GameActionState)))
        {
            return(false);
        }
        else
        {
            GameActionState newSon = new GameActionState(sm, cam, game);
            sm.state_change_son(this, newSon);
            newSon.OnTouch(t);

            return(true);
        }
    }
예제 #13
0
    // Action de jeu : touche
    public override bool OnTouch(Touche t)
    {
        if (sm.state_has_son(this, typeof(GameActionState)))
        {
            return false;
        }
        else
        {
            GameActionState newSon = new GameActionState(sm, cam, game);
            sm.state_change_son(this, newSon);
            newSon.OnTouch(t);

            return true;
        }
    }
예제 #14
0
 public static void RemoveAllSiblingActions(this GameTurn turn, GameActionState state)
 {
     var temp = turn.PendingActions;
     var action = temp.FirstOrDefault(a => a.State == state);
     if (action != null)
     {
         if (action.Priority == GameActionPriority.OptionalExclusive)
         {
             temp.RemoveAll(a => a.Priority == GameActionPriority.OptionalExclusive && a.Parent.State == action.Parent.State);
         }
         else
         {
             temp.Remove(action);
         }
     }
     turn.PendingActions = temp;
 }
예제 #15
0
        public static void RemoveAllSiblingActions(this GameTurn turn, GameActionState state)
        {
            var temp   = turn.PendingActions;
            var action = temp.FirstOrDefault(a => a.State == state);

            if (action != null)
            {
                if (action.Priority == GameActionPriority.OptionalExclusive)
                {
                    temp.RemoveAll(a => a.Priority == GameActionPriority.OptionalExclusive && a.Parent.State == action.Parent.State);
                }
                else
                {
                    temp.Remove(action);
                }
            }
            turn.PendingActions = temp;
        }
        public bool DoAction(GameActionState state, string actionLocation = "")
        {
            var newAction = new GameAction { State = state, Location = actionLocation, IsExecutable = true };
            if (!IsValidTransition(newAction))
            {
                return false;
            }
            //todo remove the pending action that corresponds to the new action request
            Game.CurrentTurn.RemoveAllSiblingActions(newAction.State);

            DoActionSingle(newAction);

            var nextAction = Game.CurrentTurn.PendingActions.FirstOrDefault(a => a.IsExecutable == true);
            if (nextAction != null)
            {
                Game.CurrentTurn.RemoveAllSiblingActions(nextAction);
                DoActionSingle(nextAction);
            }
            return true;
        }
예제 #17
0
        public bool DoAction(GameActionState state, string actionLocation = "")
        {
            var newAction = new GameAction {
                State = state, Location = actionLocation, IsExecutable = true
            };

            if (!IsValidTransition(newAction))
            {
                return(false);
            }
            //todo remove the pending action that corresponds to the new action request
            Game.CurrentTurn.RemoveAllSiblingActions(newAction.State);

            DoActionSingle(newAction);

            var nextAction = Game.CurrentTurn.PendingActions.FirstOrDefault(a => a.IsExecutable == true);

            if (nextAction != null)
            {
                Game.CurrentTurn.RemoveAllSiblingActions(nextAction);
                DoActionSingle(nextAction);
            }
            return(true);
        }
예제 #18
0
 public bool IsValidGameState(GameAction action)
 {
     State  = action.State;
     Action = action;
     return(_state.IsValidGameState(this));
 }
 public static ActionContext GetContext(GameActionState state, Game game)
 {
     Type contextType = ActionToContextType[state];
     return (ActionContext)Activator.CreateInstance(contextType, game);
 }
예제 #20
0
        public ActionResult TakeGameAction(int id, GameActionState gameAction, string actionLocation = "")
        {
            using (var galleristContext = new GalleristComponentsDbContext())
            {
                using (var identityContext = new ApplicationDbContext()) //may not need this anymore after adding the authorize helper
                {
                    var gameResponse = GameManager.GetGame(id, galleristContext);
                    var game = gameResponse.Game;

                    //todo todo todo
                    //make sure the player taking an action is the current player
                    //compare current action to game state to make sure a valid action was taken (e.g. player can't move to board spot A from board spot A) [states..]
                    //todo make getting user by username a method (is it one already?)
                    var currentUser = identityContext.Users.FirstOrDefault(m => m.UserName == User.Identity.Name);

                    //todo refactor some of this into a game logic module
                    var player = game.Players.FirstOrDefault(p => p.UserId == currentUser.Id);
                    if (player == null)
                    {
                        return View("GameError");
                    }
                    if (player.Id != game.CurrentPlayerId )
                    {
                        return View("GameError");
                    }

                    var actionInvoker = new ActionContextInvoker(game);

                    if(!actionInvoker.DoAction(gameAction, actionLocation))
                    {
                        return Redirect("~/Game/Play/" + id);
                    }

                    //check if it is one of the special cases where the action must be confirmed before allowing the next step to proceed (e.g. player must draw cards)
                    //if yes take an intermediate step, still remains current player's turn
                    //if no, continue doing logic things  //determine order of bumped player's actions, can these happen at the end of current player's turn?
                    //check player locations for action taken by current player to see if any players need to be "bumped" to another spot
                    //somewhere in here we need to inject bumped player into turn order, we also need a way to specify that the current "turn" for a bumped player is not a full turn [bumped turn flag or something]
                    //let said player take bumped turn if necessary
                    //again do the updatey
                    //need some signalr stuff so we can show the action to everyone when it is done (intermediate step or not) as well as update money, influence, board, etc.
                    //update money, influence, board, etc.
                    galleristContext.SaveChanges();

                    var nextPlayer = identityContext.Users.First(m => m.Id == game.CurrentPlayer.UserId);
                    if (nextPlayer.AllowsEmails)
                    {
                        var gameUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/Game/Play/" + game.Id;
                        var emailTitle = nextPlayer.UserName + ", it is your turn!";
                        var emailBody = "It is your turn in a game you are playing. You can take your turn by visiting The Gallerist Online" +
                            " and viewing your active games or by clicking the following link: " + gameUrl;

                        EmailManager.SendEmail(emailTitle, emailBody, new List<string> { nextPlayer.Email });
                    }
                    PushHelper singleton = PushHelper.GetPushEngine();
                    singleton.RefreshGame(game.Players.Where(p => p.UserName != User.Identity.Name).Select(p => p.UserName).ToList());
                    return Redirect("~/Game/Play/" + id);
                }
            }
        }
예제 #21
0
 public static void RemovePendingAction(this GameTurn turn, GameActionState state)
 {
     var temp = turn.PendingActions;
     var action = temp.FirstOrDefault(a => a.State == state);
     if( action != null)
     {
         temp.Remove(action);
     }
     turn.PendingActions = temp;
 }
예제 #22
0
        public ActionResult TakeGameAction(int id, GameActionState gameAction, string actionLocation = "")
        {
            using (var galleristContext = new GalleristComponentsDbContext())
            {
                using (var identityContext = new ApplicationDbContext()) //may not need this anymore after adding the authorize helper
                {
                    var gameResponse = GameManager.GetGame(id, galleristContext);
                    var game         = gameResponse.Game;

                    //todo todo todo
                    //make sure the player taking an action is the current player
                    //compare current action to game state to make sure a valid action was taken (e.g. player can't move to board spot A from board spot A) [states..]
                    //todo make getting user by username a method (is it one already?)
                    var currentUser = identityContext.Users.FirstOrDefault(m => m.UserName == User.Identity.Name);

                    //todo refactor some of this into a game logic module
                    var player = game.Players.FirstOrDefault(p => p.UserId == currentUser.Id);
                    if (player == null)
                    {
                        return(View("GameError"));
                    }
                    if (player.Id != game.CurrentPlayerId)
                    {
                        return(View("GameError"));
                    }

                    var actionInvoker = new ActionContextInvoker(game);

                    if (!actionInvoker.DoAction(gameAction, actionLocation))
                    {
                        return(Redirect("~/Game/Play/" + id));
                    }

                    //check if it is one of the special cases where the action must be confirmed before allowing the next step to proceed (e.g. player must draw cards)
                    //if yes take an intermediate step, still remains current player's turn
                    //if no, continue doing logic things  //determine order of bumped player's actions, can these happen at the end of current player's turn?
                    //check player locations for action taken by current player to see if any players need to be "bumped" to another spot
                    //somewhere in here we need to inject bumped player into turn order, we also need a way to specify that the current "turn" for a bumped player is not a full turn [bumped turn flag or something]
                    //let said player take bumped turn if necessary
                    //again do the updatey
                    //need some signalr stuff so we can show the action to everyone when it is done (intermediate step or not) as well as update money, influence, board, etc.
                    //update money, influence, board, etc.
                    galleristContext.SaveChanges();

                    var nextPlayer = identityContext.Users.First(m => m.Id == game.CurrentPlayer.UserId);
                    if (nextPlayer.AllowsEmails)
                    {
                        var gameUrl    = Request.Url.GetLeftPart(UriPartial.Authority) + "/Game/Play/" + game.Id;
                        var emailTitle = nextPlayer.UserName + ", it is your turn!";
                        var emailBody  = "It is your turn in a game you are playing. You can take your turn by visiting The Gallerist Online" +
                                         " and viewing your active games or by clicking the following link: " + gameUrl;

                        EmailManager.SendEmail(emailTitle, emailBody, new List <string> {
                            nextPlayer.Email
                        });
                    }
                    PushHelper singleton = PushHelper.GetPushEngine();
                    singleton.RefreshGame(game.Players.Where(p => p.UserName != User.Identity.Name).Select(p => p.UserName).ToList());
                    return(Redirect("~/Game/Play/" + id));
                }
            }
        }
예제 #23
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);
            }
        }
예제 #24
0
 public void DoAction(GameAction action)
 {
     Action = action;
     State  = action.State;
     _state.DoAction(this);
 }
예제 #25
0
        public static ActionContext GetContext(GameActionState state, Game game)
        {
            Type contextType = ActionToContextType[state];

            return((ActionContext)Activator.CreateInstance(contextType, game));
        }
예제 #26
0
 /// <summary>
 /// The release.
 /// </summary>
 public void Release()
 {
     this.state = GameActionState.Released;
 }
예제 #27
0
 /// <summary>
 /// The reset.
 /// </summary>
 public void Reset()
 {
     this.state  = GameActionState.Released;
     this.amount = 0;
 }
 public bool IsValidTransition(GameActionState state)
 {
     if (Game.CurrentTurn.PendingActions.Any(a => a.State == state))
     {
         var action = new GameAction { State = state };
         return IsValidGameState(action);
     }
     return false;
 }
예제 #29
0
 public static void SetCurrentAction(this GameTurn turn, GameActionState state, string location)
 {
     if (turn.CurrentAction != null)
     {
         turn.AddCompletedAction(turn.CurrentAction);
     }
     turn.CurrentAction = new GameAction { State = state, Location = location, IsExecutable = true };
 }