Go to Post Cooperate BEHIND the curtain; compete IN FRONT OF it. - Travis Hoffman [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #20   Spotlight this post!  
Unread 03-05-2014, 14:27
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: Share you Autonomous

Quote:
Originally Posted by notmattlythgoe View Post
Code:
public class DecisionCommand extends Command {

public DecisionCommand (IProvidesDecision decision, Command trueCommand, Command falseCommand) {}

   public void initialize() {
      if (decision.getValue()) {
         trueCommand.initialize();
      } else {
         falseCommand.initialize());
      }
   }

   public void execute() {
      if (decision.getValue()) {
         trueCommand.execute();
      } else {
         falseCommand.execute());
      }

   etc...
}
That looks like it would work. I was pretty sure it would be possible to do something but I thought it might get really ugly really fast. That's a pretty slick way to do it.

Here's something you could do if you wanted to be avoid duplicating the end of command conditions in the subsequent if:
Code:
class Continuable extends Command{
	//I don't remember whether I've set this class up is valid Java...

	//this would return self unless you wnated to run a different command.
	abstract public Continuable next();

	public bool isFinished(){
		return next()==null;
	}
}

class Continues extends Command{
	Continuable current;

	Continues(Continuable cmd){
		current=cmd;
	}

	void initialize(){
		if(current!=null) current.initialize();
	}

	void execute(){
		if(current!=null){
			current.execute();
		}
	}

	bool isFinished(){
		if(current==null) return 1;
		current=current.next();
		return current==null;
	}
}
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 23:57.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi