Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.76 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include<iostream>
  3. #include<SFML/System.hpp>
  4. #include<SFML/Window.hpp>
  5. #include<SFML/Main.hpp>
  6. #include<SFML/Audio.hpp>
  7. #include<string>
  8. #include<list>
  9. #include <time.h>
  10. #include <windows.h>
  11.  
  12. using namespace std;
  13.  
  14. class Board {
  15. public:
  16.     sf::Vector2f position;
  17.     sf::Sprite Sprite;
  18.     sf::Sprite Sprite1;
  19.     sf::Texture texture;
  20.     sf::Texture texture1;
  21.     sf::Text text;
  22.     sf::Text text1;
  23.     sf::Font font;
  24.     string adres = "karty\\tlo.png";
  25.     string backGR = "karty\\background.png";
  26.     void loadBoardPic()
  27.     {
  28.         if (!(texture).loadFromFile(adres))
  29.         {
  30.             system("pause");
  31.         }
  32.     }
  33.     void loadBackGR()
  34.     {
  35.         if (!(texture1).loadFromFile(backGR))
  36.         {
  37.             system("pause");
  38.         }
  39.     }
  40.     void loadText(double resolutionCtrl)
  41.     {
  42.  
  43.         if (!font.loadFromFile("arial.ttf"))
  44.         {
  45.             exit(0);
  46.         }
  47.  
  48.         text.setFont(font);
  49.         text1.setFont(font);
  50.         text.setString("Losuj od nowa");
  51.         text1.setString("Pokaz");
  52.         text.setFillColor(sf::Color::Green);
  53.         text1.setFillColor(sf::Color::Green);
  54.         text.setCharacterSize(16);
  55.         text.setCharacterSize(17);
  56.         position.x = 15 * resolutionCtrl;
  57.         position.y = 700 * resolutionCtrl;
  58.         text.setPosition(position);
  59.         position.x = 15 * resolutionCtrl;
  60.         position.y = 100 * resolutionCtrl;
  61.         text1.setPosition(position);
  62.     }
  63.     void drawBack(sf::RenderWindow* window)
  64.     {
  65.         Sprite1.setTexture(texture1);
  66.         Sprite1.setPosition(position);
  67.         (*window).draw(Sprite1);
  68.     }
  69.     void drawBoard(sf::RenderWindow* window)
  70.     {
  71.         Sprite.setTexture(texture);
  72.         Sprite.setPosition(position);
  73.         (*window).draw(Sprite);
  74.     }
  75.     void drawText(sf::RenderWindow* window)
  76.     {
  77.  
  78.         (*window).draw(text);
  79.         (*window).draw(text1);
  80.  
  81.     }
  82. };
  83.  
  84. class Card {
  85. public:
  86.     int id_karty, value;
  87.     bool enableToMove;
  88.     sf::Vector2f docelowe_polozenie;
  89.     sf::Sprite Sprite;
  90.     sf::Texture texture;
  91.     sf::Texture textureClr;
  92.     unsigned int odkryte;
  93.     string adres;
  94.     string adres1 = "karty\\karta53.png";
  95.     void loadCardPic()
  96.     {
  97.         cout << "Adres ktory zostanie dodany: " << adres << endl;
  98.         if (!(texture).loadFromFile(adres))
  99.         {
  100.             system("pause");
  101.         }
  102.         if (!(textureClr).loadFromFile(adres1))
  103.             exit(0);
  104.     }
  105.     void wyswietlanie(sf::RenderWindow* window)
  106.     {
  107.         if (odkryte == 2)
  108.         {
  109.             Sprite.setTexture(texture);
  110.             Sprite.setPosition(docelowe_polozenie);
  111.             (*window).draw(Sprite);
  112.         }
  113.         if (odkryte == 1)
  114.         {
  115.             Sprite.setTexture(textureClr);
  116.             Sprite.setPosition(docelowe_polozenie);
  117.             (*window).draw(Sprite);
  118.         }
  119.     }
  120.  
  121. };
  122.  
  123. struct infoAboutList {
  124.     int index;
  125.     int x;
  126.     int y;
  127. };
  128. ///DEKLARACJE FUNKCJI///-------------------------------------
  129. void Tworzenie_Kart(sf::RenderWindow* window, Card *Karty, Board* Tlo, double resolutionCtrl);
  130. void podtrzymujaca(sf::RenderWindow* window);
  131. void decision();
  132. void waiting(sf::RenderWindow* window, sf::Music* music, Card *Karty, double resolutionCtrl, Board* Tlo);
  133. void showing(int *Table, list<Card> *lista, sf::RenderWindow* window, double resolutionCtrl, Board *Tlo, int ListNR);
  134. void drukowanieList(list<Card> *lista);
  135. ///-----------------------------------------------------------
  136. ///
  137. void waiting(sf::RenderWindow* window, sf::Music* music, Card *Karty, double resolutionCtrl, Board* Tlo)
  138. {
  139.     sf::Sprite Sprite;
  140.     sf::Texture texture;
  141.     sf::Event event;
  142.     if (!(texture).loadFromFile("karty\\karta.png"))
  143.         system("pause");
  144.     Sprite.setTexture(texture);
  145.     Sprite.setPosition(sf::Vector2f(10, 50));
  146.     (*window).draw(Sprite);
  147.     int i = 0;
  148.     (*window).display();
  149.     Sleep(2000);
  150.     while (i == 0)
  151.     {
  152.  
  153.  
  154.  
  155.         if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  156.         {
  157.             sf::Vector2i localPosition = sf::Mouse::getPosition(*window);
  158.             int x = localPosition.x;
  159.             int y = localPosition.y;
  160.             if ((x >= 239 * resolutionCtrl && x <= 433 * resolutionCtrl) && (y >= 409 * resolutionCtrl && y <= 436 * resolutionCtrl))
  161.             {
  162.                 i = 1;
  163.                 Tworzenie_Kart(&(*window), Karty, Tlo, resolutionCtrl);
  164.  
  165.             }
  166.             if ((x >= 239 * resolutionCtrl && x <= 380 * resolutionCtrl) && (y >= 649 * resolutionCtrl && y <= 676 * resolutionCtrl))
  167.             {
  168.                 i = 1;
  169.                 (*window).close();
  170.                 exit(0);
  171.  
  172.             }
  173.         }
  174.         while ((*window).pollEvent(event))
  175.         {
  176.             if (event.type == sf::Event::Closed)
  177.             {
  178.                 (*window).close();
  179.                 exit(0);
  180.             }
  181.         }
  182.     }
  183.  
  184. }
  185.  
  186.  
  187. ///FUNKCJA ZAPĘTLA PROGRAM I CHRONI PRZED ZATRZYMANIEM-----------------
  188. void podtrzymujaca(sf::RenderWindow* window)
  189. {
  190.     while ((*window).isOpen())
  191.     {
  192.         sf::Event event;
  193.         while ((*window).pollEvent(event))
  194.         {
  195.             if (event.type == sf::Event::Closed)
  196.                 (*window).close();
  197.         }
  198.     }
  199. }
  200. ///---------------------------------------------------------------------
  201. ///(createBoard)MIESZANIE KOLEJNOSCI LICZB W TABLICY W LOSOWY SPOSOB--------------------------------------------
  202. void Shuffling(int * Table)
  203. {
  204.     int i, i1, i2;
  205.     srand(time(NULL));
  206.     for (i = 1; i <= 3 * 52; i++)
  207.     {
  208.         i1 = rand() % 52; i2 = rand() % 52;
  209.         swap(Table[i1], Table[i2]);
  210.     }
  211. }
  212.  
  213. void add_to_list(list<Card> *list, int start, int end, int posX, int posY, int* TableID, Card *Karty)
  214. {
  215.     int i, value;
  216.     for (i = start; i <= end; i++)
  217.     {
  218.         value = TableID[i];
  219.         Karty[value].docelowe_polozenie.x = posX;
  220.         Karty[value].docelowe_polozenie.y = posY;
  221.         if (i == end)
  222.         {
  223.             Karty[value].odkryte = 2;
  224.             Karty[value].enableToMove = true;
  225.         }
  226.         else {
  227.             Karty[value].odkryte = 1;
  228.             Karty[value].enableToMove = false;
  229.         }
  230.         (*list).push_front(Karty[value]);
  231.         posY += 10;
  232.     }
  233.  
  234. }
  235. void CreateBoard(int *TableID, Card *Karty, list<Card> *lista, double resolutionCtrl)
  236. {
  237.  
  238.     int  i, value, cardPosX = 1400 * resolutionCtrl, cardPosY = 230 * resolutionCtrl;
  239.     for (i = 0; i < 13; i++)
  240.     {
  241.         lista[i].clear();
  242.     }
  243.     Shuffling(TableID);
  244.  
  245.     cardPosX = 1400 * resolutionCtrl, cardPosY = 230 * resolutionCtrl;
  246.     add_to_list(&lista[0], 0, 6, cardPosX, cardPosY, TableID, Karty);
  247.     cardPosX -= 205 * resolutionCtrl;
  248.     cardPosY = 230 * resolutionCtrl;
  249.     add_to_list(&lista[1], 7, 12, cardPosX, cardPosY, TableID, Karty);
  250.     cardPosX -= 205 * resolutionCtrl;
  251.     cardPosY = 230 * resolutionCtrl;
  252.     add_to_list(&lista[2], 13, 17, cardPosX, cardPosY, TableID, Karty);
  253.     cardPosX -= 205 * resolutionCtrl;
  254.     cardPosY = 230 * resolutionCtrl;
  255.     add_to_list(&lista[3], 18, 21, cardPosX, cardPosY, TableID, Karty);
  256.     cardPosX -= 205 * resolutionCtrl;
  257.     cardPosY = 230 * resolutionCtrl;
  258.     add_to_list(&lista[4], 22, 24, cardPosX, cardPosY, TableID, Karty);
  259.     cardPosX -= 205 * resolutionCtrl;
  260.     cardPosY = 230 * resolutionCtrl;
  261.     add_to_list(&lista[5], 25, 26, cardPosX, cardPosY, TableID, Karty);
  262.     cardPosX -= 205 * resolutionCtrl;
  263.     cardPosY = 230 * resolutionCtrl;
  264.     add_to_list(&lista[6], 27, 27, cardPosX, cardPosY, TableID, Karty);
  265.     cardPosX -= 205 * resolutionCtrl;
  266.     cardPosY = 230 * resolutionCtrl;
  267.     for (i = 28; i < 52; i++)
  268.     {
  269.         value = TableID[i];
  270.         Karty[value].docelowe_polozenie.x = 0;
  271.         Karty[value].docelowe_polozenie.y = 0;
  272.         Karty[value].odkryte = 0;
  273.         Karty[value].enableToMove = false;
  274.         lista[12].push_back(Karty[value]);
  275.     }
  276. }
  277. void Tworzenie_Kart(sf::RenderWindow* window, Card *Karty, Board* Tlo, double resolutionCtrl)
  278. {
  279.     int i, k = 1, j = 48, color = 1, posX;
  280.     string sciezka = "karty\\karta";
  281.     string numer;
  282.     posX = 640;
  283.     Tlo[0].loadText(resolutionCtrl);
  284.     Tlo[0].position.x = 0;
  285.     Tlo[0].position.y = 0;
  286.     Tlo[0].loadBackGR();
  287.     for (i = 1; i <= 4; i++)
  288.     {
  289.         Tlo[i].position.x = posX*resolutionCtrl;
  290.         Tlo[i].position.y = 30 * resolutionCtrl;
  291.         Tlo[i].loadBoardPic();
  292.         posX += 180;
  293.     }
  294.     posX = 1400 * resolutionCtrl;
  295.     for (i = 5; i < 12; i++)
  296.     {
  297.         Tlo[i].position.x = posX;
  298.         Tlo[i].position.y = 230 * resolutionCtrl;
  299.         Tlo[i].loadBoardPic();
  300.         posX -= 205 * resolutionCtrl;
  301.     }
  302.     Tlo[12].adres = "karty\\karta54.png";
  303.     Tlo[12].position.x = 30 * resolutionCtrl;
  304.     Tlo[12].position.y = 50 * resolutionCtrl;
  305.     Tlo[13].adres = "karty\\odNowa.png";
  306.     Tlo[13].position.x = 1480 * resolutionCtrl;
  307.     Tlo[13].position.y = 20 * resolutionCtrl;
  308.     for (i = 12; i < 14; i++)
  309.     {
  310.         Tlo[i].loadBoardPic();
  311.     }
  312.     for (i = 0; i < 52; i++)
  313.     {
  314.         Karty[i].id_karty = k;
  315.         Karty[i].value = color;
  316.         if (k == 13)
  317.         {
  318.             k = 0;
  319.             color++;
  320.         }
  321.         k++;
  322.         numer = sciezka + (char)(i + j) + ".png";
  323.         if (i % 2 == 0) {
  324.             Karty[i].odkryte = 0;
  325.         }
  326.         else
  327.         {
  328.             Karty[i].odkryte = 2;
  329.         }
  330.         Karty[i].adres = numer;
  331.         cout << Karty[i].adres << endl;
  332.         Karty[i].loadCardPic();
  333.  
  334.         Karty[i].docelowe_polozenie.x = 0;
  335.         Karty[i].docelowe_polozenie.y = 0;
  336.         Karty[i].enableToMove = false;
  337.         if (i >= 49)
  338.         {
  339.             sciezka = "karty\\karta5";
  340.             j = -2;
  341.         }
  342.         else {
  343.             if (i >= 39)
  344.             {
  345.                 sciezka = "karty\\karta4";
  346.                 j = 8;
  347.             }
  348.             else
  349.             {
  350.                 if (i >= 29)
  351.                 {
  352.                     sciezka = "karty\\karta3";
  353.                     j = 18;
  354.                 }
  355.                 else
  356.                 {
  357.                     if (i >= 19)
  358.                     {
  359.                         sciezka = "karty\\karta2";
  360.                         j = 28;
  361.                     }
  362.                     else {
  363.                         if (i >= 9)
  364.                         {
  365.                             sciezka = "karty\\karta1";
  366.                             j = 38;
  367.                         }
  368.                     }
  369.                 }
  370.             }
  371.         }
  372.     }
  373. }
  374.  
  375. void showing(int *Table, list<Card> *lista, sf::RenderWindow* window, double resolutionCtrl, Board *Tlo, int ListNR)
  376. {
  377.  
  378.     int i, value;
  379.     (*window).clear(sf::Color::Red);
  380.     Tlo[0].drawBack(&(*window));
  381.     for (i = 1; i < 14; i++)
  382.     {
  383.         Tlo[i].drawBoard(&(*window));
  384.     }
  385.     list <Card>::reverse_iterator it;
  386.     if (ListNR == 0)
  387.     {
  388.         for (i = 11; i >= 0; i--)
  389.         {
  390.             for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
  391.             {
  392.                 it->wyswietlanie(&(*window));
  393.             }
  394.         }
  395.     }
  396.     else {
  397.         if (ListNR == 11)
  398.         {
  399.             for (i = 0; i <= 11; i++)
  400.             {
  401.                 for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
  402.                 {
  403.                     it->wyswietlanie(&(*window));
  404.                 }
  405.             }
  406.         }
  407.         else {
  408.             for (i = 11; i > ListNR; i--)
  409.             {
  410.                 for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
  411.                 {
  412.                     it->wyswietlanie(&(*window));
  413.                 }
  414.             }
  415.             for (i = ListNR - 1; i >= 0; i--)
  416.             {
  417.                 for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
  418.                 {
  419.                     it->wyswietlanie(&(*window));
  420.                 }
  421.             }
  422.             for (it = lista[ListNR].rbegin(); it != lista[ListNR].rend(); it++)
  423.             {
  424.                 it->wyswietlanie(&(*window));
  425.             }
  426.         }
  427.  
  428.  
  429.     }
  430.  
  431. }
  432.  
  433. void change_list(int add, int del, list<Card> *lista, int wspClickCardX, int wspClickCardY, list <Card>::iterator iter, double resolutionCtrl)
  434. {
  435.     int x, y, counter = 1;
  436.     list <Card>::iterator it;
  437.     it = lista[add].begin();
  438.     list <Card>::iterator it2;
  439.     Card Karta;
  440.     it2 = lista[del].begin();
  441.     do
  442.     {
  443.         if ((it2)->adres == iter->adres)
  444.         {
  445.             it2++;
  446.             break;
  447.         }
  448.         counter++;
  449.     } while ((it2++) != lista[del].end());
  450.  
  451.     for (int k = 0; k < counter; k++)
  452.     {
  453.         it2--;
  454.         it = lista[add].begin();
  455.         if (lista[add].empty())
  456.         {
  457.             x = wspClickCardX;
  458.             y = wspClickCardY;
  459.         }
  460.         else
  461.         {
  462.             if (add > 6) {
  463.                 x = it->docelowe_polozenie.x;
  464.                 y = (it->docelowe_polozenie.y);
  465.             }
  466.             else {
  467.                 x = it->docelowe_polozenie.x;
  468.                 y = (it->docelowe_polozenie.y) + 16;
  469.             }
  470.         }
  471.         Karta.id_karty = it2->id_karty;
  472.         Karta.value = it2->value;
  473.         Karta.enableToMove = it2->enableToMove;
  474.         Karta.docelowe_polozenie.x = x;
  475.         Karta.docelowe_polozenie.y = y;
  476.         Karta.Sprite = it2->Sprite;
  477.         Karta.texture = it2->texture;
  478.         Karta.textureClr = it2->textureClr;
  479.         Karta.odkryte = it2->odkryte;
  480.         Karta.adres = it2->adres;
  481.         Karta.adres1 = it2->adres1;
  482.         lista[add].push_front(Karta);
  483.         lista[del].erase(it2);
  484.         it2 = lista[del].begin();
  485.         for (int j = 0; j != (counter - (k + 1)); j++)
  486.         {
  487.             it2++;
  488.         }
  489.     }
  490.     if (lista[del].begin() != lista[del].end())
  491.     {
  492.         it = lista[del].begin();
  493.         it->enableToMove = true;
  494.         it->odkryte = 2;
  495.     }
  496.     drukowanieList(lista);
  497. }
  498.  
  499. void drukowanieList(list<Card> *lista)
  500. {
  501.     int i;
  502.     list <Card>::iterator it;
  503.     for (i = 0; i < 7; i++)
  504.     {
  505.         for (it = lista[i].begin(); it != lista[i].end(); ++it)
  506.         {
  507.             cout << it->id_karty << " , ";
  508.         }
  509.         cout << endl;
  510.     }
  511. }
  512.  
  513. struct infoAboutList checkEmptyList(double resolutionCtrl, vector<int> emptyList, list <Card>::iterator picked)
  514. {
  515.     cout << "Weszlo w check empty list" << endl;
  516.     int capacity = emptyList.size(), index;
  517.     struct infoAboutList foundList;
  518.     foundList.index = -1;
  519.     foundList.x = 0;
  520.     foundList.y = 0;
  521.     for (int i = 0; i < capacity; i++)
  522.     {
  523.         index = emptyList[i];
  524.         switch (index)
  525.         {
  526.         case 0: {
  527.             if (picked->docelowe_polozenie.x >= (1400 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (1400 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  528.             {
  529.                 foundList.index = 0;
  530.                 foundList.x = 1400 * resolutionCtrl;
  531.                 foundList.y = 230 * resolutionCtrl;
  532.             }
  533.         }
  534.                 break;
  535.         case 1: {
  536.             if (picked->docelowe_polozenie.x >= (1195 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (1195 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  537.             {
  538.                 foundList.index = 1;
  539.                 foundList.x = 1195 * resolutionCtrl;
  540.                 foundList.y = 230 * resolutionCtrl;
  541.             }
  542.         }
  543.                 break;
  544.         case 2: {
  545.             if (picked->docelowe_polozenie.x >= (990 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (990 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  546.             {
  547.                 foundList.index = 2;
  548.                 foundList.x = 990 * resolutionCtrl;
  549.                 foundList.y = 230 * resolutionCtrl;
  550.             }
  551.         }
  552.                 break;
  553.         case 3: {
  554.             if (picked->docelowe_polozenie.x >= (785 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (785 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  555.             {
  556.                 foundList.index = 3;
  557.                 foundList.x = 785 * resolutionCtrl;
  558.                 foundList.y = 230 * resolutionCtrl;
  559.             }
  560.         }
  561.                 break;
  562.         case 4: {
  563.             if (picked->docelowe_polozenie.x >= (580 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (580 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  564.             {
  565.                 foundList.index = 4;
  566.                 foundList.x = 580 * resolutionCtrl;
  567.                 foundList.y = 230 * resolutionCtrl;
  568.             }
  569.         }
  570.                 break;
  571.         case 5: {
  572.             if (picked->docelowe_polozenie.x >= (375 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (375 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  573.             {
  574.                 foundList.index = 5;
  575.                 foundList.x = 375 * resolutionCtrl;
  576.                 foundList.y = 230 * resolutionCtrl;
  577.             }
  578.         }
  579.                 break;
  580.         case 6: {
  581.             if (picked->docelowe_polozenie.x >= (170 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (170 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (230 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (230 * resolutionCtrl + 25))
  582.             {
  583.                 foundList.index = 6;
  584.                 foundList.x = 170 * resolutionCtrl;
  585.                 foundList.y = 230 * resolutionCtrl;
  586.             }
  587.         }
  588.                 break;
  589.         case 7: {
  590.             if (picked->docelowe_polozenie.x >= (1180 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (1180 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (30 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (30 * resolutionCtrl + 25))
  591.             {
  592.                 foundList.index = 7;
  593.                 foundList.x = 1180 * resolutionCtrl;
  594.                 foundList.y = 30 * resolutionCtrl;
  595.             }
  596.         }
  597.                 break;
  598.         case 8: {
  599.             if (picked->docelowe_polozenie.x >= (1000 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (1000 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (30 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (30 * resolutionCtrl + 25))
  600.             {
  601.                 foundList.index = 8;
  602.                 foundList.x = 1000 * resolutionCtrl;
  603.                 foundList.y = 30 * resolutionCtrl;
  604.             }
  605.         }
  606.                 break;
  607.         case 9: {
  608.             if (picked->docelowe_polozenie.x >= (820 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (820 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (30 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (30 * resolutionCtrl + 25))
  609.             {
  610.                 foundList.index = 9;
  611.                 foundList.x = 820 * resolutionCtrl;
  612.                 foundList.y = 30 * resolutionCtrl;
  613.             }
  614.         }
  615.                 break;
  616.         case 10: {
  617.             if (picked->docelowe_polozenie.x >= (640 * resolutionCtrl - 25) && picked->docelowe_polozenie.x <= (640 * resolutionCtrl + 25) && picked->docelowe_polozenie.y >= (30 * resolutionCtrl - 25) && picked->docelowe_polozenie.y <= (30 * resolutionCtrl + 25))
  618.             {
  619.                 foundList.index = 10;
  620.                 foundList.x = 640 * resolutionCtrl;
  621.                 foundList.y = 30 * resolutionCtrl;
  622.             }
  623.         }
  624.                  break;
  625.         }
  626.     }
  627.     cout << "Wyszło z empty list" << endl;
  628.     return foundList;
  629. }
  630. void transferingToShow(list<Card> *lista, double resolutionCtrl)
  631. {
  632.     Card Karta;
  633.     list <Card>::iterator it;
  634.     if (lista[12].empty())
  635.     {
  636.         lista[12].swap(lista[11]);
  637.  
  638.     }
  639.     else {
  640.         it = lista[12].end();
  641.         it--;
  642.         Karta.id_karty = it->id_karty;
  643.         Karta.value = it->value;
  644.         Karta.enableToMove = true;
  645.         Karta.docelowe_polozenie.x = 170 * resolutionCtrl;
  646.         Karta.docelowe_polozenie.y = 50 * resolutionCtrl;
  647.         Karta.Sprite = it->Sprite;
  648.         Karta.texture = it->texture;
  649.         Karta.textureClr = it->textureClr;
  650.         Karta.odkryte = 2;
  651.         Karta.adres = it->adres;
  652.         Karta.adres1 = it->adres1;
  653.         lista[11].push_front(Karta);
  654.         lista[12].pop_back();
  655.     }
  656. }
  657. void check(int *Table, sf::RenderWindow* window, list<Card> *lista, Card *Karty, double resolutionCtrl, Board *Tlo, vector<int> emptyList)
  658. {
  659.     sf::Vector2i localPosition = sf::Mouse::getPosition(*window);
  660.     int x = localPosition.x;
  661.     int y = localPosition.y;
  662.     if ((((x >= 28 * resolutionCtrl) && (x <= 118 * resolutionCtrl)) && ((y >= 48 * resolutionCtrl) && (y <= 172 * resolutionCtrl))) && (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
  663.     {
  664.         transferingToShow(lista, resolutionCtrl);
  665.         showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
  666.         (*window).display();
  667.         Sleep(350);
  668.         return;
  669.     }
  670.     list <Card>::iterator it;
  671.     list <Card>::iterator it2;
  672.     list <Card>::iterator it3;
  673.     list <Card>::iterator it4;
  674.     vector<sf::Vector2f> coOrdinates;
  675.     int ordX, var = 0, ordY, i, m, saveListI, counter = 0;
  676.     struct infoAboutList result;
  677.     result.index = -1;
  678.  
  679.     for (i = 0; i < 12; i++)
  680.     {
  681.         for (it = lista[i].begin(); it != lista[i].end(); ++it)
  682.         {
  683.             if ((((x >= it->docelowe_polozenie.x) && (x <= (it->docelowe_polozenie.x + 86))) && ((y >= it->docelowe_polozenie.y) && (y <= (it->docelowe_polozenie.y + 120)))) && it->enableToMove)
  684.             {
  685.                 cout << "ID trzymanej karty!!: " << it->id_karty << endl;
  686.                 it3 = it;
  687.                 it3++;
  688.                 it4 = it;
  689.                 do {
  690.                     if (it3 != lista[i].begin())
  691.                     {
  692.                         it3--;
  693.                     }
  694.                     coOrdinates.push_back(it3->docelowe_polozenie);
  695.                     counter++;
  696.                 } while (it3 != lista[i].begin());
  697.                 ordX = it->docelowe_polozenie.x;
  698.                 ordY = it->docelowe_polozenie.y;
  699.  
  700.                 while (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  701.                 {
  702.                     localPosition = sf::Mouse::getPosition(*window);
  703.                     for (m = 0; m < counter; m++)
  704.                     {
  705.                         (it4->docelowe_polozenie.x) = coOrdinates[m].x + (localPosition.x - x);
  706.                         it4->docelowe_polozenie.y = coOrdinates[m].y + (localPosition.y - y);
  707.                         if (it4 != lista[i].begin())
  708.                         {
  709.                             it4--;
  710.                         }
  711.                     }
  712.                     it4 = it;
  713.                     showing(Table, lista, &(*window), resolutionCtrl, Tlo, i);
  714.                     (*window).display();
  715.                 }
  716.                 if ((it->docelowe_polozenie.x != ordX) || (it->docelowe_polozenie.y != ordY))
  717.                 {
  718.                     for (int k = 0; k<7; k++)
  719.                     {
  720.                         if (lista[k].empty() && it->id_karty == 13)
  721.                         {
  722.                             cout << "Przeszlo tu" << endl;
  723.                             emptyList.push_back(k);
  724.                         }
  725.                         else {
  726.                             if(lista[k].empty())
  727.                         {
  728.                             break;
  729.                         }
  730.                             cout << "Przeszlo ten warunek a nie powinno" << endl;
  731.                             it2 = lista[k].begin();
  732.                             if ((it->docelowe_polozenie.x < it2->docelowe_polozenie.x + 30 && it->docelowe_polozenie.x >= it2->docelowe_polozenie.x - 30 && it->docelowe_polozenie.y <= it2->docelowe_polozenie.y + 55 && it->docelowe_polozenie.y >= it2->docelowe_polozenie.y - 55 && it2->enableToMove && ((it->value % 2) != (it2->value % 2)) && it->id_karty == it2->id_karty - 1))
  733.                             {
  734.                                 cout << "Weszło dla jednej " << it->id_karty << " i drugiej " << it2->id_karty << endl;
  735.                                 if (i != k)
  736.                                 {
  737.                                     x = it2->docelowe_polozenie.x;
  738.                                     y = it2->docelowe_polozenie.y;
  739.                                     var = 1;
  740.                                     saveListI = k;
  741.                                     result.index = 0;
  742.                                     break;
  743.                                 }
  744.                             }
  745.                         }
  746.                        
  747.  
  748.                     }
  749.                     if (var != 1) {
  750.  
  751.                         for (int k = 7; k < 11; k++)
  752.                         {
  753.                             for (it2 = lista[k].begin(); it2 != lista[k].end(); ++it2)
  754.                             {
  755.                                 if ((it->docelowe_polozenie.x < it2->docelowe_polozenie.x + 30 && it->docelowe_polozenie.x >= it2->docelowe_polozenie.x - 30 && it->docelowe_polozenie.y <= it2->docelowe_polozenie.y + 55 && it->docelowe_polozenie.y >= it2->docelowe_polozenie.y - 55 && it2->enableToMove && (it->value == it2->value) && it->id_karty == it2->id_karty + 1))
  756.                                 {
  757.                                     if (i != k)
  758.                                     {
  759.                                         x = it2->docelowe_polozenie.x;
  760.                                         y = it2->docelowe_polozenie.y;
  761.                                         var = 1;
  762.                                         saveListI = k;
  763.                                     }
  764.                                 }
  765.                             }
  766.                             if (lista[k].empty() && it->id_karty == 1)
  767.                             {
  768.                                 emptyList.push_back(k);
  769.                             }
  770.  
  771.                         }
  772.                     }
  773.                     if (var != 1)
  774.                     {
  775.                         if (!(emptyList.empty()))
  776.                         {
  777.                             result = checkEmptyList(resolutionCtrl, emptyList, it);
  778.                             if (result.index == -1)
  779.                             {
  780.                                 for (m = 0; m < counter; m++)
  781.                                 {
  782.  
  783.                                     it4->docelowe_polozenie.x = coOrdinates[m].x;
  784.                                     it4->docelowe_polozenie.y = coOrdinates[m].y;
  785.                                     if (it4 != lista[i].begin())
  786.                                     {
  787.                                         it4--;
  788.                                     }
  789.                                 }
  790.                                 it4 = it;
  791.                                 showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
  792.                                 (*window).display();
  793.                             }
  794.                             else {
  795.                                 change_list(result.index, i, lista, result.x, result.y, it, resolutionCtrl);
  796.                                 showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
  797.                                 (*window).display();
  798.                             }
  799.  
  800.                         }
  801.                         else
  802.                         {
  803.                             for (m = 0; m < counter; m++)
  804.                             {
  805.                                 it4->docelowe_polozenie.x = coOrdinates[m].x;
  806.                                 it4->docelowe_polozenie.y = coOrdinates[m].y;
  807.                                 if (it4 != lista[i].begin())
  808.                                 {
  809.                                     it4--;
  810.                                 }
  811.                             }
  812.                             it4 = it;
  813.                             showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
  814.                             (*window).display();
  815.                         }
  816.                     }
  817.                     else
  818.                     {
  819.                         change_list(saveListI, i, lista, ordX, ordY, it, resolutionCtrl);
  820.                         showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
  821.                         (*window).display();
  822.                     }
  823.                 }
  824.                 break;
  825.             }
  826.  
  827.         }
  828.     }
  829.     if ((((x >= 1478 * resolutionCtrl) && (x <= 1616 * resolutionCtrl)) && ((y >= 20 * resolutionCtrl) && (y <= 67 * resolutionCtrl))) && (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
  830.     {
  831.         CreateBoard(Table, Karty, lista, resolutionCtrl);
  832.         showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
  833.         (*window).display();
  834.         Sleep(700);
  835.     }
  836. }
  837.  
  838. void decision()
  839. {
  840.     double resolutionControl;
  841.     int koniec = 0;
  842.     vector <int> emptyList;
  843.     sf::VideoMode desktop = sf::VideoMode().getDesktopMode();
  844.     cout << "Width wynosi: " << desktop.width << endl;
  845.     resolutionControl = desktop.width / (double)1680;
  846.     cout << "Wynik mnoznika wynosi: " << resolutionControl << endl;
  847.     desktop.width -= 15;
  848.     desktop.height -= 70;
  849.     sf::Font font;
  850.     if (!font.loadFromFile("arial.ttf"))
  851.     {
  852.         system("pause");
  853.     }
  854.     sf::Text Title;
  855.     sf::Vector2f position;
  856.     position.x = 300 * resolutionControl;
  857.     position.y = 200 * resolutionControl;
  858.     Title.setFont(font);
  859.     Title.setString("Witamy w Pasjansie");
  860.     Title.setFillColor(sf::Color::Blue);
  861.     Title.setCharacterSize(44);
  862.     Title.setPosition(position);
  863.     sf::Text text;
  864.     position.x = 240 * resolutionControl;
  865.     position.y = 410 * resolutionControl;
  866.     text.setFont(font);
  867.     text.setString("Nowa gra");
  868.     text.setFillColor(sf::Color::Red);
  869.     text.setCharacterSize(24);
  870.     text.setPosition(position);
  871.     /*sf::Text text2;
  872.     position.x = 240 * resolutionControl;
  873.     position.y = 570 * resolutionControl;
  874.     text2.setFont(font);
  875.     text2.setString("Najlepsze wyniki");
  876.     text2.setFillColor(sf::Color::Red);
  877.     text2.setCharacterSize(24);
  878.     text2.setPosition(position); */
  879.     sf::Text text3;
  880.     position.x = 240 * resolutionControl;
  881.     position.y = 650 * resolutionControl;
  882.     text3.setFont(font);
  883.     text3.setString("Wyjdz");
  884.     text3.setFillColor(sf::Color::Red);
  885.     text3.setCharacterSize(24);
  886.     text3.setPosition(position);
  887.     Sleep(2000);
  888.     sf::Music music;
  889.     if (!music.openFromFile("audio.wav"))
  890.         system("pause");
  891.     music.setLoop(true);
  892.     music.setVolume(10);
  893.     music.play();
  894.     sf::RenderWindow window(desktop, "Pasjans", sf::Style::Close);
  895.     sf::Vector2i zero;
  896.     zero.x = 0;
  897.     zero.y = 1;
  898.     window.setPosition(zero);
  899.     /*
  900.     sf::Image Icon;
  901.     if (!Icon.loadFromFile("karty\\icon.bmp"))
  902.     exit(0);
  903.     window.setIcon(32, 32, Icon.getPixelsPtr());
  904.     */
  905.     window.clear(sf::Color::Green);
  906.     window.draw(Title);
  907.     window.draw(text);
  908.     window.draw(text3);
  909.     Card *Karty;
  910.     Board *Tlo;
  911.     Tlo = new Board[14];
  912.     Karty = new Card[52];
  913.     list<Card>*lista;
  914.     lista = new list<Card>[13];
  915.     int Table[52];
  916.     for (int i = 0; i < 52; i++)
  917.     {
  918.         Table[i] = i;
  919.     }
  920.  
  921.     waiting(&window, &music, Karty, resolutionControl, Tlo);
  922.     CreateBoard(Table, Karty, lista, resolutionControl);
  923.     showing(Table, lista, &(window), resolutionControl, Tlo, 11);
  924.     window.display();
  925.     while (true)
  926.     {
  927.         sf::Event event;
  928.         if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  929.         {
  930.             check(Table, &window, lista, Karty, resolutionControl, Tlo, emptyList);
  931.         }
  932.         else {
  933.             while (window.pollEvent(event))
  934.             {
  935.                 if (event.type == sf::Event::Closed)
  936.                 {
  937.                     window.close();
  938.                     exit(0);
  939.                 }
  940.             }
  941.         }
  942.  
  943.         for (int i = 0; i < 7; i++)
  944.         {
  945.             if (lista[i].empty())
  946.             {
  947.                 koniec++;
  948.             }
  949.         }
  950.         for (int i = 11; i < 13; i++)
  951.         {
  952.             if (lista[i].empty())
  953.             {
  954.                 koniec++;
  955.             }
  956.         }
  957.         if (koniec == 9)
  958.             break;
  959.         else
  960.             koniec = 0;
  961.  
  962.     }
  963.     window.display();
  964. }
  965. int main()
  966. {
  967.     //FreeConsole();
  968.     decision();
  969.  
  970.     return 0;
  971. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement