mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
tetris: display score and level #421
This commit is contained in:
parent
4afa02a44f
commit
34e4a5dbb9
@ -31,6 +31,19 @@ void DrawBoard() {
|
|||||||
}
|
}
|
||||||
channels_set_fg_alpha(&channels, CELL_ALPHA_TRANSPARENT);
|
channels_set_fg_alpha(&channels, CELL_ALPHA_TRANSPARENT);
|
||||||
board_->set_base(channels, 0, "");
|
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()){
|
if(!nc_.render()){
|
||||||
throw TetrisNotcursesErr("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);
|
}while(cleared);
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,10 @@ public:
|
|||||||
board_(nullptr),
|
board_(nullptr),
|
||||||
backg_(nullptr),
|
backg_(nullptr),
|
||||||
stdplane_(nc_.get_stdplane()),
|
stdplane_(nc_.get_stdplane()),
|
||||||
|
scoreplane_(nullptr),
|
||||||
gameover_(gameover),
|
gameover_(gameover),
|
||||||
level_(0),
|
level_(0),
|
||||||
|
linescleared_(0),
|
||||||
msdelay_(Gravity(level_))
|
msdelay_(Gravity(level_))
|
||||||
{
|
{
|
||||||
DrawBoard();
|
DrawBoard();
|
||||||
@ -46,6 +48,7 @@ public:
|
|||||||
|
|
||||||
#include "gravity.h"
|
#include "gravity.h"
|
||||||
#include "ticker.h"
|
#include "ticker.h"
|
||||||
|
#include "score.h"
|
||||||
#include "clear.h"
|
#include "clear.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "movedown.h"
|
#include "movedown.h"
|
||||||
@ -61,9 +64,11 @@ private:
|
|||||||
std::unique_ptr<ncpp::Plane> board_;
|
std::unique_ptr<ncpp::Plane> board_;
|
||||||
std::unique_ptr<ncpp::Visual> backg_;
|
std::unique_ptr<ncpp::Visual> backg_;
|
||||||
ncpp::Plane* stdplane_;
|
ncpp::Plane* stdplane_;
|
||||||
|
std::unique_ptr<ncpp::Plane> scoreplane_;
|
||||||
std::atomic_bool& gameover_;
|
std::atomic_bool& gameover_;
|
||||||
int board_top_y_;
|
int board_top_y_;
|
||||||
int level_;
|
int level_;
|
||||||
|
int linescleared_;
|
||||||
std::chrono::milliseconds msdelay_;
|
std::chrono::milliseconds msdelay_;
|
||||||
|
|
||||||
// Returns true if there's a current piece which can be moved
|
// Returns true if there's a current piece which can be moved
|
||||||
|
5
src/tetris/score.h
Normal file
5
src/tetris/score.h
Normal file
@ -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…
Reference in New Issue
Block a user