-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
57 lines (44 loc) · 1.36 KB
/
main.cpp
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
/*!\file main.cpp
*
* \brief Contians Main function which initializes Game object.
*
* \author Chad Martin
*
* This file is used to generate and set up a window for
* the game snake to be played in.
*/
#include "Game.h"
#include <QDesktopWidget>
#include <QApplication>
/*! \brief Sets up window size and centers window on screen.
* Precondition: Program has started.
* Postcondition: Game window is displayed on center of screen
* \param &widget A user interface object.*/
void center(QWidget &widget)
{
int x, y;
int screenWidth;
int screenHeight;
int WIDTH = 456; //set window WIDTH to 456 pixels
int HEIGHT = 773; //set window HEIGHT to 773 pixels
QDesktopWidget *desktop = QApplication::desktop();
//finds screen dimensions
screenWidth = desktop->width();
screenHeight = desktop->height();
// finds screen center
x = (screenWidth - WIDTH) / 2;
y = (screenHeight - HEIGHT) / 2;
//sets up window
widget.setGeometry(x, y, WIDTH, HEIGHT);
widget.setFixedSize(WIDTH, HEIGHT);
}
int main(int argc, char *argv[])
{
// Creates QApplication object
QApplication app(argc, argv);
Game window; // Creates a Game instance
window.setWindowTitle("Snake 2.0"); // names Game window
window.show(); // displaying window on screen
center(window); // set up window size and center window on screen
return app.exec();
}