Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include<iostream>
- #include<SFML/System.hpp>
- #include<SFML/Window.hpp>
- #include<SFML/Main.hpp>
- #include<SFML/Audio.hpp>
- #include<string>
- #include<list>
- #include <time.h>
- #include <windows.h>
- using namespace std;
- class Board {
- public:
- sf::Vector2f position;
- sf::Sprite Sprite;
- sf::Sprite Sprite1;
- sf::Texture texture;
- sf::Texture texture1;
- sf::Text text;
- sf::Text text1;
- sf::Font font;
- string adres = "karty\\tlo.png";
- string backGR = "karty\\background.png";
- void loadBoardPic()
- {
- if (!(texture).loadFromFile(adres))
- {
- system("pause");
- }
- }
- void loadBackGR()
- {
- if (!(texture1).loadFromFile(backGR))
- {
- system("pause");
- }
- }
- void loadText(double resolutionCtrl)
- {
- if (!font.loadFromFile("arial.ttf"))
- {
- exit(0);
- }
- text.setFont(font);
- text1.setFont(font);
- text.setString("Losuj od nowa");
- text1.setString("Pokaz");
- text.setFillColor(sf::Color::Green);
- text1.setFillColor(sf::Color::Green);
- text.setCharacterSize(16);
- text.setCharacterSize(17);
- position.x = 15 * resolutionCtrl;
- position.y = 700 * resolutionCtrl;
- text.setPosition(position);
- position.x = 15 * resolutionCtrl;
- position.y = 100 * resolutionCtrl;
- text1.setPosition(position);
- }
- void drawBack(sf::RenderWindow* window)
- {
- Sprite1.setTexture(texture1);
- Sprite1.setPosition(position);
- (*window).draw(Sprite1);
- }
- void drawBoard(sf::RenderWindow* window)
- {
- Sprite.setTexture(texture);
- Sprite.setPosition(position);
- (*window).draw(Sprite);
- }
- void drawText(sf::RenderWindow* window)
- {
- (*window).draw(text);
- (*window).draw(text1);
- }
- };
- class Card {
- public:
- int id_karty, value;
- bool enableToMove;
- sf::Vector2f docelowe_polozenie;
- sf::Sprite Sprite;
- sf::Texture texture;
- sf::Texture textureClr;
- unsigned int odkryte;
- string adres;
- string adres1 = "karty\\karta53.png";
- void loadCardPic()
- {
- cout << "Adres ktory zostanie dodany: " << adres << endl;
- if (!(texture).loadFromFile(adres))
- {
- system("pause");
- }
- if (!(textureClr).loadFromFile(adres1))
- exit(0);
- }
- void wyswietlanie(sf::RenderWindow* window)
- {
- if (odkryte == 2)
- {
- Sprite.setTexture(texture);
- Sprite.setPosition(docelowe_polozenie);
- (*window).draw(Sprite);
- }
- if (odkryte == 1)
- {
- Sprite.setTexture(textureClr);
- Sprite.setPosition(docelowe_polozenie);
- (*window).draw(Sprite);
- }
- }
- };
- struct infoAboutList {
- int index;
- int x;
- int y;
- };
- ///DEKLARACJE FUNKCJI///-------------------------------------
- void Tworzenie_Kart(sf::RenderWindow* window, Card *Karty, Board* Tlo, double resolutionCtrl);
- void podtrzymujaca(sf::RenderWindow* window);
- void decision();
- void waiting(sf::RenderWindow* window, sf::Music* music, Card *Karty, double resolutionCtrl, Board* Tlo);
- void showing(int *Table, list<Card> *lista, sf::RenderWindow* window, double resolutionCtrl, Board *Tlo, int ListNR);
- void drukowanieList(list<Card> *lista);
- ///-----------------------------------------------------------
- ///
- void waiting(sf::RenderWindow* window, sf::Music* music, Card *Karty, double resolutionCtrl, Board* Tlo)
- {
- sf::Sprite Sprite;
- sf::Texture texture;
- sf::Event event;
- if (!(texture).loadFromFile("karty\\karta.png"))
- system("pause");
- Sprite.setTexture(texture);
- Sprite.setPosition(sf::Vector2f(10, 50));
- (*window).draw(Sprite);
- int i = 0;
- (*window).display();
- Sleep(2000);
- while (i == 0)
- {
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- sf::Vector2i localPosition = sf::Mouse::getPosition(*window);
- int x = localPosition.x;
- int y = localPosition.y;
- if ((x >= 239 * resolutionCtrl && x <= 433 * resolutionCtrl) && (y >= 409 * resolutionCtrl && y <= 436 * resolutionCtrl))
- {
- i = 1;
- Tworzenie_Kart(&(*window), Karty, Tlo, resolutionCtrl);
- }
- if ((x >= 239 * resolutionCtrl && x <= 380 * resolutionCtrl) && (y >= 649 * resolutionCtrl && y <= 676 * resolutionCtrl))
- {
- i = 1;
- (*window).close();
- exit(0);
- }
- }
- while ((*window).pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- {
- (*window).close();
- exit(0);
- }
- }
- }
- }
- ///FUNKCJA ZAPĘTLA PROGRAM I CHRONI PRZED ZATRZYMANIEM-----------------
- void podtrzymujaca(sf::RenderWindow* window)
- {
- while ((*window).isOpen())
- {
- sf::Event event;
- while ((*window).pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- (*window).close();
- }
- }
- }
- ///---------------------------------------------------------------------
- ///(createBoard)MIESZANIE KOLEJNOSCI LICZB W TABLICY W LOSOWY SPOSOB--------------------------------------------
- void Shuffling(int * Table)
- {
- int i, i1, i2;
- srand(time(NULL));
- for (i = 1; i <= 3 * 52; i++)
- {
- i1 = rand() % 52; i2 = rand() % 52;
- swap(Table[i1], Table[i2]);
- }
- }
- void add_to_list(list<Card> *list, int start, int end, int posX, int posY, int* TableID, Card *Karty)
- {
- int i, value;
- for (i = start; i <= end; i++)
- {
- value = TableID[i];
- Karty[value].docelowe_polozenie.x = posX;
- Karty[value].docelowe_polozenie.y = posY;
- if (i == end)
- {
- Karty[value].odkryte = 2;
- Karty[value].enableToMove = true;
- }
- else {
- Karty[value].odkryte = 1;
- Karty[value].enableToMove = false;
- }
- (*list).push_front(Karty[value]);
- posY += 10;
- }
- }
- void CreateBoard(int *TableID, Card *Karty, list<Card> *lista, double resolutionCtrl)
- {
- int i, value, cardPosX = 1400 * resolutionCtrl, cardPosY = 230 * resolutionCtrl;
- for (i = 0; i < 13; i++)
- {
- lista[i].clear();
- }
- Shuffling(TableID);
- cardPosX = 1400 * resolutionCtrl, cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[0], 0, 6, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[1], 7, 12, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[2], 13, 17, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[3], 18, 21, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[4], 22, 24, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[5], 25, 26, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- add_to_list(&lista[6], 27, 27, cardPosX, cardPosY, TableID, Karty);
- cardPosX -= 205 * resolutionCtrl;
- cardPosY = 230 * resolutionCtrl;
- for (i = 28; i < 52; i++)
- {
- value = TableID[i];
- Karty[value].docelowe_polozenie.x = 0;
- Karty[value].docelowe_polozenie.y = 0;
- Karty[value].odkryte = 0;
- Karty[value].enableToMove = false;
- lista[12].push_back(Karty[value]);
- }
- }
- void Tworzenie_Kart(sf::RenderWindow* window, Card *Karty, Board* Tlo, double resolutionCtrl)
- {
- int i, k = 1, j = 48, color = 1, posX;
- string sciezka = "karty\\karta";
- string numer;
- posX = 640;
- Tlo[0].loadText(resolutionCtrl);
- Tlo[0].position.x = 0;
- Tlo[0].position.y = 0;
- Tlo[0].loadBackGR();
- for (i = 1; i <= 4; i++)
- {
- Tlo[i].position.x = posX*resolutionCtrl;
- Tlo[i].position.y = 30 * resolutionCtrl;
- Tlo[i].loadBoardPic();
- posX += 180;
- }
- posX = 1400 * resolutionCtrl;
- for (i = 5; i < 12; i++)
- {
- Tlo[i].position.x = posX;
- Tlo[i].position.y = 230 * resolutionCtrl;
- Tlo[i].loadBoardPic();
- posX -= 205 * resolutionCtrl;
- }
- Tlo[12].adres = "karty\\karta54.png";
- Tlo[12].position.x = 30 * resolutionCtrl;
- Tlo[12].position.y = 50 * resolutionCtrl;
- Tlo[13].adres = "karty\\odNowa.png";
- Tlo[13].position.x = 1480 * resolutionCtrl;
- Tlo[13].position.y = 20 * resolutionCtrl;
- for (i = 12; i < 14; i++)
- {
- Tlo[i].loadBoardPic();
- }
- for (i = 0; i < 52; i++)
- {
- Karty[i].id_karty = k;
- Karty[i].value = color;
- if (k == 13)
- {
- k = 0;
- color++;
- }
- k++;
- numer = sciezka + (char)(i + j) + ".png";
- if (i % 2 == 0) {
- Karty[i].odkryte = 0;
- }
- else
- {
- Karty[i].odkryte = 2;
- }
- Karty[i].adres = numer;
- cout << Karty[i].adres << endl;
- Karty[i].loadCardPic();
- Karty[i].docelowe_polozenie.x = 0;
- Karty[i].docelowe_polozenie.y = 0;
- Karty[i].enableToMove = false;
- if (i >= 49)
- {
- sciezka = "karty\\karta5";
- j = -2;
- }
- else {
- if (i >= 39)
- {
- sciezka = "karty\\karta4";
- j = 8;
- }
- else
- {
- if (i >= 29)
- {
- sciezka = "karty\\karta3";
- j = 18;
- }
- else
- {
- if (i >= 19)
- {
- sciezka = "karty\\karta2";
- j = 28;
- }
- else {
- if (i >= 9)
- {
- sciezka = "karty\\karta1";
- j = 38;
- }
- }
- }
- }
- }
- }
- }
- void showing(int *Table, list<Card> *lista, sf::RenderWindow* window, double resolutionCtrl, Board *Tlo, int ListNR)
- {
- int i, value;
- (*window).clear(sf::Color::Red);
- Tlo[0].drawBack(&(*window));
- for (i = 1; i < 14; i++)
- {
- Tlo[i].drawBoard(&(*window));
- }
- list <Card>::reverse_iterator it;
- if (ListNR == 0)
- {
- for (i = 11; i >= 0; i--)
- {
- for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
- {
- it->wyswietlanie(&(*window));
- }
- }
- }
- else {
- if (ListNR == 11)
- {
- for (i = 0; i <= 11; i++)
- {
- for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
- {
- it->wyswietlanie(&(*window));
- }
- }
- }
- else {
- for (i = 11; i > ListNR; i--)
- {
- for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
- {
- it->wyswietlanie(&(*window));
- }
- }
- for (i = ListNR - 1; i >= 0; i--)
- {
- for (it = lista[i].rbegin(); it != lista[i].rend(); it++)
- {
- it->wyswietlanie(&(*window));
- }
- }
- for (it = lista[ListNR].rbegin(); it != lista[ListNR].rend(); it++)
- {
- it->wyswietlanie(&(*window));
- }
- }
- }
- }
- void change_list(int add, int del, list<Card> *lista, int wspClickCardX, int wspClickCardY, list <Card>::iterator iter, double resolutionCtrl)
- {
- int x, y, counter = 1;
- list <Card>::iterator it;
- it = lista[add].begin();
- list <Card>::iterator it2;
- Card Karta;
- it2 = lista[del].begin();
- do
- {
- if ((it2)->adres == iter->adres)
- {
- it2++;
- break;
- }
- counter++;
- } while ((it2++) != lista[del].end());
- for (int k = 0; k < counter; k++)
- {
- it2--;
- it = lista[add].begin();
- if (lista[add].empty())
- {
- x = wspClickCardX;
- y = wspClickCardY;
- }
- else
- {
- if (add > 6) {
- x = it->docelowe_polozenie.x;
- y = (it->docelowe_polozenie.y);
- }
- else {
- x = it->docelowe_polozenie.x;
- y = (it->docelowe_polozenie.y) + 16;
- }
- }
- Karta.id_karty = it2->id_karty;
- Karta.value = it2->value;
- Karta.enableToMove = it2->enableToMove;
- Karta.docelowe_polozenie.x = x;
- Karta.docelowe_polozenie.y = y;
- Karta.Sprite = it2->Sprite;
- Karta.texture = it2->texture;
- Karta.textureClr = it2->textureClr;
- Karta.odkryte = it2->odkryte;
- Karta.adres = it2->adres;
- Karta.adres1 = it2->adres1;
- lista[add].push_front(Karta);
- lista[del].erase(it2);
- it2 = lista[del].begin();
- for (int j = 0; j != (counter - (k + 1)); j++)
- {
- it2++;
- }
- }
- if (lista[del].begin() != lista[del].end())
- {
- it = lista[del].begin();
- it->enableToMove = true;
- it->odkryte = 2;
- }
- drukowanieList(lista);
- }
- void drukowanieList(list<Card> *lista)
- {
- int i;
- list <Card>::iterator it;
- for (i = 0; i < 7; i++)
- {
- for (it = lista[i].begin(); it != lista[i].end(); ++it)
- {
- cout << it->id_karty << " , ";
- }
- cout << endl;
- }
- }
- struct infoAboutList checkEmptyList(double resolutionCtrl, vector<int> emptyList, list <Card>::iterator picked)
- {
- cout << "Weszlo w check empty list" << endl;
- int capacity = emptyList.size(), index;
- struct infoAboutList foundList;
- foundList.index = -1;
- foundList.x = 0;
- foundList.y = 0;
- for (int i = 0; i < capacity; i++)
- {
- index = emptyList[i];
- switch (index)
- {
- case 0: {
- 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))
- {
- foundList.index = 0;
- foundList.x = 1400 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 1: {
- 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))
- {
- foundList.index = 1;
- foundList.x = 1195 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 2: {
- 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))
- {
- foundList.index = 2;
- foundList.x = 990 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 3: {
- 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))
- {
- foundList.index = 3;
- foundList.x = 785 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 4: {
- 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))
- {
- foundList.index = 4;
- foundList.x = 580 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 5: {
- 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))
- {
- foundList.index = 5;
- foundList.x = 375 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 6: {
- 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))
- {
- foundList.index = 6;
- foundList.x = 170 * resolutionCtrl;
- foundList.y = 230 * resolutionCtrl;
- }
- }
- break;
- case 7: {
- 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))
- {
- foundList.index = 7;
- foundList.x = 1180 * resolutionCtrl;
- foundList.y = 30 * resolutionCtrl;
- }
- }
- break;
- case 8: {
- 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))
- {
- foundList.index = 8;
- foundList.x = 1000 * resolutionCtrl;
- foundList.y = 30 * resolutionCtrl;
- }
- }
- break;
- case 9: {
- 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))
- {
- foundList.index = 9;
- foundList.x = 820 * resolutionCtrl;
- foundList.y = 30 * resolutionCtrl;
- }
- }
- break;
- case 10: {
- 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))
- {
- foundList.index = 10;
- foundList.x = 640 * resolutionCtrl;
- foundList.y = 30 * resolutionCtrl;
- }
- }
- break;
- }
- }
- cout << "Wyszło z empty list" << endl;
- return foundList;
- }
- void transferingToShow(list<Card> *lista, double resolutionCtrl)
- {
- Card Karta;
- list <Card>::iterator it;
- if (lista[12].empty())
- {
- lista[12].swap(lista[11]);
- }
- else {
- it = lista[12].end();
- it--;
- Karta.id_karty = it->id_karty;
- Karta.value = it->value;
- Karta.enableToMove = true;
- Karta.docelowe_polozenie.x = 170 * resolutionCtrl;
- Karta.docelowe_polozenie.y = 50 * resolutionCtrl;
- Karta.Sprite = it->Sprite;
- Karta.texture = it->texture;
- Karta.textureClr = it->textureClr;
- Karta.odkryte = 2;
- Karta.adres = it->adres;
- Karta.adres1 = it->adres1;
- lista[11].push_front(Karta);
- lista[12].pop_back();
- }
- }
- void check(int *Table, sf::RenderWindow* window, list<Card> *lista, Card *Karty, double resolutionCtrl, Board *Tlo, vector<int> emptyList)
- {
- sf::Vector2i localPosition = sf::Mouse::getPosition(*window);
- int x = localPosition.x;
- int y = localPosition.y;
- if ((((x >= 28 * resolutionCtrl) && (x <= 118 * resolutionCtrl)) && ((y >= 48 * resolutionCtrl) && (y <= 172 * resolutionCtrl))) && (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
- {
- transferingToShow(lista, resolutionCtrl);
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
- (*window).display();
- Sleep(350);
- return;
- }
- list <Card>::iterator it;
- list <Card>::iterator it2;
- list <Card>::iterator it3;
- list <Card>::iterator it4;
- vector<sf::Vector2f> coOrdinates;
- int ordX, var = 0, ordY, i, m, saveListI, counter = 0;
- struct infoAboutList result;
- result.index = -1;
- for (i = 0; i < 12; i++)
- {
- for (it = lista[i].begin(); it != lista[i].end(); ++it)
- {
- 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)
- {
- cout << "ID trzymanej karty!!: " << it->id_karty << endl;
- it3 = it;
- it3++;
- it4 = it;
- do {
- if (it3 != lista[i].begin())
- {
- it3--;
- }
- coOrdinates.push_back(it3->docelowe_polozenie);
- counter++;
- } while (it3 != lista[i].begin());
- ordX = it->docelowe_polozenie.x;
- ordY = it->docelowe_polozenie.y;
- while (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- localPosition = sf::Mouse::getPosition(*window);
- for (m = 0; m < counter; m++)
- {
- (it4->docelowe_polozenie.x) = coOrdinates[m].x + (localPosition.x - x);
- it4->docelowe_polozenie.y = coOrdinates[m].y + (localPosition.y - y);
- if (it4 != lista[i].begin())
- {
- it4--;
- }
- }
- it4 = it;
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, i);
- (*window).display();
- }
- if ((it->docelowe_polozenie.x != ordX) || (it->docelowe_polozenie.y != ordY))
- {
- for (int k = 0; k<7; k++)
- {
- if (lista[k].empty() && it->id_karty == 13)
- {
- cout << "Przeszlo tu" << endl;
- emptyList.push_back(k);
- }
- else {
- if(lista[k].empty())
- {
- break;
- }
- cout << "Przeszlo ten warunek a nie powinno" << endl;
- it2 = lista[k].begin();
- 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))
- {
- cout << "Weszło dla jednej " << it->id_karty << " i drugiej " << it2->id_karty << endl;
- if (i != k)
- {
- x = it2->docelowe_polozenie.x;
- y = it2->docelowe_polozenie.y;
- var = 1;
- saveListI = k;
- result.index = 0;
- break;
- }
- }
- }
- }
- if (var != 1) {
- for (int k = 7; k < 11; k++)
- {
- for (it2 = lista[k].begin(); it2 != lista[k].end(); ++it2)
- {
- 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))
- {
- if (i != k)
- {
- x = it2->docelowe_polozenie.x;
- y = it2->docelowe_polozenie.y;
- var = 1;
- saveListI = k;
- }
- }
- }
- if (lista[k].empty() && it->id_karty == 1)
- {
- emptyList.push_back(k);
- }
- }
- }
- if (var != 1)
- {
- if (!(emptyList.empty()))
- {
- result = checkEmptyList(resolutionCtrl, emptyList, it);
- if (result.index == -1)
- {
- for (m = 0; m < counter; m++)
- {
- it4->docelowe_polozenie.x = coOrdinates[m].x;
- it4->docelowe_polozenie.y = coOrdinates[m].y;
- if (it4 != lista[i].begin())
- {
- it4--;
- }
- }
- it4 = it;
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
- (*window).display();
- }
- else {
- change_list(result.index, i, lista, result.x, result.y, it, resolutionCtrl);
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
- (*window).display();
- }
- }
- else
- {
- for (m = 0; m < counter; m++)
- {
- it4->docelowe_polozenie.x = coOrdinates[m].x;
- it4->docelowe_polozenie.y = coOrdinates[m].y;
- if (it4 != lista[i].begin())
- {
- it4--;
- }
- }
- it4 = it;
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
- (*window).display();
- }
- }
- else
- {
- change_list(saveListI, i, lista, ordX, ordY, it, resolutionCtrl);
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
- (*window).display();
- }
- }
- break;
- }
- }
- }
- if ((((x >= 1478 * resolutionCtrl) && (x <= 1616 * resolutionCtrl)) && ((y >= 20 * resolutionCtrl) && (y <= 67 * resolutionCtrl))) && (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
- {
- CreateBoard(Table, Karty, lista, resolutionCtrl);
- showing(Table, lista, &(*window), resolutionCtrl, Tlo, 11);
- (*window).display();
- Sleep(700);
- }
- }
- void decision()
- {
- double resolutionControl;
- int koniec = 0;
- vector <int> emptyList;
- sf::VideoMode desktop = sf::VideoMode().getDesktopMode();
- cout << "Width wynosi: " << desktop.width << endl;
- resolutionControl = desktop.width / (double)1680;
- cout << "Wynik mnoznika wynosi: " << resolutionControl << endl;
- desktop.width -= 15;
- desktop.height -= 70;
- sf::Font font;
- if (!font.loadFromFile("arial.ttf"))
- {
- system("pause");
- }
- sf::Text Title;
- sf::Vector2f position;
- position.x = 300 * resolutionControl;
- position.y = 200 * resolutionControl;
- Title.setFont(font);
- Title.setString("Witamy w Pasjansie");
- Title.setFillColor(sf::Color::Blue);
- Title.setCharacterSize(44);
- Title.setPosition(position);
- sf::Text text;
- position.x = 240 * resolutionControl;
- position.y = 410 * resolutionControl;
- text.setFont(font);
- text.setString("Nowa gra");
- text.setFillColor(sf::Color::Red);
- text.setCharacterSize(24);
- text.setPosition(position);
- /*sf::Text text2;
- position.x = 240 * resolutionControl;
- position.y = 570 * resolutionControl;
- text2.setFont(font);
- text2.setString("Najlepsze wyniki");
- text2.setFillColor(sf::Color::Red);
- text2.setCharacterSize(24);
- text2.setPosition(position); */
- sf::Text text3;
- position.x = 240 * resolutionControl;
- position.y = 650 * resolutionControl;
- text3.setFont(font);
- text3.setString("Wyjdz");
- text3.setFillColor(sf::Color::Red);
- text3.setCharacterSize(24);
- text3.setPosition(position);
- Sleep(2000);
- sf::Music music;
- if (!music.openFromFile("audio.wav"))
- system("pause");
- music.setLoop(true);
- music.setVolume(10);
- music.play();
- sf::RenderWindow window(desktop, "Pasjans", sf::Style::Close);
- sf::Vector2i zero;
- zero.x = 0;
- zero.y = 1;
- window.setPosition(zero);
- /*
- sf::Image Icon;
- if (!Icon.loadFromFile("karty\\icon.bmp"))
- exit(0);
- window.setIcon(32, 32, Icon.getPixelsPtr());
- */
- window.clear(sf::Color::Green);
- window.draw(Title);
- window.draw(text);
- window.draw(text3);
- Card *Karty;
- Board *Tlo;
- Tlo = new Board[14];
- Karty = new Card[52];
- list<Card>*lista;
- lista = new list<Card>[13];
- int Table[52];
- for (int i = 0; i < 52; i++)
- {
- Table[i] = i;
- }
- waiting(&window, &music, Karty, resolutionControl, Tlo);
- CreateBoard(Table, Karty, lista, resolutionControl);
- showing(Table, lista, &(window), resolutionControl, Tlo, 11);
- window.display();
- while (true)
- {
- sf::Event event;
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- check(Table, &window, lista, Karty, resolutionControl, Tlo, emptyList);
- }
- else {
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- {
- window.close();
- exit(0);
- }
- }
- }
- for (int i = 0; i < 7; i++)
- {
- if (lista[i].empty())
- {
- koniec++;
- }
- }
- for (int i = 11; i < 13; i++)
- {
- if (lista[i].empty())
- {
- koniec++;
- }
- }
- if (koniec == 9)
- break;
- else
- koniec = 0;
- }
- window.display();
- }
- int main()
- {
- //FreeConsole();
- decision();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement