-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTetrisBoardTextView.java
More file actions
70 lines (61 loc) · 2.09 KB
/
TetrisBoardTextView.java
File metadata and controls
70 lines (61 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* TetrisBoardTextView creates a String view of a TetrisBoard.
*
* @author Ching Ching Huang
*
*/
public class TetrisBoardTextView {
private TetrisBoard board;
private TetrisPiece piece;
/*
* constructor takes in tetris board and calls the board
*/
public TetrisBoardTextView(TetrisBoard b) {
board = b;
}
public java.lang.String getBoardString() {
return null;
}
/*
* print out the board and the piece
*/
public void printBoard() {
piece = board.getCurrentPiece();//get the current tetris piece
int rot = piece.getPieceRotation(); //get the current tetris piece's rotation
int positions[] = board.getCurrentPieceGridPosition();
//the calculation for converting the piece to the board
int leftX = positions[0]; //get the left top x location of the piece grid
int rightX = leftX + 3; //get the right top x location of the piece grid
int topY = positions[1]; //get the top left y location of the piece grid
int bottomY = positions[1] + 3; //get the bottom left y location
//print out the instruction
System.out.println("Please enter a move (l,r,d,z,x) or type Quit to end");
//print out how many lines the player has cleared
System.out.println("Number of lines cleared: "
+ board.numberOfFormedLines());
//print out how many times did the player clear 4 lines at a time
System.out.println("Number of TetrisesScore cleared: " + board.getFourLineScore());
//print out the board and the piece
for (int i = 0; i < board.blockMatrix.length; i++) {
for (int j = 0; j < board.blockMatrix[i].length; j++) {
//check if the board has contain a block, then print out x
if (board.blockMatrix[i][j] == true) {
System.out.print("x");
} else if (i >= leftX && i <= rightX && j >= topY
&& j <= bottomY) {
//converting the piece to the board
//check if i, j are in the piece grid
if (piece.isFilled(rot, i - leftX, j - topY) == true) {
//then check the piece grid
System.out.print("*");
} else {
System.out.print(".");
}
} else {
System.out.print(".");
}
}
System.out.println();
}
}
}