Add a CMakeLists.txt to each exercise directory, included from cmat/CMakeLists.txt, so every exercise and solution becomes a buildable target. GUI exercises link the curses-based DOS_Unix implementations on Unix-like systems; the Windows-specific DOS variants are not compiled. Exercises without a portable path or with missing dependencies (Boost) are reported as not available at configure time. Targets are excluded from the default build and built by name, e.g. `cmake --build build --target Ex11`, so intentionally buggy exercises such as Ex21 do not break the default build. Also fix two portability issues: rename Ex11bug/pole.h to Pole.h for case-sensitive filesystems and drop the extra Light:: qualification in SolutionEx71A/Light.h. Document build commands and layout in AGENTS.md. Co-authored-by: Qwen 3.8 27B <qwen3.8_27b-q3_k_xl@lmstudio.local>
61 lines
3.0 KiB
C++
61 lines
3.0 KiB
C++
#include "Pole.h"
|
|
#include "Screen.h"
|
|
|
|
Pole::Pole(int x, int y) : waitLight(new Light("WAIT", x + 6, y + 12, Screen::WHITE)) {
|
|
using namespace Screen; // we will discuss namespaces in the course
|
|
|
|
lights[RED_LIGHT] = new Light("*", x + 11, y + 3, RED);
|
|
lights[RED_MAN] = new Light("*<-=", x + 6, y + 4, RED);
|
|
lights[YELLOW_LIGHT] = new Light("*", x + 11, y + 5, YELLOW);
|
|
lights[GREEN_LIGHT] = new Light("*", x + 11, y + 7, GREEN);
|
|
lights[GREEN_MAN] = new Light("*|-<", x + 6, y + 7, GREEN);
|
|
|
|
write(" _____ ", x, ++y, GRAY);
|
|
write(" /___ /| ", x, ++y, GRAY);
|
|
write(" | | | ", x, ++y, GRAY);
|
|
write(" | |/| ", x, ++y, GRAY);
|
|
write(" |____| | ", x, ++y, GRAY);
|
|
write(" | |/| ", x, ++y, GRAY);
|
|
write(" | | | ", x, ++y, GRAY);
|
|
write(" |____|/ ", x, ++y, GRAY);
|
|
write(" _||__ ", x, ++y, GRAY);
|
|
write(" /___ /| ", x, ++y, GRAY);
|
|
write(" | | | ", x, ++y, GRAY);
|
|
write(" | | | ", x, ++y, GRAY);
|
|
write(" |____|/ ", x, ++y, GRAY);
|
|
write(" || ", x, ++y, GRAY);
|
|
write(" || ", x, ++y, GRAY);
|
|
write(" || ", x, ++y, GRAY);
|
|
write(" || ", x, ++y, GRAY);
|
|
write(" || ", x, ++y, GRAY);
|
|
write(" || ", x, ++y, GRAY);
|
|
write("========||===========", x, ++y, GRAY);
|
|
write(" / || / ", x, ++y, GRAY);
|
|
write("_ /_________ /_ ", x, ++y, GRAY);
|
|
write("/ / ", x, ++y, GRAY);
|
|
}
|
|
|
|
Pole::~Pole() {
|
|
for (int i = 0; i < sizeof lights / sizeof(lights[0]); ++i)
|
|
delete lights[i];
|
|
delete waitLight;
|
|
}
|
|
|
|
void Pole::setTrafficLights(Pelican::PelicanState state) {
|
|
|
|
static const Light::LightState LightStates[Pelican::YELLOW_STATE + 1][RED_MAN + 1] = {
|
|
// red yellow green green man red man
|
|
{Light::LightState::ON, Light::LightState::OFF, Light::LightState::OFF, Light::LightState::ON, Light::LightState::OFF}, // red
|
|
{Light::LightState::OFF, Light::LightState::FLASH, Light::LightState::OFF, Light::LightState::FLASH, Light::LightState::OFF}, // y flash
|
|
{Light::LightState::OFF, Light::LightState::OFF, Light::LightState::ON, Light::LightState::OFF, Light::LightState::ON}, // g time
|
|
{Light::LightState::OFF, Light::LightState::OFF, Light::LightState::ON, Light::LightState::OFF, Light::LightState::ON}, // g idle
|
|
{Light::LightState::OFF, Light::LightState::ON, Light::LightState::OFF, Light::LightState::OFF, Light::LightState::ON} // yellow
|
|
};
|
|
|
|
for (int i = RED_LIGHT; i <= RED_MAN; i++) {
|
|
lights[i]->set(LightStates[state][i]);
|
|
}
|
|
}
|
|
|
|
void Pole::setWaitLight(bool pressed) { waitLight->set(pressed ? Light::LightState::ON : Light::LightState::OFF); }
|