public delegate void State(); // create anonymous delegate "void function()"
public void SetGameState(State newState) { // lastState = currentState; // not used yet.. GameState -= currentState; // unsubscribe current function currentState = newState; // assign new function to the variable GameState += currentState; // subscribe the new function gameSubState = GSS.GSS_0; // apply initial game sub state. } protected override void OnNavigatedTo(NavigationEventArgs e) { SetGameState(DoState1); // assign the 1st state to DoState1() masterGameTimer = new GameTimer(); masterGameTimer.UpdateInterval = TimeSpan.FromTicks(333333); masterGameTimer.Update += OnUpdate; masterGameTimer.Start(); } private void OnUpdate(object sender, GameTimerEventArgs e) { GameState(); // this redirects execution to the assigned state } private void DoState1() // 1st state { SetGameState(DoState2); } private void DoState2() // 2nd state { SetGameState(DoState1); // and back around we go! }
-(void)SetGameState:(SEL) newState // assign a new state { gameState=newState; gameSubState=GSS_0; } -(void)viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:0.033f target:self selector:@selector(Update:) userInfo:nil repeats:YES]; [SetGameState DoState1]; // set an initial gameState } -(void)DoState1: (id) sender { [SetGameState DoState2]; // first state, } -(void)DoState2: (id) sender { [SetGameState DoState1]; // then 2nd state, and back around } -(void)Update: (id) sender { [self.gameState]; // this won't work, but the idea would be to execute the assigned state. and programatically change it. }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)