-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (60 loc) · 2.53 KB
/
main.cpp
File metadata and controls
85 lines (60 loc) · 2.53 KB
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
#include <SFML/Graphics.hpp>
#include "MainPage.h"
#include "LocationPage.h"
#include "FoodTypePage.h"
#include <iostream>
#include <string>
using namespace std;
using namespace sf;
int main(){
RenderWindow window(VideoMode(1000, 1100), "Restaurant Finder", Style::Titlebar | Style::Close);
window.setFramerateLimit(60);
//Different windows
MainPage mainPage;
LocationPage locationPage;
FoodTypePage foodTypePage;
//Controller
string currPage = "Main";
while(window.isOpen()){
Event event{};
while(window.pollEvent(event)){
if(event.type == Event::Closed) window.close();
//Main Info
if(currPage == "Main"){
if(event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left){
Vector2f mousePos(static_cast<float>(event.mouseButton.x), static_cast<float>(event.mouseButton.y));
if(mainPage.isLocationClicked(mousePos)){
//cout << "[MainPage] Location button clicked."<<endl;
currPage = "Location";
}else if(mainPage.isFoodTypeClicked(mousePos)){
//cout << "[MainPage] Food Type button clicked."<<endl;
currPage = "Food";
}
}
}
//Location Info
else if(currPage == "Location"){
locationPage.Event(event, window);
if(Keyboard::isKeyPressed(Keyboard::Escape)){
//cout << "[LocationPage] Returning to Main."<<endl;
currPage = "Main";
}
}
//Food Type Info
else if(currPage == "Food"){
foodTypePage.Event(event, window);
if(Keyboard::isKeyPressed(Keyboard::Escape)){
//cout << "[FoodTypePage] Returning to Main."<<endl;
currPage = "Main";
}
}
}
//Drawing
window.clear(Color(250, 243, 232)); // soft beige
if(currPage == "Main") mainPage.draw(window);
else if(currPage == "Location") locationPage.draw(window);
else if(currPage == "Food") foodTypePage.draw(window);
window.display();
}
return 0;
}