Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. //Logic.h
  2.  
  3. #ifndef LOGIC_H
  4. #define LOGIC_H
  5.  
  6. #include <fstream>
  7. #include <iostream>
  8. #include <vector>
  9. #include <string>
  10. #include <random>
  11. #include <chrono>
  12. #include <SFML/Graphics.hpp>
  13.  
  14. class Logic
  15. {
  16. public:
  17. Logic();
  18.  
  19. private:
  20. void QuestionHandler();
  21. int RngHandler(int from, int to);
  22. void TextStringHandler();
  23.  
  24. sf::Text TextScore;
  25. sf::Text QuestionText;
  26. sf::Text AnswerText;
  27.  
  28. sf::Font Font; //Font
  29.  
  30. std::string question;
  31. std::string correctAnswer;
  32. std::string inCorrectAnswer1;
  33. std::string inCorrectAnswer2;
  34. };
  35.  
  36. #endif // LOGIC_H
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //Trivia.cpp
  48.  
  49.  
  50. #include <SFML/Graphics.hpp>
  51. #include "Trivia.h"
  52. #include "Logic.h"
  53.  
  54.  
  55. Trivia::Trivia()
  56. :TrigWindow(sf::VideoMode(1280, 720), "Learn to debug you twit.") //Constructor (Runs stuff when program runs, mainly sets window parameters)
  57. {
  58. TrigWindow.setActive(true);
  59. TrigWindow.setFramerateLimit(60);
  60. }
  61.  
  62. void Trivia::Draw() //Draws stuff
  63. {
  64. TrigWindow.clear(sf::Color(25,25,25));
  65. TrigWindow.draw(TextScore);
  66. TrigWindow.draw(QuestionText);
  67. TrigWindow.draw(AnswerText);
  68. TrigWindow.display();
  69. }
  70.  
  71. void Trivia::Run() //Calls rest of the game functions
  72. {
  73. QuestionHandler();
  74. TextStringHandler();
  75. while(TrigWindow.isOpen())
  76. {
  77. Draw();
  78. ProcessEvents();
  79. }
  80. }
  81.  
  82. int Trivia::ProcessEvents() //Processes key inputs and other events
  83. {
  84. sf::Event Event;
  85. while(TrigWindow.pollEvent(Event))
  86. {
  87. if(Event.type == sf::Event::Closed)
  88. {
  89. TrigWindow.close();
  90. }
  91.  
  92. switch(Event.type)
  93. {
  94. case sf::Event::KeyPressed:
  95. if(Event.key.code == sf::Keyboard::Escape) //Closes window if esc pressed
  96. {
  97. TrigWindow.close();
  98. }
  99. if(Event.key.code == sf::Keyboard::Num1) //Picks 1st guess option
  100. {
  101.  
  102. return 1;
  103. }
  104. if(Event.key.code == sf::Keyboard::Num2) //Picks 2nd guess option
  105. {
  106.  
  107. return 2;
  108. }
  109. if(Event.key.code == sf::Keyboard::Num3) //Picks 3rd guess option
  110. {
  111.  
  112. return 3;
  113. }
  114. break;
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement