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
Anonymous
unregistriert
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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
/* Kampftest Version: 1.0 author : Simon Klausner */ #include <iostream> using namespace std; //Classes class CHero { public: //Classvariables int m_Damage, m_Hitpoints, m_Strength, m_Intelligence, m_Manapoints; char m_chName[30]; //Classfunctions CHero(int *pStrength, int *pIntelligence); void Attack(); int CastAttack(); void SpecialAttack(); void GetItem(); void ShowStats(); }; //Constructor Hero CHero :: CHero(int *pStrength, int *pIntelligence) { m_Strength = *pStrength; m_Intelligence = *pIntelligence; m_Hitpoints = m_Strength * 5; m_Manapoints = m_Intelligence * 3; m_Damage = m_Strength * 3; cout << "Der Held startet mit " << m_Strength << " Staerke und " << m_Intelligence << " Intelligenz." << endl; cout << "Der Held hat " << m_Hitpoints << " Leben und " << m_Manapoints << " Mana." << endl; } void CHero::ShowStats() { cout << "Verbleibende Leben: "<< m_Hitpoints << endl; cout << "Verbleibende Mana: "<< m_Manapoints << endl; } void CHero::Attack() { cout << "Euer Charakter richtet " << m_Damage << " Schaden an!" << endl; } int CHero::CastAttack() { //Variables int Damage = 0; int Auswahl = 0; if (m_Intelligence <= 10) { cout << "1 - Feuerblitz" << endl; cout << "Eingabe: "; cin >> Auswahl; } else if (m_Intelligence >10 && m_Intelligence <= 20) { cout << "1 - Feuerblitz" << endl; cout << "2 - Eisblitz" << endl; cout << "Eingabe: "; cin >> Auswahl; } else if (m_Intelligence >20 && m_Intelligence <= 30) { cout << "1 - Feuerblitz" << endl; cout << "2 - Eisblitz" << endl; cout << "3 - Blitz" << endl; cout << "Eingabe: "; cin >> Auswahl; } else if (m_Intelligence >30 && m_Intelligence <= 40) { cout << "1 - Feuerblitz" << endl; cout << "2 - Eisblitz" << endl; cout << "3 - Blitz" << endl; cout << "4 - Schlammbombe" << endl; cout << "Eingabe: "; cin >> Auswahl; } else { cout << "1 - Feuerblitz" << endl; cout << "2 - Eisblitz" << endl; cout << "3 - Blitz" << endl; cout << "4 - Schlammbombe" << endl; cout << "5 - Feuerball" << endl; cout << "Eingabe: "; cin >> Auswahl; } if (Auswahl == 1 && m_Manapoints > 5) { cout << endl; m_Manapoints -= 5; cout << "Feuerblitz wird gezaubert." << endl; return 25; } else if (Auswahl == 2 && m_Manapoints > 5) { cout << endl; m_Manapoints -= 8; cout << "Eisblitz wird gezaubert." << endl; return 35; } else if (Auswahl == 3 && m_Manapoints > 5) { cout << endl; m_Manapoints -= 10; cout << "Blitz wird gezaubert." << endl; return 55; } else if (Auswahl == 4 && m_Manapoints > 5) { cout << endl; m_Manapoints -= 15; cout << "Schlammbombe wird gezaubert." << endl; return 75; } else if (Auswahl == 5 && m_Manapoints > 5) { cout << endl; m_Manapoints -= 25; cout << "Feuerball wird gezaubert." << endl; return 100; } else { cout << endl; cout << "Fehler in der Eingabe oder zu wenig Mana." << endl; return 0; } } void CHero::GetItem() { //Variables int ItemNumber[3]; ItemNumber[1] = 5; ItemNumber[2] = 4; ItemNumber[3] = 2; int Auswahl = 0; cout << "Beutel: " << endl; cout << "1 - Heiltrank (" << ItemNumber[1] << "x) - Stellt 100 Hitpoints wieder her." << endl; cout << "2 - Manatrank (" << ItemNumber[2] << "x) - Stellt 75 Manapunkte wieder her." << endl; cout << "3 - Trank des Lebens (" << ItemNumber[3] << "x) - Stellt 125 Leben und 50 Manapunkte wieder her." << endl; cout << "Eingabe: "; cin >> Auswahl; if (Auswahl == 1 && ItemNumber[1] > 0) { m_Hitpoints += 100; ItemNumber[1] --; } else if (Auswahl == 2 && ItemNumber[2] > 0) { m_Manapoints += 75; ItemNumber[2] --; } else if (Auswahl == 3 && ItemNumber[3] > 0) { m_Manapoints += 50; m_Hitpoints += 125; ItemNumber[3] --; } else cout << "Fehler in der Eingabe!" << endl; } class CEnemy { public: //Classvariables int m_HitpointsEnemy, m_DamageEnemy; char m_chNameEnemy[30]; //Classfunctions CEnemy(); void Attack(); int CastAttack(); void SpecialAttack(); void ShowStats(); }; CEnemy::CEnemy() { m_HitpointsEnemy = 0, m_DamageEnemy = 0; sprintf (m_chNameEnemy, "Noone"); } void CEnemy::ShowStats() { cout << "Name: " << m_chNameEnemy << endl; cout << "Leben: "<< m_HitpointsEnemy << endl; } void CEnemy::Attack() { cout << "" << m_chNameEnemy << " richtet " << m_DamageEnemy << " Schaden an!" << endl; } int CEnemy::CastAttack() { cout << "" << m_chNameEnemy << " zaubert Geisterhand! " << endl; return 45; } class CGhost : public CEnemy { //Constructor public: CGhost(); }; CGhost::CGhost() { m_HitpointsEnemy = 500; m_DamageEnemy = 27; sprintf (m_chNameEnemy, "Zerof - the Ghost"); } //Prototypes void Battle(CEnemy *Enemy, CHero *Hero); //Mainfunction int main() { //Variables int Strength = 0, Intelligence = 0; CHero *Hero = NULL; CEnemy *Enemy = NULL; //GetValues cout << "Geben sie einen Staerkewert ein: "; cin >> Strength; cout << "Geben sie einen Intelligenzwert ein: "; cin >> Intelligence; Hero = new CHero (&Strength, &Intelligence); Enemy = new CGhost(); //StartBattle Battle(Enemy, Hero); return 0; } void Battle(CEnemy *Enemy, CHero *Hero) { //Variables char chAuswahl; cout << "Kampf beginnt!" << endl; Enemy->ShowStats(); do { cout << "(A)ngreifen, (Z)aubern, (B)enutzen"; if (Hero->m_Hitpoints <= (Hero->m_Strength*5/2)) cout << ", (L)imitattacke"; cout << "\n"; cout << "Eingabe: "; cin >> chAuswahl; switch (chAuswahl) { case ('A'): case ('a'): { cout << "Angriff wird ausgefuehert:" << endl; Hero->Attack(); cout << endl; Enemy->Attack(); Hero->m_Hitpoints -= Enemy->m_DamageEnemy; Enemy->m_HitpointsEnemy -= Hero->m_Damage; cout << endl; Hero->ShowStats(); cout << endl; Enemy->ShowStats(); } break; case ('Z'): case ('z'): { cout << "Zauber wird ausgefuehert:" << endl; int CastingDamage = Hero->CastAttack(); cout << endl; Enemy->m_HitpointsEnemy -= CastingDamage; CastingDamage = Enemy->CastAttack(); Hero->m_Hitpoints -= CastingDamage; cout << endl; Hero->ShowStats(); cout << endl; Enemy->ShowStats(); } break; case ('B'): case ('b'): { cout << "Beutel wird geoeffnet:" << endl; Hero->GetItem(); } break; } } while(Enemy->m_HitpointsEnemy > 0 && Hero->m_Hitpoints > 0); } |
Sicaine
unregistriert
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 Vector { private: float x, y, z; public: Vector() {} Vector(const Vector &v) : x(v.x), y(v.y), z(v.z) {} Vector(const float _x, const float _y, const float _z) : x(_x), y(_y), z(_z) {} Vector(const float f) : x(f), y(f), z(f) {} float getX() const {return x;} float getY() const {return y;} float getZ() const {return z;} inline Vector operator + (const Vector &a) {return Vector(this->x+a.x, this->y+a.y, this->z+a.z);} inline Vector operator - (const Vector &a) {return Vector(this->x-a.x, this->y+a.y, this->z+a.z);} inline Vector operator * (const float f) {return Vector(this->x*f, this->y*f, this->z*f);} }; |
Alter Hase
Werbeanzeige