Untitled
unknown
plain_text
2 years ago
3.9 kB
9
Indexable
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cstdlib>
#include <ctime>
// Funkcja do gry w jednorękiego bandytę
void slotMachine(sf::RenderWindow& window) {
sf::Font font;
if (!font.loadFromFile("arial.ttf")) {
std::cerr << "Failed to load font!" << std::endl;
return;
}
sf::Text text("Press Space to Spin", font, 30);
text.setFillColor(sf::Color::White);
text.setPosition(200, 500);
sf::RectangleShape lever(sf::Vector2f(50, 150));
lever.setFillColor(sf::Color(139, 69, 19)); // Brown color for the lever
lever.setPosition(700, 400);
sf::RectangleShape slot1(sf::Vector2f(100, 100));
sf::RectangleShape slot2(sf::Vector2f(100, 100));
sf::RectangleShape slot3(sf::Vector2f(100, 100));
slot1.setPosition(150, 200);
slot2.setPosition(300, 200);
slot3.setPosition(450, 200);
srand(static_cast<unsigned>(time(0)));
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space) {
// Spin the slots
int result1 = rand() % 3;
int result2 = rand() % 3;
int result3 = rand() % 3;
// Set the colors based on the results
slot1.setFillColor(sf::Color::Red);
slot2.setFillColor(sf::Color::Green);
slot3.setFillColor(sf::Color::Blue);
if (result1 == 0)
slot1.setFillColor(sf::Color::Red);
else if (result1 == 1)
slot1.setFillColor(sf::Color::Green);
else
slot1.setFillColor(sf::Color::Blue);
if (result2 == 0)
slot2.setFillColor(sf::Color::Red);
else if (result2 == 1)
slot2.setFillColor(sf::Color::Green);
else
slot2.setFillColor(sf::Color::Blue);
if (result3 == 0)
slot3.setFillColor(sf::Color::Red);
else if (result3 == 1)
slot3.setFillColor(sf::Color::Green);
else
slot3.setFillColor(sf::Color::Blue);
}
}
window.clear();
window.draw(lever);
window.draw(slot1);
window.draw(slot2);
window.draw(slot3);
window.draw(text);
window.display();
}
}
// Funkcja do gry numer 2
void game2(sf::RenderWindow& window) {
sf::RectangleShape shape(sf::Vector2f(100, 100));
shape.setFillColor(sf::Color::Blue);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
}
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Game Menu");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
// Menu
std::cout << "1. Jednoręki bandyta" << std::endl;
std::cout << "2. Gra numer 2" << std::endl;
std::cout << "Wybierz numer gry: ";
int choice;
std::cin >> choice;
switch (choice) {
case 1:
slotMachine(window);
break;
case 2:
game2(window);
break;
default:
std::cout << "Nieprawidłowy numer gry!" << std::endl;
break;
}
window.display();
}
return 0;
}
Editor is loading...
Leave a Comment