Advertisement
Guest User

Praktikum3, Aufgabe2

a guest
Nov 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. //Variablen
  10. string posA = "", posB = "";
  11. unsigned int pos1 = 0, pos2 = 0, posZahlA = 0, posZahlB = 0;
  12.  
  13. //Spielfeld-
  14. const int rows = 9;
  15. const int cols = 9;
  16. vector< vector<string> > spielfeld(rows, vector<string> (cols));
  17.  
  18. //-linien
  19. for(unsigned int i=0; i < rows; ++i) {
  20. for(unsigned int j=0; j < cols; ++j) {
  21. spielfeld[i] [j] = " ___________ ";
  22. }
  23. }
  24.  
  25.  
  26. //Spielfiguren-
  27. const string wB = " ___wBauer__ ";
  28. const string sB = " ___sBauer__ ";
  29. const string wL = " __wLaeufer_ ";
  30. const string sL = " __sLaeufer_ ";
  31. const string wS = " _wSpringer_ ";
  32. const string sS = " _sSpringer_ ";
  33. const string wT = " ___wTurm___ ";
  34. const string sT = " ___sTurm___ ";
  35. const string wD = " ___wDame___ ";
  36. const string sD = " ___sDame___ ";
  37. const string wK = " __wKoenig__ ";
  38. const string sK = " __sKoenig__ ";
  39.  
  40. //-aufstellung (schwarz)
  41. spielfeld[0] [1] = sT;
  42. spielfeld[0] [2] = sS;
  43. spielfeld[0] [3] = sL;
  44. spielfeld[0] [4] = sD;
  45. spielfeld[0] [5] = sK;
  46. spielfeld[0] [6] = sL;
  47. spielfeld[0] [7] = sS;
  48. spielfeld[0] [8] = sT;
  49. spielfeld[1] [1] = sB;
  50. spielfeld[1] [2] = sB;
  51. spielfeld[1] [3] = sB;
  52. spielfeld[1] [4] = sB;
  53. spielfeld[1] [5] = sB;
  54. spielfeld[1] [6] = sB;
  55. spielfeld[1] [7] = sB;
  56. spielfeld[1] [8] = sB;
  57. //-aufstellung (weiß)
  58. spielfeld[7] [1] = wT;
  59. spielfeld[7] [2] = wS;
  60. spielfeld[7] [3] = wL;
  61. spielfeld[7] [4] = wD;
  62. spielfeld[7] [5] = wK;
  63. spielfeld[7] [6] = wL;
  64. spielfeld[7] [7] = wS;
  65. spielfeld[7] [8] = wT;
  66. spielfeld[6] [1] = wB;
  67. spielfeld[6] [2] = wB;
  68. spielfeld[6] [3] = wB;
  69. spielfeld[6] [4] = wB;
  70. spielfeld[6] [5] = wB;
  71. spielfeld[6] [6] = wB;
  72. spielfeld[6] [7] = wB;
  73. spielfeld[6] [8] = wB;
  74.  
  75. //Spielfeldbeschriftung & -formatierung
  76. spielfeld[0] [0] = "8";
  77. spielfeld[1] [0] = "7";
  78. spielfeld[2] [0] = "6";
  79. spielfeld[3] [0] = "5";
  80. spielfeld[4] [0] = "4";
  81. spielfeld[5] [0] = "3";
  82. spielfeld[6] [0] = "2";
  83. spielfeld[7] [0] = "1";
  84. spielfeld[8] [0] = "";
  85.  
  86. spielfeld[8] [0] = " ";
  87. spielfeld[8] [1] = " _____a_____ ";
  88. spielfeld[8] [2] = " _____b_____ ";
  89. spielfeld[8] [3] = " _____c_____ ";
  90. spielfeld[8] [4] = " _____d_____ ";
  91. spielfeld[8] [5] = " _____e_____ ";
  92. spielfeld[8] [6] = " _____f_____ ";
  93. spielfeld[8] [7] = " _____g_____ ";
  94. spielfeld[8] [8] = " _____h_____ ";
  95.  
  96.  
  97. //Benutzereingabe Spielzüge
  98. while (posA != "exit") {
  99.  
  100.  
  101.  
  102. //Figur geschlagen?
  103. //if()
  104.  
  105.  
  106. for(unsigned int i=0; i < rows; ++i) {
  107. if(i >= (rows-1)) {
  108. cout << endl;
  109. }
  110. for(unsigned int j=0; j < cols; ++j) {
  111. cout << spielfeld[i] [j];
  112. if(j>= (cols-1)) {
  113. cout << "\n" << endl;
  114. }
  115. }
  116. }
  117.  
  118.  
  119.  
  120. //Eingabe
  121. cout << "Bitte geben Sie einen Spielzug ein (z.B.: Von: a2 Zu: a3):" << endl;
  122. cout << "Start Buchstabe: ";
  123. cin >> posA;
  124. //Umwandlung Buchstabe in Zahl: posA
  125. if(posA == "a") {posZahlA = 1;}
  126. else if (posA == "b") {posZahlA = 2;}
  127. else if (posA == "c") {posZahlA = 3;}
  128. else if (posA == "d") {posZahlA = 4;}
  129. else if (posA == "e") {posZahlA = 5;}
  130. else if (posA == "f") {posZahlA = 6;}
  131. else if (posA == "g") {posZahlA = 7;}
  132. else if (posA == "h") {posZahlA = 8;}
  133. else if (posA == "exit") {cout << "Spielende" << endl;}
  134. else {cout << "ungültige Eingabe!" << endl;}
  135.  
  136. cout << "Start Zahl: ";
  137. cin >> pos1;
  138. //Umwandlung Buchstabe in Zahl: posB
  139. if(posB == "a") {posZahlB = 1;}
  140. else if (posB == "b") {posZahlB = 2;}
  141. else if (posB == "c") {posZahlB = 3;}
  142. else if (posB == "d") {posZahlB = 4;}
  143. else if (posB == "e") {posZahlB = 5;}
  144. else if (posB == "f") {posZahlB = 6;}
  145. else if (posB == "g") {posZahlB = 7;}
  146. else if (posB == "h") {posZahlB = 8;}
  147. else {cout << "ungültige Eingabe!" << endl;}
  148.  
  149. cout << "Ziel Buchstabe: ";
  150. cin >> posB;
  151. //Umwandlung VektorZahl in FeldZahl: pos1
  152. if(pos1 == 1) {pos1 = 7;}
  153. else if (pos1 == 2) {pos1 = 6;}
  154. else if (pos1 == 3) {pos1 = 5;}
  155. else if (pos1 == 4) {pos1 = 4;}
  156. else if (pos1 == 5) {pos1 = 3;}
  157. else if (pos1 == 6) {pos1 = 2;}
  158. else if (pos1 == 7) {pos1 = 1;}
  159. else if (pos1 == 8) {pos1 = 0;}
  160. else {cout << "ungültige Eingabe!" << endl; continue;}
  161.  
  162.  
  163. cout << "Ziel Zahl: ";
  164. cin >> pos2;
  165. //Umwandlung VektorZahl in FeldZahl: pos2
  166. if(pos2 == 1) {pos2 = 7;}
  167. else if (pos2 == 2) {pos2 = 6;}
  168. else if (pos2 == 3) {pos2 = 5;}
  169. else if (pos2 == 4) {pos2 = 4;}
  170. else if (pos2 == 5) {pos2 = 3;}
  171. else if (pos2 == 6) {pos2 = 2;}
  172. else if (pos2 == 7) {pos2 = 1;}
  173. else if (pos2 == 8) {pos2 = 0;}
  174. else {cout << "ungültige Eingabe!" << endl;}
  175.  
  176.  
  177. //Spielzüge Änderung
  178. spielfeld[pos2] [posZahlB] = spielfeld[pos1] [posZahlA];
  179. spielfeld[pos1] [posZahlA] = " ___________ ";
  180. }
  181.  
  182.  
  183. return 0;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement