mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-06 03:20:26 +00:00
tetris: factor out MAX_LEVEL
This commit is contained in:
parent
8214665b7e
commit
d30858e60d
@ -1,11 +1,11 @@
|
||||
static constexpr int MAX_LEVEL = 15;
|
||||
// the number of milliseconds before a drop is forced at the given level,
|
||||
// using the NES fps counter of 50ms
|
||||
static constexpr int Gravity(int level) {
|
||||
constexpr int MS_PER_GRAV = 30; // 10MHz*63/88/455/525 (~29.97fps) in NTSC
|
||||
// The number of frames before a drop is forced, per level
|
||||
constexpr std::array<int, 30> Gravities = {
|
||||
48, 43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 5,
|
||||
4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
|
||||
constexpr std::array<int, MAX_LEVEL + 1> Gravities = {
|
||||
43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 4, 4, 3, 2, 1
|
||||
};
|
||||
if(level < 0){
|
||||
throw std::out_of_range("Illegal level");
|
||||
|
@ -33,7 +33,7 @@ bool LockPiece(){ // returns true if game has ended by reaching level 16
|
||||
linescleared_ += cleared;
|
||||
static constexpr int points[] = {50, 150, 350, 1000};
|
||||
score_ += (level_ + 1) * points[cleared - 1];
|
||||
if((level_ = linescleared_ / 10) > 15){
|
||||
if((level_ = linescleared_ / 10) > MAX_LEVEL){
|
||||
return true;
|
||||
}
|
||||
msdelay_ = std::chrono::milliseconds(Gravity(level_));
|
||||
|
@ -1,7 +1,7 @@
|
||||
void Ticker() { // FIXME ideally this would be called from constructor :/
|
||||
std::chrono::milliseconds ms;
|
||||
mtx_.lock();
|
||||
do{
|
||||
mtx_.lock();
|
||||
ms = msdelay_;
|
||||
mtx_.unlock();
|
||||
std::this_thread::sleep_for(ms);
|
||||
|
Loading…
Reference in New Issue
Block a user