#include "game.h"

#define DELAY 30000

Game::Game()
    : x(0), y(0), max_x(800), max_y(600), direction(0),
      window(sf::VideoMode(max_x, max_y), "SFML Window") {
    if (!font.loadFromFile("cascaydia.otf")) {
        std::cerr << "Failed to load font" << std::endl;
        exit(1);
    }

    text.setString("o");
    text.setFont(font);
    text.setCharacterSize(24);
    text.setFillColor(sf::Color::White);
}

void Game::run() {
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && y > 0) {
            y--;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && y < max_y - 1) {
            y++;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && x > 0) {
            x--;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && x < max_x - 1) {
            x++;
        }

        window.clear();
        text.setPosition(x, y);
        window.draw(text);
        window.display();
        sf::sleep(sf::microseconds(DELAY));
    }
}

