Compare commits
No commits in common. "b29973189f092c42c40a7a51caf908a1af3d79ce" and "e5bde81964329cf0c5b2e3a8b5190742f84a256b" have entirely different histories.
b29973189f
...
e5bde81964
2 changed files with 7 additions and 81 deletions
|
|
@ -4,32 +4,6 @@ import Tetromino from "./Tetromino";
|
||||||
|
|
||||||
export default class GameLogic {
|
export default class GameLogic {
|
||||||
|
|
||||||
static levelTicks = {
|
|
||||||
'1': 1000,
|
|
||||||
'2': 900,
|
|
||||||
'3': 800,
|
|
||||||
'4': 700,
|
|
||||||
'5': 600,
|
|
||||||
'6': 500,
|
|
||||||
'7': 400,
|
|
||||||
'8': 300,
|
|
||||||
'9': 200,
|
|
||||||
'10': 150,
|
|
||||||
};
|
|
||||||
|
|
||||||
static levelThresholds = {
|
|
||||||
'1': 100,
|
|
||||||
'2': 300,
|
|
||||||
'3': 500,
|
|
||||||
'4': 700,
|
|
||||||
'5': 1000,
|
|
||||||
'7': 1500,
|
|
||||||
'8': 2000,
|
|
||||||
'9': 3000,
|
|
||||||
'10': 4000,
|
|
||||||
'11': 5000,
|
|
||||||
};
|
|
||||||
|
|
||||||
currentGrid: Array<Array<Object>>;
|
currentGrid: Array<Array<Object>>;
|
||||||
|
|
||||||
height: number;
|
height: number;
|
||||||
|
|
@ -39,7 +13,6 @@ export default class GameLogic {
|
||||||
gamePaused: boolean;
|
gamePaused: boolean;
|
||||||
gameTime: number;
|
gameTime: number;
|
||||||
score: number;
|
score: number;
|
||||||
level: number;
|
|
||||||
|
|
||||||
currentObject: Tetromino;
|
currentObject: Tetromino;
|
||||||
|
|
||||||
|
|
@ -58,6 +31,7 @@ export default class GameLogic {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.gameRunning = false;
|
this.gameRunning = false;
|
||||||
this.gamePaused = false;
|
this.gamePaused = false;
|
||||||
|
this.gameTick = 250;
|
||||||
this.colors = colors;
|
this.colors = colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,21 +165,9 @@ export default class GameLogic {
|
||||||
this.currentObject.rotate(false);
|
this.currentObject.rotate(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
setNewGameTick(level: number) {
|
|
||||||
if (level > 10)
|
|
||||||
return;
|
|
||||||
this.gameTick = GameLogic.levelTicks[level];
|
|
||||||
clearInterval(this.gameTickInterval);
|
|
||||||
this.gameTickInterval = setInterval(this.onTick, this.gameTick);
|
|
||||||
}
|
|
||||||
|
|
||||||
onTick(callback: Function) {
|
onTick(callback: Function) {
|
||||||
this.tryMoveTetromino(0, 1);
|
this.tryMoveTetromino(0, 1);
|
||||||
callback(this.score, this.level, this.getFinalGrid());
|
callback(this.score, this.getFinalGrid());
|
||||||
if (this.level <= 10 && this.score > GameLogic.levelThresholds[this.level]) {
|
|
||||||
this.level++;
|
|
||||||
this.setNewGameTick(this.level);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onClock(callback: Function) {
|
onClock(callback: Function) {
|
||||||
|
|
@ -286,11 +248,9 @@ export default class GameLogic {
|
||||||
this.gamePaused = false;
|
this.gamePaused = false;
|
||||||
this.gameTime = 0;
|
this.gameTime = 0;
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
this.level = 1;
|
|
||||||
this.gameTick = GameLogic.levelTicks[this.level];
|
|
||||||
this.currentGrid = this.getEmptyGrid();
|
this.currentGrid = this.getEmptyGrid();
|
||||||
this.createTetromino();
|
this.createTetromino();
|
||||||
tickCallback(this.score, this.level, this.getFinalGrid());
|
tickCallback(this.score, this.getFinalGrid());
|
||||||
clockCallback(this.gameTime);
|
clockCallback(this.gameTime);
|
||||||
this.onTick = this.onTick.bind(this, tickCallback);
|
this.onTick = this.onTick.bind(this, tickCallback);
|
||||||
this.onClock = this.onClock.bind(this, clockCallback);
|
this.onClock = this.onClock.bind(this, clockCallback);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ type State = {
|
||||||
grid: Array<Array<Object>>,
|
grid: Array<Array<Object>>,
|
||||||
gameRunning: boolean,
|
gameRunning: boolean,
|
||||||
gameTime: number,
|
gameTime: number,
|
||||||
gameScore: number,
|
gameScore: number
|
||||||
gameLevel: number,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TetrisScreen extends React.Component<Props, State> {
|
class TetrisScreen extends React.Component<Props, State> {
|
||||||
|
|
@ -40,7 +39,6 @@ class TetrisScreen extends React.Component<Props, State> {
|
||||||
gameRunning: false,
|
gameRunning: false,
|
||||||
gameTime: 0,
|
gameTime: 0,
|
||||||
gameScore: 0,
|
gameScore: 0,
|
||||||
gameLevel: 0,
|
|
||||||
};
|
};
|
||||||
this.onTick = this.onTick.bind(this);
|
this.onTick = this.onTick.bind(this);
|
||||||
this.onClock = this.onClock.bind(this);
|
this.onClock = this.onClock.bind(this);
|
||||||
|
|
@ -85,26 +83,9 @@ class TetrisScreen extends React.Component<Props, State> {
|
||||||
this.showPausePopup();
|
this.showPausePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormattedTime(seconds: number) {
|
onTick(score: number, newGrid: Array<Array<Object>>) {
|
||||||
let date = new Date();
|
|
||||||
date.setHours(0);
|
|
||||||
date.setMinutes(0);
|
|
||||||
date.setSeconds(seconds);
|
|
||||||
let format;
|
|
||||||
console.log(date);
|
|
||||||
if (date.getHours())
|
|
||||||
format = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
|
|
||||||
else if (date.getMinutes())
|
|
||||||
format = date.getMinutes() + ':' + date.getSeconds();
|
|
||||||
else
|
|
||||||
format = date.getSeconds();
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
onTick(score: number, level: number, newGrid: Array<Array<Object>>) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
gameScore: score,
|
gameScore: score,
|
||||||
gameLevel: level,
|
|
||||||
grid: newGrid,
|
grid: newGrid,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -160,8 +141,7 @@ class TetrisScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
showGameOverConfirm() {
|
showGameOverConfirm() {
|
||||||
let message = 'SCORE: ' + this.state.gameScore + '\n';
|
let message = 'SCORE: ' + this.state.gameScore + '\n';
|
||||||
message += 'LEVEL: ' + this.state.gameLevel + '\n';
|
message += 'TIME: ' + this.state.gameTime + '\n';
|
||||||
message += 'TIME: ' + this.getFormattedTime(this.state.gameTime) + '\n';
|
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
'GAME OVER',
|
'GAME OVER',
|
||||||
message,
|
message,
|
||||||
|
|
@ -209,21 +189,7 @@ class TetrisScreen extends React.Component<Props, State> {
|
||||||
<Text style={{
|
<Text style={{
|
||||||
marginLeft: 5,
|
marginLeft: 5,
|
||||||
color: this.colors.subtitle
|
color: this.colors.subtitle
|
||||||
}}>{this.getFormattedTime(this.state.gameTime)}</Text>
|
}}>{this.state.gameTime}</Text>
|
||||||
</View>
|
|
||||||
<View style={{
|
|
||||||
flexDirection: 'row',
|
|
||||||
position: 'absolute',
|
|
||||||
top: 50,
|
|
||||||
left: 10,
|
|
||||||
}}>
|
|
||||||
<MaterialCommunityIcons
|
|
||||||
name={'gamepad'}
|
|
||||||
color={this.colors.text}
|
|
||||||
size={20}/>
|
|
||||||
<Text style={{
|
|
||||||
marginLeft: 5
|
|
||||||
}}>{this.state.gameLevel}</Text>
|
|
||||||
</View>
|
</View>
|
||||||
<View style={{
|
<View style={{
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue