0% found this document useful (0 votes)
9 views

Game CPP

Uploaded by

wijifal264
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Game CPP

Uploaded by

wijifal264
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include "Game.

h"
#include <set>
#include <vector>

namespace Tetris {

void Game::startGame(){
currentBrick = std::make_unique<Brick>(shapesContainer.getNextShape(),board);
board.placeBrick(*currentBrick);
pause = false;
}
void Game::setPause(const bool& p){pause = p;}
void Game::endGame(){gameOver = true;}

bool Game::move(const Direction& dir){


if(!pause && !(*currentBrick).moveBrick(dir)){
if(dir == Direction::DOWN) nextCurrentBrick();
return false;
}
return true;
}
void Game::rotate(const Direction& dir){
if(!pause) (*currentBrick).rotateBrick(dir);
}
void Game::dropCurrentBrick(){
while(move(Direction::DOWN));
}
void Game::nextCurrentBrick(){
std::set<unsigned> mySet= {};// lines occupied by current brick (set a la
particularité de ne pas répété les élément inséré)
std::vector<unsigned> points= {0,40,100,300,1200};
unsigned cpt =0; //count nb rows compteled with this brick
for(const Position& pos : (*currentBrick).getCellsPositions()){
mySet.insert(pos.x());
}
for(const unsigned& i: mySet){
if(board.checkCompleteRow(i)){ /////
board.deleteRow(i);
cpt ++ ;
}
}
score += (points[cpt] * cpt + ((*currentBrick).getAbsolutePosition().x()-2)) *
level;
/* (40 * l + d) * n si l <= 1, l ligne , n niveeau , d
drop
(100 * l + d) * n si l = 2,
(300 * l + d) * n si l = 3,
(1200 * l + d) * n si l = 4 */
setLevel(cpt);
rowcpt += cpt;
currentBrick = std::make_unique<Brick>(shapesContainer.getNextShape(), board);
if(score>=50000 || rowcpt>= 100 || !board.placeBrick(*currentBrick)) gameOver =
true;
}

void Game::setLevel(const unsigned rows){


static unsigned cpt =0;
cpt+= rows;
if(cpt>=10){
level ++;
cpt -=10;
}
}
const bool Game::checkHasWon(){
if(!gameOver) throw std::logic_error("the game is not over");

if(score>=50000 || rowcpt>= 100)return true;


else return false;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy