Skip to content

Commit b330acb

Browse files
authored
Scoring (#5)
* slightly cleaning up GameState impl to move all non-pub funcs to the bottom * first refactor step. Hide old methods which exposed the implementation detail that there were discrete settled blocks vs just a collection of settled pieces which might no longer consistently stay in the same shape * all tests are passing again after first refactor * removed cell in favor of just reusing vec2 * render the active piece again * rendering each individual block again * there is now some distinction between settled blocks and the active block and tests are passing * get rid of stale todos * get rid of one more stale TODO * hey look some basic scoring! but oops I forgot to drop the blocks after clearing the rows * YOOOOOO I can clear and multi clear :) * added some test reminder * display the score * added a new failing score test * first score test passing others failing * all tests passing * a little bit of refactoring * refactored so that a block's position is implicit in its representation in the array * add scoring * quick ws fix
1 parent a4b66f2 commit b330acb

File tree

7 files changed

+641
-296
lines changed

7 files changed

+641
-296
lines changed

demo/12-scoring.gif

26 KB
Loading

readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@
7373

7474
![Image of pause screen](demo/11-pause.gif)
7575

76-
- [ ] Allow clearing lines
76+
- [X] [Scoring and line clears](https://github.com/scottnm/tetrust/commit/FILL-ME-IN)
77+
78+
![Image of scoring](demo/12-scoring.gif)
79+
7780
- [ ] Speed up pieces falling as more lines are cleared
78-
- [ ] Handle scoring
7981
- [ ] Handle quick fall
82+
- [ ] Add start screen
83+
- [ ] Add high score logging
84+
- [ ] Add high score screen from start
8085

src/block.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::randwrapper::*;
2+
use crate::util::*;
23

34
#[derive(Clone, Copy, Debug)]
45
pub enum Rotation {
@@ -8,7 +9,6 @@ pub enum Rotation {
89
Rot3,
910
}
1011

11-
// TODO (scottnm): separate out blocktype into blocktype and blockvisuals and blockdata (orientation+cells)
1212
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1313
pub enum BlockType {
1414
I = 1, // NOTE (scottnm): if our enum starts at 0, init_pair doesn't seem to function. Needs investigation
@@ -26,17 +26,11 @@ pub struct Block {
2626
pub block_type: BlockType,
2727
}
2828

29-
#[derive(Clone, Copy, Debug, PartialEq)]
30-
pub struct Cell {
31-
pub x: i32,
32-
pub y: i32,
33-
}
34-
3529
macro_rules! cell_array {
3630
( $(($x:expr,$y:expr)),* $(,)?) => {
3731
[
3832
$(
39-
Cell{x: $x, y: $y},
33+
Vec2{x: $x, y: $y},
4034
)*
4135
]
4236
};
@@ -84,7 +78,7 @@ impl Rotation {
8478
}
8579
}
8680

87-
pub fn get_kick_attempts(&self, block: BlockType, dest_rot: Rotation) -> [Cell; 5] {
81+
pub fn get_kick_attempts(&self, block: BlockType, dest_rot: Rotation) -> [Vec2; 5] {
8882
match block {
8983
BlockType::O => panic!("O blocks do not need to be kicked"),
9084
BlockType::I => match (*self, dest_rot) {
@@ -190,7 +184,7 @@ impl Block {
190184
self.block_type.sprite_char()
191185
}
192186

193-
pub fn cells(&self) -> [Cell; 4] {
187+
pub fn cells(&self) -> [Vec2; 4] {
194188
let rot = self.rot;
195189
match self.block_type {
196190
// - - - - - - 0 - - - - - - 0 - -
@@ -263,27 +257,23 @@ impl Block {
263257
}
264258

265259
pub fn top(&self) -> i32 {
266-
// TODO (scottnm): handle different block orientations
267260
// NOTE (scottnm): Unwrap is safe because all blocks should have at least 1 cell
268261
self.cells().iter().min_by_key(|cell| cell.y).unwrap().y
269262
}
270263

271264
pub fn left(&self) -> i32 {
272-
// TODO (scottnm): handle different block orientations
273265
// NOTE (scottnm): Unwrap is safe because all blocks should have at least 1 cell
274266
self.cells().iter().min_by_key(|cell| cell.x).unwrap().x
275267
}
276268

277269
pub fn width(&self) -> i32 {
278-
// TODO (scottnm): handle different block orientations
279270
// NOTE (scottnm): Unwrap is safe because all blocks should have at least 1 cell
280271
let left_block = self.left();
281272
let right_block = self.cells().iter().max_by_key(|cell| cell.x).unwrap().x;
282273
right_block - left_block + 1
283274
}
284275

285276
pub fn height(&self) -> i32 {
286-
// TODO (scottnm): handle different block orientations
287277
// NOTE (scottnm): Unwrap is safe because all blocks should have at least 1 cell
288278
let top_block = self.top();
289279
let bottom_block = self.cells().iter().max_by_key(|cell| cell.y).unwrap().y;

0 commit comments

Comments
 (0)