Im Getting a but load of errors I have to make a traffic light. Im thinking I have things mixed around or something. any help is appreciated. I know basically I have to draw each rectangle and make it sleep for a duration of time.
void TrafficLight::Advance()
{
switch (color)
{
case RED: color = GREEN; break;
case YELLOW: color = RED; break;
case GREEN: color = YELLOW; break;
}
};
void TrafficLight::Wait()
{
//Sleep
Sleep(1000);
}
char* TrafficLight::CurrentColor()
{
switch (color)
{
case RED: return "Red"; break;
case YELLOW: return "Yellow"; break;
case GREEN: return "Green"; break;
}
return "Error";
}
int main()
{
cout << TrafficLight::drawRect(int x, int y, int 14, int , byte color) <<
drawRect(int x, int y, int width, int height, byte color) <<
drawRect(int x, int y, int width, int height, byte color) <<
drawRect(int x, int y, int width, int height, byte color);
}
enum LightState { RED = 0, YELLOW, GREEN };
const byte GREEN = 0xA0;
const byte YELLOW = 0xE0;
const byte RED = 0xC0;
const byte GRAY = 0x80;
const byte BLACK = 0x00;
You cannot put initialization in there.
enum LightState { RED = 0xA0, YELLOW = 0xE0, GREEN = 0xC0, GRAY = 0x80, BLACK = 0x00 };
Better like this.
1 2 3 4 5 6 7
TrafficLight::TrafficLight()
{
color RED; // Here you missed = character for assignment
wait[RED] = 10 * 1000;
wait[YELLOW] = 4 * 1000;
wait[GREEN] = 15 * 1000;
}
1 2 3 4 5 6 7 8
void TrafficLight::Advance()
{
switch (color)
{
case RED: color = GREEN; break; //It has to be LightState::GREEN
case YELLOW: color = RED; break; //It has to be LightState::RED
case GREEN: color = YELLOW; break; //It has to be LightState::YELLOW
}
1 2 3 4 5 6 7
int main()
{
cout << TrafficLight::drawRect(int x, int y, int 14, int , byte color) <<
drawRect(int x, int y, int width, int height, byte color) <<
drawRect(int x, int y, int width, int height, byte color) <<
drawRect(int x, int y, int width, int height, byte color);
}
DrawRect is not a static function so you need to instantiate an object of TrafficLight type to use it (or make it static. Fixed that, drawRect return void so you cannot giving the result type of drawRect as input of the cout stream. Then the function calling doesn't have any sense, it's like a function sign declaration.
Ok, so youre saying to put initialize them all with in the enum LightState statement instead of underneath like I have them. also should I go ahead and take the drawRect out of my class, or can I code the integers in the class and call them properly as you stated above
I see the draw rect as a private function of the TrafficLight class; in my vision the class expose a function that take a color as input and hide all the drawing stuff to the user.