-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgame.cpp
More file actions
134 lines (106 loc) · 2.37 KB
/
game.cpp
File metadata and controls
134 lines (106 loc) · 2.37 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "game.h"
#include "shape.h"
#include <QDebug>
#include <iostream>
using namespace std;
Game::Game(QQmlApplicationEngine *engine, QObject *parent) : QObject(parent)
{
userinfo=new Users();
QQmlContext *ctx =engine->rootContext();
//sending object for user information
ctx->setContextProperty ("userInfo" , userinfo);
ctx->setContextProperty ("myGame" , this);
expose=new ExposeClass(userinfo);
//Here we expose both the class and the model to QML
ctx->setContextProperty("ExposeClass", expose);
ctx->setContextProperty("ExposeModel", expose->model());
GameOver=false;
QObject::connect (this,SIGNAL(moveDone()),this,SLOT(createNewShape()));
QObject::connect (this,SIGNAL(gameOver()),this,SLOT(gameOverSlot()));
if(userinfo->numberOfUsers == 0)
{
userinfo->AddUser("ali","0000","pass","0","13950712");
userinfo->AddUser ("admin","0000","pass","1","19951004");
delete(userinfo);
userinfo=new Users();
}
}
Game::~Game()
{
delete(userinfo);
}
void Game::start()
{
createNewShape ();
}
int Game::score()
{
return Score;
}
void Game::setScore(int value)
{
Score = value;
emit scoreChanged();
}
void Game::createNewShape()
{
if(!GameOver)
shape=new Shape();
}
void Game::gameOverSlot()
{
cout<<endl<<"moveing down";
shape->timer->stop ();
for(int i=0;i<14;i++)
{
cout<<endl;
for(int j=0;j<14;j++)
cout<<boardArry[j][i];
}
cout<<endl<<"Game Over";
}
void Game::pause()
{
if(shape->isStillRunning)
{
shape->timer->stop ();
shape->isStillRunning=false;
}else
{
shape->timer->start();
shape->isStillRunning=true;
}
}
bool Game::isRunning()
{
return shape->isStillRunning;
}
void Game::setIsRunning(bool value)
{
shape->isStillRunning=value;
emit isRunningChanged ();
}
void Game::restart()
{
for(int i=0;i<14;i++)
for(int j=0;j<14;j++)
boardArry[i][j]=0;
shape->timer->start ();
GameOver=false;
delete shape;
createNewShape ();
setScore (0);
}
QString Game::arryQML()
{
return stringArrayQml;
}
void Game::setArryQML(QString value)
{
for(int i=0;i<14;i++)
for(int j=0;j<14;j++)
{
stringArrayQml[i*14+ j]=QString::number(boardArry[i][j]).at(0);
}
emit arryQMLChanged ();
}