SFML и C++ Уроки \ Разработка игр › Форумы › Логика игр › логика и графика Match3 game( три в ряд) › Ответ в теме: логика и графика Match3 game( три в ряд)
Спасибо большое за ответ. Ваше наброски интересные и основную идею я понял, но пару вопросов в понимании остались (ибо я тугой). Первый вопрос: разве типы для вектора не ограничиваются int, float и unsignet int?(Сразу скажу что с векторами я плохо знаком и в Visual Studio компилятор выдает ошибку “идентификатор “RectangleShape” не определен” ) Вроде больше вопросов нет. Я набросал два своих класса, но проблема возникла с рандомом он красит все шары в один цвет, а должен в разные. И я пытался и через enum и как только не пытался все равно не выходит сделать их всех разными. А вопрос с сеткой я решил с помощью матрицы, но не уверен что смогу потом с помощью мыши с объектами взаимодействовать
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
#include <SFML/Graphics.hpp> #include <cstdlib> using namespace sf; class Bubble { private: Sprite *sprite; Texture *texture; Color color; public: Bubble(Color _color) { setColor(_color); } Bubble() { setColor(GetRandomColor()); } void setColor(Color _color) { color = _color; texture = new Texture; texture->loadFromFile("images/gray.png"); sprite = new Sprite(*texture); sprite->setColor(color); } Sprite* getSprite() { return sprite; } Color getColor() { return color; } static Color GetRandomColor() { const sf::Color colorArray[5] = { sf::Color::Cyan, sf::Color::Blue, sf::Color::Green, sf::Color::Red, sf::Color::Yellow }; srand(time(NULL)); return(colorArray[rand() % 5]); } }; class GridBubbles { private: Bubble matrixBubbles[10][10]; const int N = 9; public: GridBubbles() { initMatrix(); } Bubble getBubble(int i, int j) { return matrixBubbles[i][j]; } private: void initMatrix() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { matrixBubbles[i][j].setColor(Bubble::GetRandomColor()); } } } }; int main() { Bubble bubble; GridBubbles grid; srand(time(0)); RenderWindow app(VideoMode(800, 600), "Bubbles"); app.setFramerateLimit(60); //все для фона ыыы Texture t1; t1.loadFromFile("images/background.png"); Sprite background(t1); //базовый цикл для отрисовки и всей фигни (это от бибилиотеки ) while (app.isOpen()) { sf::Event event; while (app.pollEvent(event)) { if (event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)) app.close(); } app.clear(); app.draw(background); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { Sprite *sprite = grid.getBubble(i, j).getSprite(); sprite->setPosition(i * BallSize, j * BallSize); Color color = grid.getBubble(i, j).getColor(); sprite->setColor(color); app.draw(*sprite); } } app.display(); } } |