Created
December 1, 2011 18:00
-
-
Save basicxman/1418606 to your computer and use it in GitHub Desktop.
MMRambotics OOP Lessons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RobotClasses.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
class Robot { | |
public: | |
string teamName; | |
Robot(string name): | |
teamName(name) | |
{ | |
cout << endl; | |
} | |
void Autonomous(int length) { | |
cout << "Team " << teamName << " is entering autonomous mode for " << length << " seconds." << endl; | |
} | |
void TeleOp(int length) { | |
cout << "Team " << teamName << " is entering tele op mode for " << length << " seconds." << endl; | |
} | |
}; | |
class Simbot : public Robot { | |
public: | |
Simbot(string name) : Robot(name) {} | |
void Autonomous(int length) { | |
for (int i = 0; i < length; i++) { | |
cout << teamName << " "; | |
} | |
cout << endl; | |
} | |
}; | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
Robot robot = Robot(""); | |
cout << robot.teamName << endl; | |
Robot rambot = Robot("MMRambotics"); | |
rambot.Autonomous(10); | |
Simbot simbot = Simbot("Simbotics"); | |
simbot.Autonomous(10); | |
int temp; cin >> temp; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Robot(object): | |
def __init__(self, team_name = None): | |
self.team_name = team_name | |
def autonomous(self, length): | |
print "Team %s is entering autonomous mode for %d seconds!" % (self.team_name, length) | |
def tele_op(self, length): | |
print "Team %s is entering tele operated mode for %d seconds!" % (self.team_name, length) | |
class Simbot(Robot): | |
def autonomous(self, length): | |
print (self.team_name + " ") * length | |
robot = Robot(None) | |
robot.autonomous(10) | |
robot.tele_op(120) | |
rambot = Robot("MMRambotics") | |
rambot.autonomous(10) | |
rambot.tele_op(120) | |
simbot = Simbot("Simbotics") | |
simbot.autonomous(10) | |
simbot.tele_op(120) | |
print "\nExecuting autonomous mode for all robots on the field!" | |
robots_on_the_field = [robot, rambot, simbot] | |
for current_robot in robots_on_the_field: | |
current_robot.autonomous(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def autonomous(robot, length): | |
print "Team %s is entering autonomous mode for %d seconds!" % (robot["team_name"], length) | |
def tele_op(robot, length): | |
print "Team %s is entering tele operated mode for %d seconds!" % (robot["team_name"], length) | |
def simbotics_autonomous(robot, length): | |
print (robot["team_name"] + " ") * length | |
robot = { | |
"autonomous": autonomous, | |
"tele_op": tele_op, | |
"team_name": None | |
} | |
robot["autonomous"](robot, 10) | |
robot["tele_op"](robot, 120) | |
rambot = robot.copy() | |
rambot["team_name"] = "MMRambotics" | |
simbot = robot.copy() | |
simbot["team_name"] = "Simbotics" | |
simbot["autonomous"] = simbotics_autonomous | |
robots_on_the_field = [rambot, simbot] | |
for current_robot in robots_on_the_field: | |
current_robot["autonomous"](current_robot, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment