Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
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 |
class smallrect { private: RECT rect_to_draw; const static int s_width = 10; const static int s_height = 10; int i_mcolor_r; int i_mcolor_g; int i_mcolor_b; public: void RandomColor(); void CalculateRect(); void Draw_small_rect(); void Delete_small_rect(); void Draw(); }; |
C-/C++-Quelltext |
|
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 |
void smallrect::RandomColor() { i_mcolor_r = random(0,254); //RGB-Farbwerte generieren i_mcolor_g = random(0,254); // "" i_mcolor_b = random(0,254); // "" } void smallrect::CalculateRect() { RECT mainrect; //Rect für den Clientbereich GetClientRect(hWnd,&mainrect); //Größe des Clientbereich holen int i_xPosition = random(0,mainrect.right); //einen x-Wert aus der Breite des Clientbereich generieren int i_yPosition = random(0,mainrect.bottom); //einen y-Wert aus der Höhe des Clientbereich generieren rect_to_draw.top = i_yPosition; rect_to_draw.left = i_xPosition; rect_to_draw.bottom = i_yPosition - s_height; rect_to_draw.right = i_xPosition - s_width; } void smallrect::Draw_small_rect() { HDC hDC = GetDC(hWnd); HBRUSH hBR = CreateSolidBrush(RGB(i_mcolor_r,i_mcolor_g,i_mcolor_b)); FillRect(hDC,&rect_to_draw,hBR); DeleteObject(hBR); ReleaseDC(hWnd,hDC); } void smallrect::Delete_small_rect() { POINTS points = MAKEPOINTS(lParam); if(points.x > rect_to_draw.left && points.x < rect_to_draw.right && points.y > rect_to_draw.bottom && points.y > rect_to_draw.top) { HDC hDC = GetDC(hWnd); RECT rc; GetClientRect(hWnd,&rc); FillRect(hDC,&rc,CreateSolidBrush(RGB(255,255,255))); ReleaseDC(hWnd,hDC); } } void smallrect::Draw() { RandomColor(); CalculateRect(); Draw_small_rect(); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
void DrawRects() { if(iRectCounter == 0) { smallrect srect; srect.Draw(); RectCounter = 1; } } |
C-/C++-Quelltext |
|
1 |
void smallrect::Delete_small_rect (const POINT& point) { ... } |
C-/C++-Quelltext |
|
1 |
std::vector<smallrect> rectangles; |
C-/C++-Quelltext |
|
1 |
rectangles[i].Delete_small_rect (point); |
C-/C++-Quelltext |
|
1 2 3 |
smallrect rectangle; rectangle.Draw (); // Erzeugt Koordinaten und Farbe und zeichnet sich rectangles.push_back (rectangle); // Merken, damit die Koordinaten nicht verloren gehen |
Zitat von »"spacegaier"«
Heißt das, dass ich die Draw-Methode nicht brauche (die funktioniert nämlich nicht) und ich einfach in der Draw_small_rect-Methode die beiden Randomfunktionen aufrufe?
C-/C++-Quelltext |
|
1 |
void smallrect::Delete_small_rect (const POINT& point) { ... } |
C-/C++-Quelltext |
|
1 |
POINT point = MAKEPOINT (lParam);
|
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void smallrect::Draw_small_rect() { RandomColor(); CalculateRect(); HDC hDC = GetDC(hWnd); HBRUSH hBR = CreateSolidBrush(RGB(i_mcolor_r,i_mcolor_g,i_mcolor_b)); FillRect(hDC,&rect_to_draw,hBR); DeleteObject(hBR); ReleaseDC(hWnd,hDC); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class smallrect { private: RECT rect_to_draw; const static int s_width = 10; const static int s_height = 10; int i_mcolor_r; int i_mcolor_g; int i_mcolor_b; public: void RandomColor(); void CalculateRect(); void Draw_small_rect(); void Delete_small_rect(const POINTS points); }; |
Zitat von »"spacegaier"«
Frage: Nachfolgender Code (Draw-Funktion) generiert ja Ort und Farbe. Sind diese Werte dann nur für diese Funktion in dem in der Klasse definiertem RECT drin?
Zitat von »"spacegaier"«
C-/C++-Quelltext
1 2 3 4 if (points.x > s_rc.rect_to_draw.left && points.x < s_rc.rect_to_draw.right && points.y > s_rc.rect_to_draw.bottom && points.y > s_rc.rect_to_draw.top)
Werbeanzeige