tetris: display score and level #421

pull/426/head
nick black 4 years ago
parent 4afa02a44f
commit 34e4a5dbb9
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -31,6 +31,19 @@ void DrawBoard() {
}
channels_set_fg_alpha(&channels, CELL_ALPHA_TRANSPARENT);
board_->set_base(channels, 0, "");
scoreplane_ = std::make_unique<ncpp::Plane>(1, 20, y - BOARD_HEIGHT, 2, nullptr);
if(!scoreplane_){
throw TetrisNotcursesErr("Plane()");
}
uint64_t scorechan = 0;
channels_set_bg_alpha(&scorechan, CELL_ALPHA_TRANSPARENT);
channels_set_fg_alpha(&scorechan, CELL_ALPHA_TRANSPARENT);
if(!scoreplane_->set_base(scorechan, 0, "")){
throw TetrisNotcursesErr("set_base()");
}
scoreplane_->set_fg(0x00d0a0);
scoreplane_->set_bg_alpha(CELL_ALPHA_TRANSPARENT);
UpdateScore();
if(!nc_.render()){
throw TetrisNotcursesErr("render()");
}

@ -45,8 +45,18 @@ void LockPiece(){
}
}
}
/*for(int x = 1 ; x < bdimx - 1 ; ++x){
}*/
linescleared_ += cleared;
if(cleared == 4){
score_ += (level_ + 1) * 1000;
}else if(cleared == 3){
score_ += (level_ + 1) * 350;
}else if(cleared == 2){
score_ += (level_ + 1) * 150;
}else{
score_ += (level_ + 1) * 50;
}
level_ = linescleared_ / 10;
UpdateScore();
}
}while(cleared);
}

@ -32,8 +32,10 @@ public:
board_(nullptr),
backg_(nullptr),
stdplane_(nc_.get_stdplane()),
scoreplane_(nullptr),
gameover_(gameover),
level_(0),
linescleared_(0),
msdelay_(Gravity(level_))
{
DrawBoard();
@ -46,6 +48,7 @@ public:
#include "gravity.h"
#include "ticker.h"
#include "score.h"
#include "clear.h"
#include "lock.h"
#include "movedown.h"
@ -61,9 +64,11 @@ private:
std::unique_ptr<ncpp::Plane> board_;
std::unique_ptr<ncpp::Visual> backg_;
ncpp::Plane* stdplane_;
std::unique_ptr<ncpp::Plane> scoreplane_;
std::atomic_bool& gameover_;
int board_top_y_;
int level_;
int linescleared_;
std::chrono::milliseconds msdelay_;
// Returns true if there's a current piece which can be moved

@ -0,0 +1,5 @@
void UpdateScore(){
if(scoreplane_->printf(0, 0, "level: %02d score: %ju", level_, static_cast<uintmax_t>(score_)) < 0){
throw TetrisNotcursesErr("printf()");
}
}
Loading…
Cancel
Save