-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveTetris.h
96 lines (82 loc) · 2.02 KB
/
MoveTetris.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// MoveTetris.h
// Tetris
//
// Created by Jose Manuel Tapia Avitia on 13/12/17.
// Copyright (c) 2017 Jose Manuel Tapia Avitia. All rights reserved.
//
#ifndef Tetris_MoveTetris_h
#define Tetris_MoveTetris_h
#include "IOFunction.h"
using namespace std;
#define pb(x) push_back(x)
bool posible(Piece A, int x,int y){
int i,j,L=(int)A.P.size();
for(i=0;i<L;i++)for(j=0;j<L;j++){
if(A.P[i][j])
if(i+x>=Height||j+y>=Width||i+x<0||j+y<0||board[i+x][j+y])
return false;
}
return true;
}
void changePiece(Piece A,int x,int y,int v){
int i,j,L=(int)A.P.size();
for(i=0;i<L;i++)for(j=0;j<L;j++)
if(A.P[i][j])board[i+x][j+y]=v;
}
void deleteLine(int l){
int i,j;
for(i=l;i>0;i--)for(j=0;j<Width;j++)
board[i][j]=board[i-1][j];
}
int deleteMultipleLines(){
int i,j,complete,microScore=0;
for(i=0;i<Height;i++){
complete=1;
for(j=0;j<Width;j++)
if(!board[i][j])complete=0;
if(complete)deleteLine(i),microScore++;
}
return microScore;
}
bool doMove(Piece &W,int &x,int &y,int movei){
Piece Wi;
//Do the move
changePiece(W,x,y,0);
switch(movei){
case 0:
if(posible(W,x,y-1))y--;
changePiece(W,x,y,2);
break;
case 1:
if(posible(W,x,y+1))y++;
changePiece(W,x,y,2);
break;
case 2:
Wi=rotateL(W);
if(posible(Wi,x,y))W=Wi;
changePiece(W,x,y,2);
break;
case 3:
Wi=rotateR(W);
if(posible(Wi,x,y))W=Wi;
changePiece(W,x,y,2);
break;
case 4:
while(posible(W,x+1,y))x++;
changePiece(W,x,y,2);
break;
default:
if(posible(W,x+1,y))
changePiece(W,++x,y,2);
else {
changePiece(W,x,y,1);
return false;
}
break;
}
clearScreen();
printBoard();
return true;
}
#endif