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 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 |
// Neues Schach // #include<iostream> using namespace std; // Klassen class CFigur { public: // Membervariablen // Figur (0 = leer 1=BauerW 2=TurmW 3=Läufer 4=Springer 5=Dame 6=König // 10=BauerS 20=TurmS...) int m_Figur; public: // Memberfunktionen CFigur(); void FigurAuswahl(int x, int y); void Felddarstellen(); }; // Konstruktor CFigur // CFigur::CFigur() { m_Figur = 0; } // Felddarstellen // void CFigur::Felddarstellen() { if (m_Figur == 1) cout << "B|"; else if (m_Figur == 2) cout << "T|"; else if (m_Figur == 3) cout << "L|"; else if (m_Figur == 4) cout << "S|"; else if (m_Figur == 5) cout << "D|"; else if (m_Figur == 6) cout << "K|"; else if (m_Figur == 10) cout << "b|"; else if (m_Figur == 20) cout << "t|"; else if (m_Figur == 30) cout << "l|"; else if (m_Figur == 40) cout << "s|"; else if (m_Figur == 50) cout << "d|"; else if (m_Figur == 60) cout << "k|"; else cout << "_|"; } // Felddarstellen // Figur erkennen // void CFigur::FigurAuswahl(int x, int y) { cout << "Figur Auswahl\nIn Arbeit...\n"; } // Prototypen // int inline Startstellung(CFigur Feld,int x,int y); int main() { CFigur Feld[8][8]; char Auswahl; do { // Startstellung for (int y = 1; y < 9; y++) { for (int x = 1; x < 9; x++) { Feld[x][y].m_Figur = Startstellung(Feld[x][y], x, y); } } // Felddarstellen int Startreihe = 0; for (int y = 1; y < 9; y++) { if (Startreihe == 1) { cout << y << " |"; } for (int x = 1; x < 9; x++) { if (Startreihe == 0) { cout << " 1 2 3 4 5 6 7 8 " << endl; cout << " _ _ _ _ _ _ _ _ "; Startreihe++; y--; break; } Feld[x][y].Felddarstellen(); } cout << endl; } cout << "\n(N)ochmal?\n"; cin >> Auswahl; } while (Auswahl == 'n'); return 0; } int Startstellung(CFigur Feld, int x, int y) { // Bauern Reihe 2 und 7 if (y == 2 ) Feld.m_Figur = 1; else if (y == 7) Feld.m_Figur = 10; // Reihe 1 else if (y == 1 || y == 8) { // Faktor für Schwarz/Weiß int F = 1; if (y == 8) F = 10; if (x == 1 || 8) Feld.m_Figur = 2 * F; if (x == 2 || 7) Feld.m_Figur = 3 * F; if (x == 3 || 6) Feld.m_Figur = 4 * F; if (x == 4) Feld.m_Figur = 6 * F; if (x == 5) Feld.m_Figur = 5 * F; } else Feld.m_Figur = 0; } return Feld.m_Figur; } |
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 |
// Tik ta to (klein) // #include<iostream> using namespace std; // Strukturen struct S_Feld { bool Besetzt = false; bool Kreuz; }; // Variablen S_Feld Feld[3][3]; bool SpielerX = true; // Prototypen void Feldausgeben(); void Feldbesetzen(); int checkwin(); void Test(); void Feldreset(); // Hauptprogramm // int main() { // Variable char Spiel; do { Feldreset(); for (int i = 0; i < 20; i++) { Feldausgeben(); Feldbesetzen(); Test(); if (checkwin() == 1) { cout << "\nX gewinnt\n\n"; break; } if (checkwin() == 2) { cout << "\n0 gewinnt\n\n"; break; } } Feldausgeben(); //Neustart? cout << "(N)eu starten?" << endl; cin >> Spiel; cout << "\n\n\n" << endl; } while (Spiel == 'n' || Spiel == 'N'); return 0; } // Feld resetten void Feldreset() { // Stan*artwer*e (Kreuz = false; Besetzt = false) for (int y = 1; y < 4; y++) { for (int x = 1; x < 4; x++) { Feld[x][y].Kreuz = false; Feld[x][y].Besetzt = false; } } } // Feld darstellen void Feldausgeben() { cout << endl; for (int y = 1; y < 4; y++) { for (int x = 1; x < 4; x++) { if (Feld[x][y].Besetzt == true) { if (Feld[x][y].Kreuz == true) cout << " X"; else cout << " 0"; } else cout << " ."; } cout << endl; cout << endl; } } // Felder machen, Zug abwechseln void Feldbesetzen() { // Variablen int xPos = 0; int yPos = 0; // Feldeingabe cout << "x-Position eingeben (1-3)" << endl; cin >> xPos; cout << "y-Position eingeben (1-3)" << endl; cin >> yPos; Feld[xPos][yPos].Besetzt = true; // Je nach spieler X = true oder = false // Spieler wechseln if (SpielerX == true) { Feld[xPos][yPos].Kreuz = true; SpielerX = false; } else { Feld[xPos][yPos].Kreuz = false; SpielerX = true; } } // Überprüfen ob gewonnen wurde int checkwin() { // Variable=Rückgabewert int Win = 0; // Felder überprüfen for (int y = 1; y < 4; y ++) { for (int x = 1; x < 4; x++) { // Waagrecht // X if (Feld[x][y].Besetzt == true && Feld[x+1][y].Besetzt == true && Feld[x+2][y].Besetzt == true) { if (Feld[x][y].Kreuz == true && Feld[x+1][y].Kreuz == true && Feld[x+2][y].Kreuz == true) Win = 1; } // 0 if (Feld[x][y].Besetzt == true && Feld[x + 1][y].Besetzt == true && Feld[x + 2][y].Besetzt == true) { if (Feld[x][y].Kreuz == false && Feld[x + 1][y].Kreuz == false && Feld[x + 2][y].Kreuz == false) Win = 2; } // Senkrecht // X if (Feld[x][y].Besetzt == true && Feld[x][y + 1].Besetzt == true && Feld[x][y + 2].Besetzt == true) { if (Feld[x][y].Kreuz == true && Feld[x][y + 1].Kreuz == true && Feld[x][y+2].Kreuz == true) { Win = 1; cout << "Senkrecht X" << x; } } // 0 if (Feld[x][y].Besetzt == true && Feld[x][y + 1].Besetzt == true && Feld[x][y + 2].Besetzt == true) { if (Feld[x][y].Kreuz == false && Feld[x][y + 1].Kreuz == false && Feld[x][y+2].Kreuz == false) Win = 2; } // Diagonal // X if (Feld[x][y].Besetzt == true && Feld[x+1][y + 1].Besetzt == true && Feld[x+2][y + 2].Besetzt == true) { if (Feld[x][y].Kreuz == true && Feld[x + 1][y + 1].Kreuz == true && Feld[x + 2][y + 2].Kreuz == true) { Win = 1; cout << "Diagonal x 1"; } } // 0 if (Feld[x][y].Besetzt == true && Feld[x + 1][y + 1].Besetzt == true && Feld[x + 2][y + 2].Besetzt == true) { if (Feld[x][y].Kreuz == false && Feld[x + 1][y + 1].Kreuz == false && Feld[x + 2][y + 2].Kreuz == false) Win = 2; } // X if (Feld[x][y].Besetzt == true && Feld[x - 1][y - 1].Besetzt == true && Feld[x - 2][y - 2].Besetzt == true) { if (Feld[x][y].Kreuz == true && Feld[x - 1][y - 1].Kreuz == true && Feld[x - 2][y - 2].Kreuz == true) { Win = 1; cout << "Diagonal x 2"; } } // 0 if (Feld[x][y].Besetzt == true && Feld[x - 1][y - 1].Besetzt == true && Feld[x - 2][y - 2].Besetzt == true) { if (Feld[x][y].Kreuz == false && Feld[x - 1][y - 1].Kreuz == false && Feld[x - 2][y - 2].Kreuz == false) Win = 2; } } } return Win; } // Test void Test() { cout << endl; for (int y = 1; y < 4; y++) { for (int x = 1; x < 4; x++) { if (Feld[x][y].Kreuz == true) cout << " X"; else cout << " 0"; } cout << endl; cout << endl; } cout << endl; for (int y = 1; y < 4; y++) { for (int x = 1; x < 4; x++) { if (Feld[x][y].Besetzt == true) cout << " B"; else cout << " ."; } cout << endl; cout << endl; } } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Lindraupe« (13.01.2016, 20:50) aus folgendem Grund: Bessere Erklärung
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Lindraupe« (14.01.2016, 17:37)
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Lindraupe« (14.01.2016, 18:21)
Mach es beginnend ab 0, eins der Dinge die man eben lernen muss
Das wird in deinem prommierleben auch an anderer Stelle wieder begegnen.
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 |
// Tik ta to (klein) // #include<iostream> using namespace std; // Strukturen struct S_Feld { bool Besetzt = false; bool Kreuz; }; struct S_Spieler { char Name[16]; int Siege = 0; }; // Variablen S_Feld Feld[3][3]; bool SpielerX = true; // Prototypen void Feldausgeben(); void Feldbesetzen(); int checkwin(); void Test(); void Feldreset(); // Hauptprogramm // int main() { // Variablen char Neustart; S_Spieler Spieler1; S_Spieler Spieler2; // Spielernamen abfragen cout << "Namen (max 15 Zeichen)" << endl; cout << "Spieler 1: "; cin.get(Spieler1.Name, 15); cin.ignore(); cout << "Spieler 2: "; cin.get(Spieler2.Name, 15); int Win; do { Feldreset(); for (int i = 0; i < 20; i++) // Zwanzig Züge { cout << endl; if (SpielerX == true) cout << Spieler1.Name << " ist am Zug" << endl; else cout << Spieler2.Name << " ist am Zug" << endl; cout << endl; Feldausgeben(); Feldbesetzen(); Win = checkwin(); if (Win == 1) { cout << "\n" << Spieler1.Name << " gewinnt\n\n"; Spieler1.Siege++; break; } if (Win == 2) { cout << "\n" << Spieler2.Name << " gewinnt\n\n"; Spieler2.Siege++; break; } if (Win == 3) { cout << "\nUnentschieden\n\n"; break; } } Feldausgeben(); if (Spieler1.Siege < Spieler2.Siege) cout << Spieler2.Name << " fuehrt mit " << Spieler2.Siege - Spieler1.Siege << " Sieg(en) (" << Spieler1.Siege << "/" << Spieler2.Siege << ")" << endl; else if (Spieler2.Siege < Spieler1.Siege) cout << Spieler1.Name << " fuehrt mit " << Spieler1.Siege - Spieler2.Siege << " Sieg(en) (" << Spieler1.Siege << "/" << Spieler2.Siege << ")" << endl; else cout << "Es steht unentschieden\n"; //Neustart? cout << "(N)eues Spiel?" << endl; cin >> Neustart; cout << "\n\n\n" << endl; } while (Neustart == 'n' || Neustart == 'N'); return 0; } // Feld resetten void Feldreset() { // Stadarwere (Kreuz = false; Besetzt = false) for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { Feld[x][y].Kreuz = false; Feld[x][y].Besetzt = false; } } } // Feld darstellen void Feldausgeben() { cout << endl; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (Feld[x][y].Besetzt == true) { if (Feld[x][y].Kreuz == true) cout << " X"; else cout << " 0"; } else cout << " ."; } cout << endl; cout << endl; } } // Felder machen, Zug abwechseln void Feldbesetzen() { // Variablen int xPos = 0; int yPos = 0; // Feldeingabe bool FalscheEingabe = false; do // Solange 3<x<1 && 3<y<1 && Feld besetzt { if (FalscheEingabe == true) cout << "\nFalsche Eingabe\n" << endl; cout << "x-Position eingeben (1-3)" << endl; cin >> xPos; cout << "y-Position eingeben (1-3)" << endl; cin >> yPos; FalscheEingabe = true; } while (xPos < 1 || xPos > 3 || yPos < 1 || yPos > 3 || Feld[xPos - 1][yPos - 1].Besetzt == true); FalscheEingabe = false; // Werte korrigieren xPos--; yPos--; Feld[xPos][yPos].Besetzt = true; // Je nach spieler X = true oder = false // Spieler wechseln if (SpielerX == true) { Feld[xPos][yPos].Kreuz = true; SpielerX = false; } else { Feld[xPos][yPos].Kreuz = false; SpielerX = true; } } // Überprüfen ob gewonnen wurde int checkwin() { // Variable=Rückgabewert int Win = 0; // Felder überprüfen for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { // Waagrecht if (x == 0) { if (Feld[x][y].Besetzt == true && Feld[x + 1][y].Besetzt == true && Feld[x + 2][y].Besetzt == true) { // X if (Feld[x][y].Kreuz == true && Feld[x + 1][y].Kreuz == true && Feld[x + 2][y].Kreuz == true) Win = 1; // 0 if (Feld[x][y].Kreuz == false && Feld[x + 1][y].Kreuz == false && Feld[x + 2][y].Kreuz == false) Win = 2; } } // Senkrecht if (y == 0) { if (Feld[x][y].Besetzt == true && Feld[x][y + 1].Besetzt == true && Feld[x][y + 2].Besetzt == true) { // X if (Feld[x][y].Kreuz == true && Feld[x][y + 1].Kreuz == true && Feld[x][y + 2].Kreuz == true) Win = 1; // 0 if (Feld[x][y].Kreuz == false && Feld[x][y + 1].Kreuz == false && Feld[x][y + 2].Kreuz == false) Win = 2; } } // Diagonal if (x == 0 && y == 0) { if (Feld[x][y].Besetzt == true && Feld[x + 1][y + 1].Besetzt == true && Feld[x + 2][y + 2].Besetzt == true) { // X if (Feld[x][y].Kreuz == true && Feld[x + 1][y + 1].Kreuz == true && Feld[x + 2][y + 2].Kreuz == true) Win = 1; // 0 if (Feld[x][y].Kreuz == false && Feld[x + 1][y + 1].Kreuz == false && Feld[x + 2][y + 2].Kreuz == false) Win = 2; } } if (x == 0 && y == 2) { if (Feld[x][y].Besetzt == true && Feld[x + 1][y - 1].Besetzt == true && Feld[x + 2][y - 2].Besetzt == true) { // X if (Feld[x][y].Kreuz == true && Feld[x + 1][y - 1].Kreuz == true && Feld[x + 2][y - 2].Kreuz == true) Win = 1; // 0 if (Feld[x][y].Kreuz == false && Feld[x + 1][y - 1].Kreuz == false && Feld[x + 2][y - 2].Kreuz == false) Win = 2; } } } } if (Feld[0][0].Besetzt == true && Feld[0][1].Besetzt == true && Feld[0][2].Besetzt == true && Feld[1][0].Besetzt == true && Feld[1][1].Besetzt == true && Feld[1][2].Besetzt == true && Feld[2][0].Besetzt == true && Feld[2][1].Besetzt == true && Feld[2][2].Besetzt == true && Win == 0) Win = 3; return Win; } |
Werbeanzeige