-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameModel.cpp
75 lines (66 loc) · 2.38 KB
/
gameModel.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "gameModel.h"
#include "levelone.h"
#include "leveltwo.h"
#include "levelThree.h"
#include "levelFour.h"
#include "levelFive.h"
#include "levelSix.h"
#include "levelSeven.h"
#include "levelEight.h"
#include "levelNine.h"
#include "levelTen.h"
#include "levelEleven.h"
#include "levelTwelve.h"
#include <algorithm>
/**
* @author Joseph Corbeil, Johnny Song, Ezekiel Jaramillo, Ahmed Zahran, Raj Reddy, Joel Ronca
* @date April. 22, 2024
* @name GameModel header file for assignment9
* This cpp file defines and implements the GameModel class which manages game levels and handles logic
* for circuit simulation based on user interactions in a digital circuit simulation game.
*/
GameModel::GameModel(QObject *parent) : QObject(parent), currentLevel(0){
// Push all premade levels
levels.push_back(std::make_unique<LevelOne>());
levels.push_back(std::make_unique<LevelTwo>());
levels.push_back(std::make_unique<LevelThree>());
levels.push_back(std::make_unique<LevelFour>());
levels.push_back(std::make_unique<LevelFive>());
levels.push_back(std::make_unique<LevelSix>());
levels.push_back(std::make_unique<LevelSeven>());
levels.push_back(std::make_unique<LevelEight>());
levels.push_back(std::make_unique<LevelNine>());
levels.push_back(std::make_unique<LevelTen>());
levels.push_back(std::make_unique<LevelEleven>());
levels.push_back(std::make_unique<LevelTwelve>());
}
void GameModel::computeLevelCircuit(int currentLevel){
levels[currentLevel]->computeOutput();
bool result = levels[currentLevel]->getResult();
emit circuitCompleted(result);
}
void GameModel:: onInputReceived(std::vector<bool>inputs)
{
levels[currentLevel]->setInput(inputs);
computeLevelCircuit(currentLevel);
}
void GameModel::checkUserGate(string gate)
{
bool gateCorrect = levels[currentLevel]->correctUserGate(gate);
emit correctGate(gateCorrect);
}
void GameModel::setGateDropped(const std::vector<std::string>& gateTypes){
if (hasEmptyString(gateTypes)){
throw std::invalid_argument("One or more gate types are empty.");
}
else {
levels[currentLevel]->setGateTypes(gateTypes);
}
}
bool GameModel::hasEmptyString(const std::vector<std::string>& gateTypes) {
return std::find(gateTypes.begin(), gateTypes.end(), "") != gateTypes.end();
}
void GameModel::onGetCurrentLevel(int level)
{
currentLevel = level-1;
}