summaryrefslogtreecommitdiff
path: root/AmpelJonas/cPeasantTrafficLight.cpp
blob: 6e348ab6cdeca1c0ddf5b162b498a59803374ae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "cPeasantTrafficLight.h"

cPeasantTrafficLight::cPeasantTrafficLight(int _type, int _startphase)
{
	iPhase = _startphase;
	iPhase == _CTL_COL_GREEN ? iPhase = _CTL_COL_RED : iPhase = _CTL_COL_GREEN; //switch arround bc switch occurs before lights are switched
	iType = _type;

	_type % 2 == 0 ? tl = new cObject(1, 2) : tl = new cObject(2, 1);

	//tl->setPosition(_SIZE_X_ / 2, _SIZE_Y_ / 2);

	switch (_type)
	{
	case _CTL_1:
		tl->setPosition(_SIZE_X_ / 2 - 9, _SIZE_Y_ / 2 - 6);
		break;
	case _CTL_4:
		tl->setPosition(_SIZE_X_ / 2 + 10, _SIZE_Y_ / 2 - 6);
		break;
	case _CTL_5:
		tl->setPosition(_SIZE_X_ / 2 + 10, _SIZE_Y_ / 2 + 5);
		break;
	case _CTL_8:
		tl->setPosition(_SIZE_X_ / 2 - 9, _SIZE_Y_ / 2 + 5);
		break;
	case _CTL_2:
		tl->setPosition(_SIZE_X_ / 2 - 8, _SIZE_Y_ / 2 - 7);
		break;
	case _CTL_3:
		tl->setPosition(_SIZE_X_ / 2 + 7, _SIZE_Y_ / 2 - 7);
		break;
	case _CTL_6:
		tl->setPosition(_SIZE_X_ / 2 + 7, _SIZE_Y_ / 2 + 7);
		break;
	case _CTL_7:
		tl->setPosition(_SIZE_X_ / 2 - 8, _SIZE_Y_ / 2 + 7);
		break;
	}

	next();
}

cPeasantTrafficLight::~cPeasantTrafficLight()
{
	delete tl;
}

void cPeasantTrafficLight::next()
{
	iPhase == _CTL_COL_GREEN ? iPhase = _CTL_COL_RED : iPhase = _CTL_COL_GREEN;
	switch (iType)
	{
	case _CTL_1:
	case _CTL_4:
		tl->drawPoint('o', sPos{ 0,0 }, true, _COL_DEFAULT);
		tl->drawPoint('o', sPos{ 0,1 }, true, _COL_DEFAULT);
		iPhase == _CTL_COL_GREEN ? tl->drawPoint('o', sPos{ 0,1 }, true, _COL_GREEN) : tl->drawPoint('o', sPos{ 0,0 }, true, _COL_RED);
		break;
	case _CTL_5:
	case _CTL_8:
		tl->drawPoint('o', sPos{ 0,0 }, true, _COL_DEFAULT);
		tl->drawPoint('o', sPos{ 0,1 }, true, _COL_DEFAULT);
		iPhase == _CTL_COL_GREEN ? tl->drawPoint('o', sPos{ 0,0 }, true, _COL_GREEN) : tl->drawPoint('o', sPos{ 0,1 }, true, _COL_RED);
		break;
	case _CTL_2:
	case _CTL_7:
		tl->drawPoint('o', sPos{ 0,0 }, true, _COL_DEFAULT);
		tl->drawPoint('o', sPos{ 1,0 }, true, _COL_DEFAULT);
		iPhase == _CTL_COL_GREEN ? tl->drawPoint('o', sPos{ 1,0 }, true, _COL_GREEN) : tl->drawPoint('o', sPos{ 0,0 }, true, _COL_RED);
		break;
	case _CTL_6:
	case _CTL_3:
		tl->drawPoint('o', sPos{ 0,0 }, true, _COL_DEFAULT);
		tl->drawPoint('o', sPos{ 1,0 }, true, _COL_DEFAULT);
		iPhase == _CTL_COL_GREEN ? tl->drawPoint('o', sPos{ 0,0 }, true, _COL_GREEN) : tl->drawPoint('o', sPos{ 1,0 }, true, _COL_RED);
		break;
	}
}

cObject *cPeasantTrafficLight::getObject()
{
	return tl;
}