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 |
void CClass::function(struct S_structure* example[]) |
C-/C++-Quelltext |
|
1 |
instance->function(example); |
C-/C++-Quelltext |
|
1 2 3 4 5 |
struct S_structure{ int a; int b;}; S_structure* example[3]; example[0]->a = 1; example[0]->b = 4; example[1]->a = 5; example[1]->b = 6; example[2]->a = 3; example[2]->b = 6; |
C-/C++-Quelltext |
|
1 |
instance->function(example[]); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Typ« (03.04.2016, 20:10) aus folgendem Grund: Neues Problem, ich wollte aber keinen neuen Thread aufmachen, da es wahrscheinlich nur eine Kleinigkeit ist, und mit dem vorherigen Problem zusammenhängt
Zitat
"void CPlayer::Init(CPlayer:_Place** place). Fehler: Die Deklaration ist nicht mit ""void CPlayer::Init(S_Place** place)(deklariert in Zeiler 17 von d:\Programmierung\c++\games\backgammon\backgammon\player.hpp)"" kompatibel
@Koschi: Danke für die Fehlerberichtigung
Muss ich den extra Parameter übergeben, damit das Ganze überhaupt funktioniert, oder nur damit ich damit arbeiten kann? Weil die größe ist immer gleich, ich hätte das deshalb selbst in die Funktion geschrieben
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
// project: backgammon // file: Game.cpp // author: Lukas Mrosek // #include <SDL2\SDL.h> #include <iostream> #include "Game.hpp" #include "structures.hpp" void CGame::Init() { // variables width = 2000/2; // the images size halved high = 1374/2; // the images size halved running = true; // initialize SDL if (SDL_Init(SDL_INIT_EVERYTHING) != 0) // initialize SDL { std::cerr << "SDL ERROR! MSG:" << SDL_GetError() << std::endl; exit(-1); } // initialize window window = SDL_CreateWindow("Backgammon", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, high, SDL_WINDOW_SHOWN); if (window == NULL) { std::cerr << "SDL WINDOW ERROR! MSG:" << SDL_GetError() << std::endl; exit(-1); } // initialize renderer renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if (renderer == NULL) { std::cerr << "SDL RENDERER ERROR! MSG:" << SDL_GetError() << std::endl; exit(-1); } // initialize background std::cout << "1" << std::endl; background = new CTexture(renderer, "background.bmp"); background->Draw(0, 0, width, high); // initialize gamefield std::cout << "2" << std::endl; setPlaceProperties(); // initialize players std::cout << "3" << std::endl; player1->Init(renderer, place, 1); std::cout << "4" << std::endl; } void CGame::Run() { while (running) // while true: game is running { Event(); // check all the user inputs Update(); // update the game } } void CGame::Stop() { // stop all the instances SDL_Quit; // quit game } // recall events void CGame::Event() { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: // when pressing the "X", stop game running = false; break; } } } // update the game void CGame::Update() { // clear old screen SDL_RenderClear(renderer); // draw new images to the renderer background->Draw(0, 0, width, high); // schow renderer SDL_RenderPresent(renderer); } // set the properties for every place void CGame::setPlaceProperties() { // stone kind 0 = nothing // stone kind 1 = black // stone kind 2 = white std::cout << "5" << std::endl; //////////////////////////////// // Hier stürt das Programm ab // place[0]->stoneKind = 1; place[0]->numberOfStones = 2; place[0]->xPos = 910; place[0]->yPos = 10; place[1]->stoneKind = 0; place[1]->numberOfStones = 0; place[1]->xPos = 830; place[1]->yPos = 10; place[2]->stoneKind = 0; place[2]->numberOfStones = 0; place[2]->xPos = 750; place[2]->yPos = 10; place[3]->stoneKind = 0; place[3]->numberOfStones = 0; place[3]->xPos = 670; place[3]->yPos = 10; place[4]->stoneKind = 0; place[4]->numberOfStones = 0; place[4]->xPos = 590; place[4]->yPos = 10; place[5]->stoneKind = 2; place[5]->numberOfStones = 5; place[5]->xPos = 510; place[5]->yPos = 10; place[6]->stoneKind = 0; place[6]->numberOfStones = 0; place[6]->xPos = 430; place[6]->yPos = 10; place[7]->stoneKind = 2; place[7]->numberOfStones = 3; place[7]->xPos = 350; place[7]->yPos = 10; place[8]->stoneKind = 0; place[8]->numberOfStones = 0; place[8]->xPos = 270; place[8]->yPos = 10; place[9]->stoneKind = 0; place[9]->numberOfStones = 0; place[9]->xPos = 190; place[9]->yPos = 10; place[10]->stoneKind = 0; place[10]->numberOfStones = 0; place[10]->xPos = 110; place[10]->yPos = 10; place[11]->stoneKind = 1; place[11]->numberOfStones = 5; place[11]->xPos = 30; place[11]->yPos = 10; place[12]->stoneKind = 2; place[12]->numberOfStones = 5; place[12]->xPos = 30; place[12]->yPos = 677; place[13]->stoneKind = 0; place[13]->numberOfStones = 0; place[13]->xPos = 110; place[13]->yPos = 677; place[14]->stoneKind = 0; place[14]->numberOfStones = 0; place[14]->xPos = 190; place[14]->yPos = 677; place[15]->stoneKind = 0; place[15]->numberOfStones = 0; place[15]->xPos = 270; place[15]->yPos = 677; place[16]->stoneKind = 1; place[16]->numberOfStones = 3; place[16]->xPos = 350; place[16]->yPos = 677; place[17]->stoneKind = 0; place[17]->numberOfStones = 0; place[17]->xPos = 430; place[17]->yPos = 677; place[18]->stoneKind = 1; place[18]->numberOfStones = 5; place[18]->xPos = 510; place[18]->yPos = 677; place[19]->stoneKind = 0; place[19]->numberOfStones = 0; place[19]->xPos = 590; place[19]->yPos = 677; place[20]->stoneKind = 0; place[20]->numberOfStones = 0; place[20]->xPos = 670; place[20]->yPos = 677; place[21]->stoneKind = 0; place[21]->numberOfStones = 0; place[21]->xPos = 750; place[21]->yPos = 677; place[22]->stoneKind = 0; place[22]->numberOfStones = 0; place[22]->xPos = 830; place[22]->yPos = 677; place[23]->stoneKind = 2; place[23]->numberOfStones = 2; place[23]->xPos = 910; place[23]->yPos = 677; } |
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 |
// project: backgammon // file: Game.hpp // author: Lukas Mrosek // #include <SDL2\SDL.h> #include "Texture.hpp" #include "Player.hpp" #include "structures.hpp" #pragma once class CGame { public: // member functions void Init(); // initialize game void Run(); // run the game void Stop(); // stop game and close window // member variables private: // member functions void Event(); // recall new events void Update(); // update the game void setPlaceProperties(); // set the place's properties (number of stones, stone kind, etc) // member variables S_place* place[24]; // all the place's properties SDL_Window* window; // the window SDL_Renderer* renderer; // the renderer SDL_Event event; // user event CTexture* background; // the game field CPlayer* player1; // the first player CPlayer* player2; // the second player bool running; // while true: game is running int high; // the window's high int width; // the window's width }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
#pragma once struct S_place // properties of a place { int stoneKind; // kind of stone (black or white) int numberOfStones; // number of stones on this field int xPos; // x position of this place int yPos; // y position of this place }; |
Werbeanzeige