public ActionResult sync(StatePackage package) { foreach (GammerState gammer in package.gammers) { sync(gammer); } foreach (GameState info in package.infos) { sync(info); } IList <GammerState> gammers = GammerStates .Where(s => s.Value.group.StartsWith(package.group)) .Select(g => g.Value) .ToList(); IList <GameState> infos = GameStates .Where(s => s.Value.group.StartsWith(package.group)) .Select(g => g.Value) .ToList(); return(Result(new StatePackage() { group = package.group, infos = infos, gammers = gammers })); }
public void Undo() { if (UndoAvailable()) { StatePackage state = (StatePackage)undo_stack.Pop(); state.ResetState(); ResetElevatorLevel(state.elevator_level); state.Destroy(); } }
public void RecordUndo(GameObject character) { StatePackage state = new StatePackage(character); //Debug.Log("Recorded " + character.name + " at pos " + position); GameObject[] boxes = GameObject.FindGameObjectsWithTag("Box"); foreach (GameObject box in boxes) { state.AddObject(box); } state.elevator_level = elevator_level; undo_stack.Push(state); }
public override RuntimeValueWrapper Execute(DoExpression e, RuntimeContext context) { Func <RuntimeValueWrapper[], RuntimeValueWrapper> monadFunction = arguments => { StatePackage result = new StatePackage() { result = null, state = arguments[0] }; RuntimeContext newContext = new RuntimeContext() { PreviousContext = context }; newContext.Values.Add("return", RuntimeValueWrapper.CreateFunction(ReturnStateMonadValue, 2)); foreach (Expression expression in e.Expressions) { VarExpression var = expression as VarExpression; if (var == null) { expression.BuildContext(newContext); result = RunStateMonad(new RuntimeValueWrapper(new RuntimeUnevaluatedValue(expression), newContext), result.state); } else { result = RunStateMonad(new RuntimeValueWrapper(new RuntimeUnevaluatedValue(var.Expression), newContext), result.state); if (!var.Pattern.Match(newContext, result.result)) { throw new Exception("模式匹配不成功。"); } } if (!(bool)continueFunction.Invoke(result.state).RuntimeObject) { break; } } if (result.result == null) { result.result = RuntimeValueWrapper.CreateValue(new object()); } return(RuntimeValueWrapper.CreateValue(result)); }; return(RuntimeValueWrapper.CreateFunction(monadFunction, 1)); }