Advertisement
Guest User

Untitled

a guest
May 25th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. // ||
  6.  
  7.  
  8. //=================Правила=====================
  9. //Игрок - может ходить, если в 3-х клетках после хода есть герой, он его убивает
  10. //Палач - может ходить, если в 3-х клетках после хода есть игрок, он его притягивает
  11. //                                                                      (не убивает)
  12. //Воин - может ходить, если в 3-х после хода есть игрок, он его убивает
  13. //
  14. //Цель игры - выжить 50 ходов или убить всех героев.
  15.  
  16.  
  17.  
  18. //================ОБОЗНАЧЕНИЯ==================
  19. // P - Player (Игрок)
  20. // E - Executioner (Палач)
  21. // W - Warrior (Воин)
  22.  
  23.  
  24. using namespace std;
  25.  
  26.  
  27. void field(int xp, int yp, int xe, int ye/* int xw, int yw*/)
  28. {
  29.     string field [22][21]; //
  30.     for (int y=21; y>0; --y)
  31.     {
  32.         for (int x=1; x<21; ++x)
  33.         {
  34.             if (y==21)
  35.             {
  36.                 if (x<10)
  37.                     cout << x << " ";
  38.                 else
  39.                     cout <<x;
  40.  
  41.             }
  42.             else
  43.             if ((xp==x)&&(yp==y))
  44.                 field[x][y]= "P ";
  45.             else
  46.             if ((xe==x)&&(ye==y))
  47.                 field[x][y]= "E ";
  48. //            else
  49. //            if ((xw==x)&&(yw==y))
  50. //                field[x][y]= "W ";
  51.             else
  52.                 field[x][y]= ". ";
  53.             cout << field[x][y];
  54.         }
  55.         cout << " y = " << y << endl;
  56.     }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. class P
  66. {
  67.     int x = 10;
  68.     int y = 2;
  69.     bool z = 0;
  70. public:
  71.     int moveP (char move/*, int z*/)
  72.     {
  73.  
  74.         if ((move == 'w')||(move == 's'))
  75.  
  76.         {
  77.             if (z==false)
  78.             {
  79.                 move == 'w' ? ++y : --y;
  80.                 y>20 ? --y : (y<1 ? ++y :y);
  81.                 z=true;
  82.                 cout << "y = " <<y<<endl;
  83.                 return y;
  84.             }
  85.             else
  86.             {
  87.                 z=false;
  88.                 cout << "x = " <<x<<endl;
  89.                 return x;
  90.             }
  91.         }
  92.         if ((move == 'd')||(move == 'a'))
  93.         {
  94.             if (z==false)
  95.             {
  96.                 z=true;
  97.                 cout << "y = " <<y<<endl;
  98.                 return y;
  99.             }
  100.             else
  101.             {
  102.                 move == 'd' ? ++x : --x;
  103.                 x>20 ? --x : (x<1 ? ++x:x);
  104.                 z=false;
  105.                 cout << "x = " <<x<<endl;
  106.                 return x;
  107.             }
  108.         }
  109.  
  110.     }
  111.  
  112. };
  113.  
  114.  
  115. class bot
  116. {
  117.    
  118. };
  119.  
  120.  
  121. class E : public bot //executioner
  122. {
  123.     int x=2;
  124.     int y=19;
  125.     int move=0;
  126. public:
  127.     int moveE(bool z)
  128.     {
  129.  
  130.         if (z==1)
  131.         {
  132.             move = 1 + rand ()%4;
  133.             if (move <3)
  134.             {
  135.                 move == 1 ? ++y : --y;
  136.                 y>20 ? y-=2 : (y<1 ? y+=2 :y);
  137.             }
  138.             return y;
  139.  
  140.         }
  141.         else
  142.         {
  143.             if (move > 2)
  144.             {
  145.                 move == 3 ? ++x : --x;
  146.                 x>20 ? x-=2 : (x<1 ? x+=2 :x);
  147.             }
  148.             return x;
  149.         }
  150.  
  151.     }
  152. };
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. int main()
  161. {
  162.     srand(time(NULL));
  163.     int xe=2;
  164.     int ye=19;
  165.     int xp = 10;
  166.     int yp = 2;
  167.  
  168.     P player;
  169.     E executioner;
  170.     char move;
  171.     cout << "x = " <<xp<<endl;
  172.     cout << "y = " <<yp<<endl;
  173.  
  174.  
  175.  
  176.     field (xp,yp,xe,ye);
  177.     for (;;)
  178.     {
  179.         cin >> move;
  180.         system("cls");
  181.         field ( player.moveP(move), player.moveP(move), executioner.moveE(0), executioner.moveE(1) );
  182.  
  183.     }
  184.  
  185.  
  186.     return 0;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement