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 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 |
// FLO Tetris #include <Pause.hpp> #include <conio.h> #include <windows.h> #include <iostream> using namespace std; #pragma comment (lib, "winmm.lib") // Prototypen void Steuerung (); void LinieLoesen (int *Pos1x, int *Pos1y, int *Pos2x, int *Pos2y, int *Pos3x, int *Pos3y, int *Pos4x, int *Pos4y, bool Besetzt); void Spielfeld (int *Pos1x, int *Pos1y, int *Pos2x, int *Pos2y, int *Pos3x, int *Pos3y, int *Pos4x, int *Pos4y, int *Art, bool Besetzt); // // Klassen class CObjekt { public: int Pos1x; int Pos1y; int Pos2x; int Pos2y; int Pos3x; int Pos3y; int Pos4x; int Pos4y; int Art; bool *ObjektUnten; public: void Fallen (int *Pos1y, int *Pos2y, int *Pos3y, int *Pos4y, bool Besetzt); void Drehen (int *Pos1x, int *Pos1y, int *Pos2x, int *Pos2y, int *Pos3x, int *Pos3y, int *Pos4x, int *Pos4y, int *Art, bool Besetzt); void LinksBewegen (int *Pos1x, int *Pos2x, int *Pos3x, int *Pos4x, bool Besetzt); void RechtsBewegen (int *Pos1x, int *Pos2x, int *Pos3x, int *Pos4x, bool Besetzt); CObjekt (); }; int main () { // Variablen srand (timeGetTime ()); bool Besetzt[24][30]; int x, y; for (x=0; x<24; x++) { for (y=0; y<30; y++) { Besetzt[x][y] = false; } } CObjekt Objekte[1000]; bool *bQuit = false; // BEI BEDARF ENTFERNEN int Zaehler = 0; // Legt die Instanz fest die benutzt werden soll while (*bQuit == true) { Spielfeld (&Objekte[Zaehler].Pos1x, &Objekte[Zaehler].Pos1y, &Objekte[Zaehler].Pos2x, &Objekte[Zaehler].Pos2y, &Objekte[Zaehler].Pos3x, &Objekte[Zaehler].Pos3y, &Objekte[Zaehler].Pos4x, &Objekte[Zaehler].Pos4y, &Objekte[Zaehler].Art, Besetzt); Objekte[Zaehler].Fallen (&Objekte[Zaehler].Pos1y, &Objekte[Zaehler].Pos2y, &Objekte[Zaehler].Pos3y, &Objekte[Zaehler].Pos4y, Besetzt); Steuerung (); } Pause (); return 0; } CObjekt::CObjekt () { Pos1x = 15; Pos1y = -1; Pos2x = 15; Pos2y = -1; Pos3x = 15; Pos3y = -1; Pos4x = 15; Pos4y = -1; Art = (rand()%4)+1; ObjektUnten = false; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
1>Tetris.obj : error LNK2028: Nicht aufgelöstes Token (0A000283) ""void __cdecl Spielfeld(int *,int *,int *,int *,int *,int *,int *,int *,int *,bool)" (?Spielfeld@@$$FYAXPAH00000000_N@Z)", auf das in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)" verwiesen wird. 1>Tetris.obj : error LNK2028: Nicht aufgelöstes Token (0A0002AB) ""void __cdecl Steuerung(void)" (?Steuerung@@$$FYAXXZ)", auf das in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)" verwiesen wird. 1>Tetris.obj : error LNK2028: Nicht aufgelöstes Token (0A0002C8) ""public: void __thiscall CObjekt::Fallen(int *,int *,int *,int *,bool)" (?Fallen@CObjekt@@$$FQAEXPAH000_N@Z)", auf das in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)" verwiesen wird. 1>Tetris.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""void __cdecl Steuerung(void)" (?Steuerung@@$$FYAXXZ)" in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)". 1>Tetris.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: void __thiscall CObjekt::Fallen(int *,int *,int *,int *,bool)" (?Fallen@CObjekt@@$$FQAEXPAH000_N@Z)" in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)". 1>Tetris.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""void __cdecl Spielfeld(int *,int *,int *,int *,int *,int *,int *,int *,int *,bool)" (?Spielfeld@@$$FYAXPAH00000000_N@Z)" in Funktion ""int __cdecl main(void)" (?main@@$$HYAHXZ)". 1>C:\Dokumente und Einstellungen\Eigene Dateien\Programmieren\Projekte\Tetris\Debug\Tetris.exe : fatal error LNK1120: 6 nicht aufgelöste externe Verweise. |
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 |
struct Feld { DWORD color; bool besetzt; }; struct Position { int x; int y; }; Feld spielfeld[20][10]; class Stein { public: enum Direction {Left, Right}; Stein(int type); bool CanFall(Feld [][10]); bool FallDown(); bool CanRotate(Direction); bool Rotate(Direction); Position GetPosition(int index); private: Position pos[4]; }; |
Quellcode |
|
1 2 3 4 |
Eine nicht behandelte Ausnahme des Typs "System.NullReferenceException" ist in Tetris.exe aufgetreten. Zusätzliche Informationen: Der Objektverweis wurde nich auf eine Objektinstanz festgelegt. |
C-/C++-Quelltext |
|
1 |
DWORD color; |
C-/C++-Quelltext |
|
1 |
enum Direction {Left, Right};
|
C-/C++-Quelltext |
|
1 |
Stein (int type);
|
C-/C++-Quelltext |
|
1 |
Position GetPosition(int index);
|
Zitat von »"ChrisJ"«
@ChrisJ
...
...
Zitat von »"ChrisJ"«
...
und benutz weniger Zeiger, das tut ja weh
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// ich gehe davon aus, das du eine "Feld" struktur oder etwas ähnliches nutzt for (unsinged i = 0; i < height; ++i) // jede reihe durchgehen { bool full = true; for (unsigned j = 0; j < width; ++j) // jetzt jeden platz { if (!feld[i][j].besetzt) // aha, ein leeres feld { full = false; break; } } if (full) // eine volle reihe { // alle höheren reihen eins tiefer setzen } } |
Zitat von »"Gotbread"«
die frage ist aber, wie sie verändert werden. du übergibst der methode
einen zeiger auf deine daten, die dann geändert werden. besser wäre
es aber wenn die methode das ergebniss zurückgeben würde, damit
die daten per zuweisung zugewiesen werden.
C-/C++-Quelltext |
|
1 |
Pos1x = BewegeNachLinks ();
|
Zitat von »"Gotbread"«
auch das bedeutet wieder, dass du das auch implementieren musst, aber dabei können wir dir später noch helfen.
Zitat von »"Gotbread"«
da die funktion nicht weiß, welchen der blöcke wir haben wollen, hat sie diesen parameter, z.b. "GetPosition(0)" holt den ersten "block".
Ich hätte da ein zweidimensionales Array benutzt.Zitat von »"Gotbread"«
// ich gehe davon aus, das du eine "Feld" struktur oder etwas ähnliches nutzt
C-/C++-Quelltext |
|
1 |
break;
|
C-/C++-Quelltext |
|
1 |
// eine volle reihe
|
Quellcode |
|
1 2 3 4 |
$(VCInstallDir)include $(VCInstallDir)atlmfc\include $(WindowsSdkDir)include $(FrameworkSDKDir)include |
Zitat von »"koschka"«
hier
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
Position GetPosition(int index) { if (index >= 0 && index < 4) // feld 0...3, da wir nur 4 felder haben return positions[index]; // "positions" ist ein array von Position in der Stein klasse return Position(-1, -1); // error. sollte niemals auftreten. // du darfst auch eine exception schmeißen, mit "__asm int 3" den // debugger zum anhalten zwingen oder einfach crashen: ++*(int*)0; } |
Werbeanzeige