Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.71 KB | None | 0 0
  1. // SBG.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. #include <math.h>
  9. using namespace std;
  10. /*
  11. class grid{
  12. private:
  13.     char grid[9][9];
  14. public:
  15.     void set_grid(char c,int x,int y) {
  16.         grid[x][y]=c;
  17.     }
  18.     char get_grid(int x,int y) {
  19.         return grid[x][y];
  20.     }
  21. };
  22. */
  23.  
  24. /*
  25. class grid :public player {
  26. private:
  27.     char grid[9][9];
  28. public:
  29.     void set_grid(char c, int x, int y) {
  30.         grid[x][y] = c;
  31.     }
  32.     char get_grid(int x, int y) {
  33.         return grid[x][y];
  34.     }
  35. };
  36.  
  37. class ship {
  38. private:
  39.     struct coordinates {
  40.         int x;
  41.         int y;
  42.         bool b;
  43.     };
  44.     bool state;
  45.     vector<coordinates> KO;
  46.    
  47. public:
  48.     void create_ship() {
  49.         coordinates newcord;
  50.         KO.push_back(newcord);
  51.     }
  52.     void set_coordinates(int x, int y) {
  53.         KO[KO.size()-1].x = x;
  54.         KO[KO.size() - 1].y = y;
  55.         KO[KO.size() - 1].b = true;
  56.     }
  57. };*/
  58.  
  59.  
  60.  
  61. /*
  62. class FreeValues {
  63. private:
  64.        
  65. public:
  66.    
  67.     void get_free_values_x() {
  68.         FVx.erase(FVx.begin(), FVx.end());
  69.         if (x0 > -1) FVx.push_back(0);
  70.         if (x1 > -1) FVx.push_back(1);
  71.         if (x2 > -1) FVx.push_back(2);
  72.         if (x3 > -1) FVx.push_back(3);
  73.         if (x4 > -1) FVx.push_back(4);
  74.         if (x5 > -1) FVx.push_back(5);
  75.         if (x6 > -1) FVx.push_back(6);
  76.         if (x7 > -1) FVx.push_back(7);
  77.         if (x8 > -1) FVx.push_back(8);
  78.         if (x9 > -1) FVx.push_back(9);
  79.     }
  80.     void get_free_values_y() {
  81.         FVy.erase(FVx.begin(), FVx.end());
  82.         if (y0 > -1) FVy.push_back(0);
  83.         if (y1 > -1) FVy.push_back(1);
  84.         if (y2 > -1) FVy.push_back(2);
  85.         if (y3 > -1) FVy.push_back(3);
  86.         if (y4 > -1) FVy.push_back(4);
  87.         if (y5 > -1) FVy.push_back(5);
  88.         if (y6 > -1) FVy.push_back(6);
  89.         if (y7 > -1) FVy.push_back(7);
  90.         if (y8 > -1) FVy.push_back(8);
  91.         if (y9 > -1) FVy.push_back(9);
  92.     }
  93.  
  94. };*/
  95.  
  96. class ShipWindow { //:FreeValues
  97. private:
  98.     int x;
  99.     int y;
  100. public:
  101.     void set_x(int x) {
  102.         x = x;
  103.         /*
  104.         if (x == 0) minusy0();
  105.         if (x == 1) minusy1();
  106.         if (x == 2) minusy2();
  107.         if (x == 3) minusy3();
  108.         if (x == 4) minusy4();
  109.         if (x == 5) minusy5();
  110.         if (x == 6) minusy6();
  111.         if (x == 7) minusy7();
  112.         if (x == 8) minusy8();
  113.         if (x == 9) minusy9();
  114.         */
  115.     }
  116.     void set_y(int x) {
  117.         y = x;
  118.         /*
  119.         if (y == 0) minusx0();
  120.         if (y == 1) minusx1();
  121.         if (y == 2) minusx2();
  122.         if (y == 3) minusx3();
  123.         if (y == 4) minusx4();
  124.         if (y == 5) minusx5();
  125.         if (y == 6) minusx6();
  126.         if (y == 7) minusx7();
  127.         if (y == 8) minusx8();
  128.         if (y == 9) minusx9();
  129.         */
  130.     }
  131.     int get_x() {
  132.         return x;
  133.     }
  134.     int get_y() {
  135.         return y;
  136.     }
  137. };
  138.  
  139.  
  140. class Ship {
  141. private:
  142.  
  143. public:
  144.     vector<ShipWindow> ShipVec;
  145.     void new_win() {
  146.         ShipWindow shipwin;
  147.         ShipVec.push_back(shipwin);
  148.     }
  149. };
  150.  
  151.  
  152. class window {
  153. private:
  154.     char window;
  155. public:
  156.     void set_window(char w) {
  157.         //is ok?
  158.         window = w;
  159.     }
  160.     char get_window() {
  161.         return window;
  162.     }
  163. };
  164.  
  165. class grid {
  166. private:
  167.     window array[9][9];
  168. public:
  169.     void flush_grid() {
  170.         for (int x = 0; x < 10; x++) {
  171.             for (int y = 0; y < 10; y++) {
  172.                 array[x][y].set_window('~');
  173.             }
  174.         }
  175.     }
  176.  
  177.     void generate_grid() {
  178.         //5 4 4 3 3 3 2 2 2
  179.         if ((rand() % 1) == 0) {
  180.             rand() % 9;
  181.  
  182.         }
  183.  
  184.     }
  185.     bool generate_ship(int size) {
  186.         bool state = true;
  187.         while (true) {
  188.             if ((rand() % 1) == 0) {
  189.                 int r = (rand() % 1);
  190.                 int xr = (rand() % 9);
  191.                 int yr = (rand() % 9);
  192.                 while (true) {
  193.  
  194.                     if (r == 0) {
  195.                         for (int i = 0; i < size; i++) {
  196.                             if ((yr + i) < 10) {
  197.                                 if ((array[xr][yr + i].get_window()) != ('~')) state = false;
  198.                             }
  199.                             else {}
  200.  
  201.                         }
  202.                     }
  203.                     else {
  204.                         for (int i = 0; i < size; i++) {
  205.                             if ((yr + i) > -1) {
  206.                                 if ((array[xr][yr - i].get_window()) != ('~')) state = false;
  207.                             }
  208.                             else {};
  209.                         }
  210.                     }
  211.  
  212.             else {
  213.                 if (r == 0) {
  214.                     if (xr + i < 10) {
  215.                         for (int i = 0; i < size; i++) {
  216.                             if ([xr + i][yr].get_window()) != ('~')) state = false;
  217.                             else return false;
  218.                         }
  219.                     }
  220.                     else {
  221.                         if (xr - i > -1) {
  222.                             for (int i = 0; i < size; i++) {
  223.                                 if ((array[xr - i][yr].get_window()) != ('~')) state = false;
  224.                             }
  225.                         else {};
  226.                         }
  227.                     }
  228.                 }
  229.             }
  230.                 }
  231.  
  232.             }
  233.         }
  234.  
  235.  
  236.  
  237.         class Player {
  238.         private:
  239.             string name;
  240.             //int ships;
  241.             bool gamestatus;
  242.  
  243.         public:
  244.             vector<Ship> S;
  245.             void set_name(string x) {
  246.                 name = x;
  247.             }
  248.             string get_name() {
  249.                 return name;
  250.             }
  251.             void set_gamestatus(bool x) {
  252.                 gamestatus = x;
  253.             }
  254.             void newship() {
  255.                 Ship newship;
  256.                 S.push_back(newship);
  257.  
  258.             }
  259.             Player() {
  260.                 gamestatus = true;
  261.                 FreeValues FV;
  262.             }
  263.  
  264.         };
  265.  
  266.        
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.     //bool assign_window(int x, int y)
  275.  
  276. };
  277.  
  278.  
  279. int main()
  280. {
  281.     Player P;
  282.     Player AI;
  283.  
  284.  
  285.     system("pause");
  286.     return 0;
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement