-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (46 loc) · 1.85 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
// Tetris NO LAG
#include <iostream>
#include <vector>
#include <deque>
#include "Tests.h"
#include "GameFunctions.h"
#define RUNTESTS false
int main(int argc, char* argv[]){
auto board = makeBoard(rows, columns);
if(RUNTESTS){
RunTests();
} else{
printGameRules();
bool updateSuccess = true;
bool validPos = true;
int newBlock = 0;
while(true){
std::cout << "Points: " << points << std::endl;
// make random block
if(updateSuccess && validPos){
newBlock = makeBlock();
}
// ask where to put it
printBoard(board);
std::string newBlockStr(newBlock, '#');
std::cout << "New block: " << newBlockStr << std::endl;
std::cout << "Where do you want to place the block?" << std::endl;
int newPos = 0;
std::cin >> newPos;
validPos = checkIfPositionValid(newBlock, newPos, columns);
if(!validPos){
points--;
std::cerr << "You cannot place the block here." << std::endl;
continue;
}
// try to place the block
try{
updateSuccess = updateBoard(board, newPos, newBlock);
} catch(std::runtime_error& e){
std::cerr << e.what() << std::endl;
return EXIT_SUCCESS;
}
}
}
return EXIT_SUCCESS;
}