Advertisement
Mlxa

GAME Labirint

Dec 23rd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <clocale>
  5. using namespace std;
  6.  
  7. namespace Mlxa {
  8.     #define eol '\n'
  9.     #define endln cout << eol
  10.     #define read cin
  11.     #define print(a) cout << a << ' '
  12.    
  13.     template<class T> inline void
  14.     println (T t) { cout << t << eol; }
  15.     template <class A, class... B> inline void
  16.     println (A a, B... b) { print(a); println(b...); }
  17.    
  18.     typedef long long ll;
  19. } using namespace Mlxa;
  20.  
  21. const ll Size(5);
  22.  
  23. char P[2][Size][Size];
  24. ll x[2], y[2];
  25. #define A 0
  26. #define B 1
  27.  
  28. void readTable (ll p) {
  29.     fstream fin;
  30.     if (p)  fin.open("B.txt");
  31.     else    fin.open("A.txt");
  32.    
  33.     for (ll i(0); i < Size; ++ i)
  34.     for (ll j(0); j < Size; ++ j) {
  35.         fin >> P[p][i][j];
  36.         if (P[p][i][j] == 'S')
  37.             x[1-p] = j, y[1-p] = i;
  38.     }
  39.     fin.close();
  40. }
  41. void printTable (ll p) {
  42.     for (ll i(0); i < Size; ++ i, endln)
  43.         for (ll j(0); j < Size; ++ j)
  44.             print(P[p][i][j]);
  45. }
  46. void init () {
  47.     println("Hello, world!");
  48.     setlocale(0, "");
  49.    
  50.     readTable(A);
  51.     readTable(B);
  52.     /*
  53.     println("Player A:");
  54.     printTable(A);
  55.    
  56.     println("Player B:");
  57.     printTable(B);
  58.     */
  59. }
  60.  
  61. void won (ll p) {
  62.     println("Player", (p ? "B" : "A"), "won!!!");
  63.     exit(0);
  64. }
  65.  
  66. void turn (ll p) {
  67.     endln;
  68.     if (p == A) println("   Player A.   ");
  69.     if (p == B) println("   Player B.   ");
  70.     /* println("Coordinates:");
  71.     println(y[p], x[p]); */
  72.     println("Where you go?");
  73.     ll dir; read >> dir;
  74.     bool w = false;
  75.     switch (dir) {
  76.         case 2:
  77.             ++ y[p];
  78.             if (P[1-p][y[p]][x[p]] == '#' || y[p] < 0 || y[p] >= Size)
  79.                 -- y[p], println("   !!! WALL !!!   "), w = true;
  80.         break;
  81.         case 6:
  82.             ++ x[p];
  83.             if (P[1-p][y[p]][x[p]] == '#' || x[p] < 0 || x[p] >= Size)
  84.             -- x[p], println("   !!! WALL !!!   "), w = true;
  85.         break;
  86.         case 4:
  87.             -- x[p];
  88.             if (P[1-p][y[p]][x[p]] == '#' || x[p] < 0 || x[p] >= Size)
  89.                 ++ x[p], println("   !!! WALL !!!   "), w = true;
  90.         break;
  91.         case 8:
  92.             -- y[p];
  93.             if (P[1-p][y[p]][x[p]] == '#' || y[p] < 0 || y[p] >= Size)
  94.                 ++ y[p], println("   !!! WALL !!!   "), w = true;
  95.         break;
  96.         default:
  97.             println("???");
  98.     }
  99.     /*println("Coordinates:");
  100.     println(y[p], x[p]);*/
  101.     if (!w)
  102.         println("Went to:", P[1-p][y[p]][x[p]]);
  103.     if (P[1-p][y[p]][x[p]] == 'F') won(p);
  104.     endln;
  105.     char tmp[256];
  106.     cin.getline(tmp, 256, '\n');
  107.     cin.getline(tmp, 256, '\n');
  108. }
  109.  
  110. int main() {
  111.     init();
  112.     while (1) {
  113.         turn(A);
  114.         turn(B);
  115.     }
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement