Crates.io | tetris-rs |
lib.rs | tetris-rs |
version | 0.1.4 |
source | src |
created_at | 2023-02-03 00:24:14.495269 |
updated_at | 2023-02-07 16:10:09.031867 |
description | terminal based tetris game written in rust. |
homepage | https://github.com/kunieone/tetris_rs |
repository | https://github.com/kunieone/tetris_rs |
max_upload_size | |
id | 775289 |
size | 46,015 |
A good example for beginners in Rust + Project architecture development
├── Cargo.lock
├── Cargo.toml
├── readme.md //this document
├── src
│ ├── bricks.rs
│ ├── display.rs //display game core
│ ├── env.rs // Environment Variable structure
│ ├── game.rs //game core
│ ├── main.rs //entry
│ └── record.rs //score computing & statistics
└── target
├── CACHEDIR.TAG
├── debug
├── package
└── release
add the executable command to your path
cargo install tetris-rs
excute the compiled command
tetris
:
tetris
Or you can download the source file and compile manually, if you don't want tetris to be a globally recognizable executable command
git clone https://github.com/kunieone/tetris_rs && cd tetris_rs
cargo run .
Setting environment variables to customize
# defaults:
FEATURE_BRICK=true #bool
ACCELERATE_MODE=true #bool
WIDTH=13 #number
HEIGHT=20 #number
TEXTURE_FULL='#' #char
TEXTURE_WALL='O' #char
TEXTURE_EMPTY=' ' #char
TEXTURE_SHADOW='+' #char
example:
TEXTURE_FULL='%' FEATURE_BRICK=false tetris
pub enum BrickType {
// 7 classic bricks
I,
O,
T,
S,
Z,
L,
J,
// FEATURE_BRICK to enable feature bricks
// #
Dot,
// # #
// ###
Desk,
// #
// ##
Angle,
// #
// ##
// ##
W,
// ##
Bean,
}
Eliminating one row, you get 200
scores.
60
more points per combo.
You get 1
point for every time you accelerate.
impl Record {
pub fn compute(&mut self, rows_num: usize) {
if rows_num == 0 {
self.combo = 0;
return;
}
for _ in 0..rows_num {
self.combo_once()
}
}
fn combo_once(&mut self) {
self.score += 200 + (self.combo * 60) as i64;
self.eliminate_rows += 1;
self.combo += 1;
// 计算历史最高连击
if self.combo > self.high_combo {
self.high_combo = self.combo
}
}
}
accelerate the update frequency based on your score
pub fn update_by(&mut self, counter: i32) {
match self.cfg.accelerate {
true => {
let time = match self.record.score {
0..=5999 => 100,
6000..=9999 => 70,
10000..=24999 => 60,
25000..=39999 => 50,
40000..=59999 => 45,
_ => 40,
};
if counter % (time) == 0 {
self.update()
}
}
false => {
if counter % (100) == 0 {
self.update()
}
}
}
}