Browse Source

Erster Commit

Lasse Wippich 10 months ago
commit
c3fef1b02c
5 changed files with 163 additions and 0 deletions
  1. 1 0
      README.md
  2. 55 0
      Spiel.cpp
  3. 107 0
      TürmeVonHanoi.cpp
  4. BIN
      output/Spiel.exe
  5. BIN
      output/TürmeVonHanoi.exe

+ 1 - 0
README.md

@@ -0,0 +1 @@
+# Projekt Lasse_Code_Bank 

+ 55 - 0
Spiel.cpp

@@ -0,0 +1,55 @@
+#include <iostream>
+#include <string>
+using namespace std;
+int spielzugpruefung(int staebe[3][4], int usereingaben[]){
+    int x = 0;
+    int temp[2];
+    return x;
+}
+void druck(int staebe[3][4]){
+    cout <<"A";
+    string labels[4] = {"      ||   " , "     <==>  ", "    <====> ", "   <======>"};
+    for(int x = 3; x >= 0; x--){
+        for(int y = 0; y < 3; y++){
+            cout << labels[staebe[y][x]];
+        }
+        cout << endl;
+    }
+}
+
+int main(){
+    bool run;
+    int usereingaben[2];
+    int staebe[3][4]; 
+    staebe[0][0] = 3;
+    staebe[0][1] = 2;
+    staebe[0][2] = 1;
+    staebe[0][3] = 0;
+    for(int x = 0; x < 2; x++){
+        for(int y = 0; y < 4; y++){
+            staebe[x][y] = 0;
+        }
+    }
+    druck(staebe);
+    do{
+        for(int x = 0; x < 2; x++){
+           run = true;
+            do{
+                cin >> usereingaben[x];
+                if(usereingaben[x] < 4 && usereingaben[x] > 0){
+                    run = false;
+                }
+                else{
+                    cout << "ERROR" <<endl;
+                }
+            }while(run); 
+        }
+        run = spielzugpruefung(staebe, usereingaben);
+        if(run){
+            cout << "Erfolgreich" << endl;
+        }
+        else{
+            cout << "ERROR.."<< endl;
+        }
+    }while(run == false);
+}

+ 107 - 0
TürmeVonHanoi.cpp

@@ -0,0 +1,107 @@
+#include <iostream>
+#include <cstdlib>
+#include <string>
+#include <windows.h>
+
+using namespace std;
+
+int spielzugpruefung(int staebe[3][4], int usereingaben[]){
+    int x;
+    int temp[2];
+    if (staebe[usereingaben[0]][0] == 0){
+        x = 0;
+    }
+    else if (staebe[usereingaben[1]][0] > 0){ //Der Stab der zweiten Usereingabe hat mindestens einen Ring
+        for (int y = 0; y < 2; y++){
+            x = 0;
+            while (staebe[usereingaben[y]][3 - x] < 1 && x < 3){ //Es wird zweimal von oben gezählt, wie viele ringfreie Stufen bei beiden Stäben der Usereingaben vorhanden sind
+                x++;
+            }
+            temp[y] = x;
+        }
+        if (staebe[usereingaben[0]][3 - temp[0]] < staebe[usereingaben[1]][3 - temp[1]]){ //Ist der Ring, der herauf gelegt wird, kleiner als der, der auf dem heraufzulegenden Stab ist 
+            x = 1;
+        }
+        else{
+            x = 0;
+        }
+    }
+    else{ //Ansonsten ist der Tausch direkt möglich
+        x = 1;
+    }
+    return x;
+}
+
+void druck(int staebe[3][4])
+{
+    string labels[4] = {"      ||   ", "     <==>  ", "    <====> ", "   <======>"};
+    system("cls");
+    for (int x = 3; x >= 0; x--){
+        for (int y = 0; y < 3; y++){
+            cout << labels[staebe[y][x]];
+        }
+        cout << endl;
+    }
+}
+int main(){
+    int spielzuege = 0;
+    bool run;
+    int tausch[3];
+    int usereingaben[2];
+    int staebe[3][4];
+
+    for(int x = 0 ; x < 4; x++){
+        staebe[0][x] = 3-x;
+    }
+    for (int x = 1; x < 3; x++){
+        for (int y = 0; y < 4; y++){
+            staebe[x][y] = 0;
+        }
+    }
+    do{
+        druck(staebe);
+        for (int x = 0; x < 2; x++){
+            run = true;
+            if (x){
+                cout << "Auf welchen Turm moechten Sie einen Stab legen?";
+            }
+            else{
+                cout << "Von welchem Turm moechten Sie einen Stab entfernen?";
+            }
+            do{
+                cin >> usereingaben[x];
+                usereingaben[x]--; //Anpassung zum Index
+                if (usereingaben[x] < 3 && usereingaben[x] >= 0){ //Überprüfung des Zahlenbereichs 
+                    run = false;
+                    cout << endl;
+                }
+                else{
+                    cout << "ERROR" << endl;
+                }
+            } while (run);
+        }
+        run = spielzugpruefung(staebe, usereingaben);
+        if (run){
+            spielzuege++;
+            for (int z = 0; z <= 1; z++){
+                tausch[2] = 1;
+                while (staebe[usereingaben[z]][3 - tausch[2]] < 1 && tausch[2] < 4){
+                    tausch[2]++;
+                }
+                tausch[z] = tausch[2];
+            }
+            tausch[2] = staebe[usereingaben[0]][3 - tausch[0]]; //Tauschen der Ringe 
+            staebe[usereingaben[0]][3 - tausch[0]] = 0;
+            staebe[usereingaben[1]][4 - tausch[1]] = tausch[2];
+            if (staebe[1][2] == 0 && staebe[2][2] == 0){    //Wenn der 2.te Index im Array der Stäbe 2 u. 3 leer ist, geht es weiter, ansonsten wäre das Rätsel gelöst
+                run = false;
+            }
+        }
+        else{
+            cout << "ERROR.." << endl;
+            Sleep(1400);
+        }
+    }while (run == false);
+    druck(staebe);
+    cout << "Sie loesten das Raetsel in " << spielzuege << " Spielzuegen!" << endl;
+}

BIN
output/Spiel.exe


BIN
output/TürmeVonHanoi.exe