Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Logic.h
- #ifndef LOGIC_H
- #define LOGIC_H
- #include <fstream>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <random>
- #include <chrono>
- #include <SFML/Graphics.hpp>
- class Logic
- {
- public:
- Logic();
- private:
- void QuestionHandler();
- int RngHandler(int from, int to);
- void TextStringHandler();
- sf::Text TextScore;
- sf::Text QuestionText;
- sf::Text AnswerText;
- sf::Font Font; //Font
- std::string question;
- std::string correctAnswer;
- std::string inCorrectAnswer1;
- std::string inCorrectAnswer2;
- };
- #endif // LOGIC_H
- //Trivia.cpp
- #include <SFML/Graphics.hpp>
- #include "Trivia.h"
- #include "Logic.h"
- Trivia::Trivia()
- :TrigWindow(sf::VideoMode(1280, 720), "Learn to debug you twit.") //Constructor (Runs stuff when program runs, mainly sets window parameters)
- {
- TrigWindow.setActive(true);
- TrigWindow.setFramerateLimit(60);
- }
- void Trivia::Draw() //Draws stuff
- {
- TrigWindow.clear(sf::Color(25,25,25));
- TrigWindow.draw(TextScore);
- TrigWindow.draw(QuestionText);
- TrigWindow.draw(AnswerText);
- TrigWindow.display();
- }
- void Trivia::Run() //Calls rest of the game functions
- {
- QuestionHandler();
- TextStringHandler();
- while(TrigWindow.isOpen())
- {
- Draw();
- ProcessEvents();
- }
- }
- int Trivia::ProcessEvents() //Processes key inputs and other events
- {
- sf::Event Event;
- while(TrigWindow.pollEvent(Event))
- {
- if(Event.type == sf::Event::Closed)
- {
- TrigWindow.close();
- }
- switch(Event.type)
- {
- case sf::Event::KeyPressed:
- if(Event.key.code == sf::Keyboard::Escape) //Closes window if esc pressed
- {
- TrigWindow.close();
- }
- if(Event.key.code == sf::Keyboard::Num1) //Picks 1st guess option
- {
- return 1;
- }
- if(Event.key.code == sf::Keyboard::Num2) //Picks 2nd guess option
- {
- return 2;
- }
- if(Event.key.code == sf::Keyboard::Num3) //Picks 3rd guess option
- {
- return 3;
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement