Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <clocale>
- using namespace std;
- namespace Mlxa {
- #define eol '\n'
- #define endln cout << eol
- #define read cin
- #define print(a) cout << a << ' '
- template<class T> inline void
- println (T t) { cout << t << eol; }
- template <class A, class... B> inline void
- println (A a, B... b) { print(a); println(b...); }
- typedef long long ll;
- } using namespace Mlxa;
- const ll Size(5);
- char P[2][Size][Size];
- ll x[2], y[2];
- #define A 0
- #define B 1
- void readTable (ll p) {
- fstream fin;
- if (p) fin.open("B.txt");
- else fin.open("A.txt");
- for (ll i(0); i < Size; ++ i)
- for (ll j(0); j < Size; ++ j) {
- fin >> P[p][i][j];
- if (P[p][i][j] == 'S')
- x[1-p] = j, y[1-p] = i;
- }
- fin.close();
- }
- void printTable (ll p) {
- for (ll i(0); i < Size; ++ i, endln)
- for (ll j(0); j < Size; ++ j)
- print(P[p][i][j]);
- }
- void init () {
- println("Hello, world!");
- setlocale(0, "");
- readTable(A);
- readTable(B);
- /*
- println("Player A:");
- printTable(A);
- println("Player B:");
- printTable(B);
- */
- }
- void won (ll p) {
- println("Player", (p ? "B" : "A"), "won!!!");
- exit(0);
- }
- void turn (ll p) {
- endln;
- if (p == A) println(" Player A. ");
- if (p == B) println(" Player B. ");
- /* println("Coordinates:");
- println(y[p], x[p]); */
- println("Where you go?");
- ll dir; read >> dir;
- bool w = false;
- switch (dir) {
- case 2:
- ++ y[p];
- if (P[1-p][y[p]][x[p]] == '#' || y[p] < 0 || y[p] >= Size)
- -- y[p], println(" !!! WALL !!! "), w = true;
- break;
- case 6:
- ++ x[p];
- if (P[1-p][y[p]][x[p]] == '#' || x[p] < 0 || x[p] >= Size)
- -- x[p], println(" !!! WALL !!! "), w = true;
- break;
- case 4:
- -- x[p];
- if (P[1-p][y[p]][x[p]] == '#' || x[p] < 0 || x[p] >= Size)
- ++ x[p], println(" !!! WALL !!! "), w = true;
- break;
- case 8:
- -- y[p];
- if (P[1-p][y[p]][x[p]] == '#' || y[p] < 0 || y[p] >= Size)
- ++ y[p], println(" !!! WALL !!! "), w = true;
- break;
- default:
- println("???");
- }
- /*println("Coordinates:");
- println(y[p], x[p]);*/
- if (!w)
- println("Went to:", P[1-p][y[p]][x[p]]);
- if (P[1-p][y[p]][x[p]] == 'F') won(p);
- endln;
- char tmp[256];
- cin.getline(tmp, 256, '\n');
- cin.getline(tmp, 256, '\n');
- }
- int main() {
- init();
- while (1) {
- turn(A);
- turn(B);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement