Advertisement
Guest User

Golf

a guest
Oct 16th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <list>
  7. #include <bitset>
  8. #include <vector>
  9. using namespace std;
  10.  
  11. const unsigned char MAX_CUPE = 255;
  12.  
  13. static unsigned char m; // linii
  14. static unsigned char n; // coloane
  15. static unsigned char c; // cupe
  16. static unsigned char p[MAX_CUPE][2]; // pozitii cupe
  17. static unsigned long long g; // variabila ajutatoare
  18.  
  19.  
  20. // h - numarul de linii, w - numarul de coloane
  21. void f(char h, char w)
  22. {
  23. system("cls");
  24. c = 0;
  25. n =m = 12;
  26. int i, j,x=0,y=1;
  27. p[0][x] = 2; p[0][y] = 2;
  28. p[1][x] = 2; p[1][y] = 5;
  29. p[2][x] = 2; p[2][y] = 7;
  30. p[3][x] = 4; p[3][y] = 9;
  31. p[4][x] = 6; p[4][y] = 3;
  32. p[5][x] = 6; p[5][y] = 5;
  33. p[6][x] = 9; p[6][y] = 2;
  34. p[7][x] = 9; p[7][y] = 5;
  35. p[8][x] = 9; p[8][y] = 7;
  36. p[9][x] = 9; p[9][y] = 9;
  37. /*for (i = 1; i < n; i++) {
  38. for (j = 1; j < m; j++) {
  39. if (p[c][x] == i&&p[c][y] ==j) {
  40. cout << 'O';
  41. c++;
  42. }
  43. else
  44. cout << '.';
  45. }
  46. cout << endl;
  47. }*/
  48. for (i = 0; i < n; i++) {
  49. for (j = 0; j < m; j++) {
  50. if (j == 0 || i == 0)
  51. cout << '#';
  52. if (i > 0 && i < n - 1 && j >= 1 && j < m - 1) {
  53. if (p[c][x] == i&&p[c][y] == j) {
  54. cout << 'O';
  55. c++;
  56. }
  57. else
  58. cout << '.';
  59. }
  60. if (i == n - 1 || j == m - 1)
  61. cout << '#';
  62. }
  63. cout << endl;
  64. }
  65. }
  66.  
  67.  
  68. void main() {
  69. char h=0, w=0;
  70. f(h, w);
  71. getchar();
  72. }
  73. ////////////////////////////////////////////////////////////////////////////////////////////////
  74. #include <iostream>
  75. #include <fstream>
  76. #include <conio.h>
  77. #include <stdlib.h>
  78. #include <string.h>
  79. #include <list>
  80. #include <bitset>
  81. #include <vector>
  82. using namespace std;
  83.  
  84. const unsigned char MAX_CUPE = 255;
  85.  
  86. static unsigned char m; // linii
  87. static unsigned char n; // coloane
  88. static unsigned char c; // cupe
  89. static unsigned char p[MAX_CUPE][2]; // pozitii cupe
  90. static unsigned long long g; // variabila ajutatoare
  91.  
  92.  
  93. // h - numarul de linii, w - numarul de coloane
  94. void f(char h, char w)
  95. {
  96. int q, r;
  97. int x = 0, y = 1, i, j;
  98. unsigned int lovitura = 1, cupa1=1, cupa2=1;
  99. int pozx = 1, pozy = 1, pozx2 = 1, pozy2 = 1;
  100. unsigned char jucator = 1;
  101. char minge='*';
  102. c = 6;
  103. n = m = 15;
  104. p[1][x] = 2; p[1][y] = 2;
  105. p[2][x] = 2; p[2][y] = 5;
  106. p[3][x] = 2; p[3][y] = 7;
  107. p[4][x] = 4; p[4][y] = 9;
  108. p[5][x] = 6; p[5][y] = 3;
  109. p[6][x] = 6; p[6][y] = 5;
  110. p[7][x] = 9; p[7][y] = 2;
  111. p[8][x] = 9; p[8][y] = 5;
  112. p[9][x] = 9; p[9][y] = 7;
  113. p[10][x] = 9; p[10][y] = 9;
  114. p[11][x] = 10; p[11][y] = 8;
  115. p[12][x] = 12; p[12][y] = 13;
  116. p[13][x] = 14; p[13][y] = 2;
  117. p[14][x] = 14; p[14][y] = 14;
  118. while (jucator <= 2) {
  119. c = 1;
  120. for (i = 1; i < n; i++) {
  121. for (j = 1; j < m; j++) {
  122. if (i==1&&j==1) {
  123. cout << minge;
  124. }
  125. else if (p[c][x] == i&&p[c][y] == j) {
  126. cout << (int)c;
  127. c++;
  128. }
  129. else
  130. cout << '.';
  131. }
  132. cout << endl;
  133. }
  134. while (lovitura <= 200) {
  135. if (cupa1&&cupa2 <= c) {
  136. if (jucator == 1) {
  137. cout << "h=";
  138. cin >> q;
  139. cout << "w=";
  140. cin >> r;
  141. pozx += q; pozy += r;
  142. if (pozx < 1 || pozx>15 || pozy < 1 || pozy>15) {
  143. pozx -= q; pozy -= r;
  144. }
  145. cout << "A lovit jucatorul " << '1' << '.' << "Numar lovituri " << lovitura << '.';
  146. if (p[cupa1][x] == pozx&&p[cupa1][y] == pozy) {
  147. cout << "Cupa curenta:" << cupa1 << "<hit>" << '.';
  148. cupa1++;
  149. }
  150. else
  151. cout << "Cupa curenta:" << cupa1 << '.';
  152. cout << "Pozitie curenta:(" << pozx << ',' << pozy << ")." << endl;
  153. }
  154. else if (jucator == 2) {
  155. cout << "h=";
  156. cin >> q;
  157. cout << "w=";
  158. cin >> r;
  159. pozx2 += q; pozy2 += r;
  160. if (pozx2 < 1 || pozx2>15 || pozy2 < 1 || pozy2>15) {
  161. pozx2 -= q; pozy2 -= r;
  162. }
  163. cout << "A lovit jucatorul " << '2' << '.' << "Numar lovituri " << lovitura << '.';
  164. if (p[cupa2][x] == pozx2&&p[cupa2][y] == pozy2) {
  165. cout << "Cupa curenta:" << cupa2 << "<hit>" << '.';
  166. cupa2++;
  167. }
  168. else
  169. cout << "Cupa curenta:" << cupa2 << '.';
  170. cout << "Pozitie curenta:(" << pozx2 << ',' << pozy2 << ")." << endl;
  171. lovitura++;
  172. }
  173. jucator++;
  174. }
  175. }
  176. }
  177. }
  178. void main() {
  179. char h=0, w=0;
  180. f(h, w);
  181. getchar();
  182. }
  183. //////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement