protected ActionContext(Game game, Dictionary <GameActionState, Type> NameToState) { Game = game; Action = game.CurrentTurn.CurrentAction; this.NameToState = NameToState; State = Game.CurrentTurn.CurrentAction.State; }
/// <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; } }
public void DoAction(GameActionState state) { Action = new GameAction { State = state, IsExecutable = true, Location = "" }; State = Action.State; _state.DoAction(this); }
// 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; }
// 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); }
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; }
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; }
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); }
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); }
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); } }
// 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); } }
// 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; } }
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; }
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); }
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); }
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); } } }
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; }
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)); } } }
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); } }
public void DoAction(GameAction action) { Action = action; State = action.State; _state.DoAction(this); }
public static ActionContext GetContext(GameActionState state, Game game) { Type contextType = ActionToContextType[state]; return((ActionContext)Activator.CreateInstance(contextType, game)); }
/// <summary> /// The release. /// </summary> public void Release() { this.state = GameActionState.Released; }
/// <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; }