Skip to content

Commit 7533ddf

Browse files
author
Mustafa Tuncay
committed
first commit
0 parents  commit 7533ddf

27 files changed

+939
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/node_modules
2+
/dist/bundle.js
3+
.DS_Store
4+
*.log
5+
.idea
6+
.vscode
7+
.cache
8+
.eslintcache
9+
package-lock.json

dist/PermanentMarker-Regular.ttf

71.9 KB
Binary file not shown.

dist/audio/newbackground.mp3

716 KB
Binary file not shown.

dist/audio/turnblock.wav

222 KB
Binary file not shown.

dist/game.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title></title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
6+
<link href="./style.css" rel="stylesheet" />
7+
</head>
8+
<body>
9+
<!-- put your html here -->
10+
<script src="bundle.js"></script>
11+
</body>
12+
</html>

dist/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title></title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
6+
<link href="./style.css" rel="stylesheet" />
7+
</head>
8+
<body class="lightBody">
9+
<h1 class="secondLine">Tetra</h1>
10+
<h1 class="thirdLine">Block !</h1>
11+
12+
<div class="buttonWrapper">
13+
<a class="" href="./game.html">Play Classic</a>
14+
</div>
15+
<div class="buttonWrapper">
16+
<a class="" href="./game.html#advancedGame">Play Advanced</a>
17+
</div>
18+
<div class="buttonWrapper">
19+
<a class="" onclick="exitFromApp()">Quit</a>
20+
</div>
21+
<script>
22+
function exitFromApp()
23+
{
24+
console.log("in button");
25+
navigator.app.exitApp();
26+
}
27+
</script>
28+
</body>
29+
</html>

dist/style.css

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
@font-face {
2+
font-family: 'PermanentMarker';
3+
src: url('./PermanentMarker-Regular.ttf'); /* IE9 Compat Modes */
4+
}
5+
6+
body {
7+
background: #202028;
8+
color: #fff;
9+
font-family: 'PermanentMarker', sans-serif;
10+
font-size: 24px;
11+
text-align: center;
12+
padding: 0px;
13+
margin: 0px;
14+
}
15+
canvas {
16+
border: solid 6px #fff;
17+
height: 90vh;
18+
}
19+
.gameOverArea {
20+
position: absolute;
21+
margin-top: 35vh;
22+
height: 30vh;
23+
z-index: 2;
24+
top: 0px;
25+
display: flex;
26+
width: 50%;
27+
text-align: center;
28+
justify-content: center;
29+
background: #333333;
30+
vertical-align: middle;
31+
align-items: center;
32+
left: 0px;
33+
right: 0px;
34+
margin-left: auto;
35+
margin-right: auto;
36+
flex-direction: column;
37+
}
38+
h1 {
39+
font-size: 54px;
40+
line-height: 54px;
41+
margin: 0px;
42+
margin-top: 20px;
43+
}
44+
45+
.lightBody {
46+
background: #E0E4CC;
47+
padding-top: 40px;
48+
}
49+
50+
.firstLine {
51+
color: #FA6900;
52+
}
53+
54+
.secondLine {
55+
color: #69D2E7;
56+
}
57+
58+
.thirdLine {
59+
color: #315267;
60+
margin-bottom: 80px;
61+
}
62+
63+
a {
64+
font-family: 'PermanentMarker', sans-serif;
65+
font-size: 36px;
66+
text-decoration: underline;
67+
color: #F38630;
68+
}
69+
70+
.buttonWrapper {
71+
width: 100%;
72+
margin-bottom: 20px;
73+
}

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "webpack-demo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack-dev-server --mode development",
8+
"build": "webpack --mode production",
9+
"test": "echo \"Error: no text specified\" && exit 1"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"devDependencies": {
15+
"ts-loader": "^6.2.2",
16+
"typescript": "^3.8.3",
17+
"webpack": "^4.42.1",
18+
"webpack-cli": "^3.3.11",
19+
"webpack-dev-server": "^3.10.3"
20+
}
21+
}

src/constants/AudioConstants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const AudioElement = document.createElement("audio");
2+
AudioElement.style.display = "none";
3+
AudioElement.setAttribute("controls", "none");
4+
AudioElement.volume = 0.05;
5+
document.body.appendChild(AudioElement);
6+
7+
export {AudioElement};
8+
export const AudioTurnBlock = './audio/turnblock.wav';
9+
export const AudioTurnBlockKey = 'turnblock';
10+
export const BackgroundSong = './audio/newbackground.mp3';

src/constants/CanvasConstants.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const CanvasWidth = 200;
2+
export const CanvasHeight = 400;
3+
export const CanvasScaleWidth = 20;
4+
export const CanvasScaleHeight = CanvasScaleWidth;
5+
export const CanvasOffsetX = 1;
6+
export const CanvasOffsetY = 1;
7+
export const CanvasWidthTile = CanvasWidth/CanvasScaleWidth;
8+
export const CanvasHeightTile = CanvasHeight/CanvasScaleHeight;
9+
10+
11+
export enum ColorEnum {
12+
black = '#fafafa',
13+
red = '#F38630',
14+
aqua = '#FA6900',
15+
blue = '#A7DBD8',
16+
orange = '#69D2E7',
17+
yellow = '#315267',
18+
green = '#DA4F26',
19+
purple = '#a026f0'
20+
}
21+
22+
export const GameColors: Array<ColorEnum> = [
23+
ColorEnum.black,
24+
ColorEnum.red,
25+
ColorEnum.aqua,
26+
ColorEnum.blue,
27+
ColorEnum.orange,
28+
ColorEnum.yellow,
29+
ColorEnum.green,
30+
ColorEnum.purple
31+
];

src/constants/GameConstants.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { PlayerModel } from "../models/PlayerModel";
2+
import { TPiece } from "./PieceContants";
3+
import { CreateMatrix } from "../helpers/CreateMatrix";
4+
import { GetRandomPiece } from "../helpers/GetRandomPiece";
5+
import { CanvasWidthTile } from "./CanvasConstants";
6+
7+
export const DropInterval = 1000;
8+
9+
export enum ArenaTile {
10+
empty = 0,
11+
fill = 1,
12+
violet = 2,
13+
blue = 3
14+
}
15+
16+
export const ArenaWidth = CanvasWidthTile;
17+
const ArenaHeight = 20;
18+
export const Arena: Array<Array<ArenaTile>> = CreateMatrix(ArenaWidth,ArenaHeight);
19+
20+
let firstPiece = GetRandomPiece();
21+
export const Player: PlayerModel = {
22+
pos: { x: Math.floor((ArenaWidth / 2)-(firstPiece.matrix.length / 2)), y: 0 },
23+
piece: firstPiece,
24+
score: 0
25+
}

src/constants/PieceContants.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { PieceModel } from "../models/PieceModel";
2+
import { ColorEnum } from "./CanvasConstants";
3+
4+
export const TPiece: PieceModel = {
5+
matrix: [
6+
[0, 7, 0],
7+
[7, 7, 7],
8+
[0, 0, 0]
9+
]
10+
}
11+
12+
export const OPiece: PieceModel = {
13+
matrix: [
14+
[5, 5],
15+
[5, 5]
16+
]
17+
}
18+
19+
export const LPiece: PieceModel = {
20+
matrix: [
21+
[0, 4, 0],
22+
[0, 4, 0],
23+
[0, 4, 4]
24+
]
25+
}
26+
27+
export const JPiece: PieceModel = {
28+
matrix: [
29+
[0, 3, 0],
30+
[0, 3, 0],
31+
[3, 3, 0]
32+
]
33+
}
34+
35+
export const IPiece: PieceModel = {
36+
matrix: [
37+
[0, 2, 0, 0],
38+
[0, 2, 0, 0],
39+
[0, 2, 0, 0],
40+
[0, 2, 0, 0]
41+
]
42+
}
43+
export const SPiece: PieceModel = {
44+
matrix: [
45+
[0, 6, 6],
46+
[6, 6, 0],
47+
[0, 0, 0]
48+
]
49+
}
50+
export const ZPiece: PieceModel = {
51+
matrix: [
52+
[1, 1, 0],
53+
[0, 1, 1],
54+
[0, 0, 0]
55+
]
56+
}
57+
58+
export const BigZPiece: PieceModel = {
59+
matrix: [
60+
[1, 1, 0],
61+
[0, 1, 0],
62+
[0, 1, 1]
63+
]
64+
}
65+
66+
export const BigSPiece: PieceModel = {
67+
matrix: [
68+
[0, 3, 3],
69+
[0, 3, 0],
70+
[3, 3, 0]
71+
]
72+
}
73+
74+
export const PlusPiece: PieceModel = {
75+
matrix: [
76+
[0, 2, 0],
77+
[2, 2, 2],
78+
[0, 2, 0]
79+
]
80+
}
81+
82+
export const MPiece: PieceModel = {
83+
matrix: [
84+
[0, 5, 5],
85+
[0, 5, 0],
86+
[0, 5, 5]
87+
]
88+
}
89+
90+
export const DotPiece: PieceModel = {
91+
matrix: [
92+
[1],
93+
]
94+
}
95+
96+
export const BigLPiece: PieceModel = {
97+
matrix: [
98+
[0, 6, 0, 0],
99+
[0, 6, 6, 0],
100+
[0, 6, 0, 0],
101+
[0, 6, 0, 0]
102+
]
103+
}
104+
105+
106+
export const BigJPiece: PieceModel = {
107+
matrix: [
108+
[0, 0, 7, 0],
109+
[0, 7, 7, 0],
110+
[0, 0, 7, 0],
111+
[0, 0, 7, 0]
112+
]
113+
}
114+
115+
const ClassicPieces: Array<PieceModel> = [TPiece, OPiece, LPiece, JPiece, IPiece, SPiece, ZPiece];
116+
const ClassicPiecesLength: number = ClassicPieces.length;
117+
118+
const AdvancedPieces: Array<PieceModel> = [TPiece, OPiece, LPiece, JPiece, IPiece, SPiece, ZPiece, BigZPiece, BigSPiece, PlusPiece, MPiece, DotPiece, BigLPiece, BigJPiece];
119+
const AdvancedPiecesLength: number = AdvancedPieces.length;
120+
121+
export const CurrentPieces: Array<PieceModel> = window.location.href.indexOf("advancedGame") !== -1 ? AdvancedPieces : ClassicPieces;
122+
export const CurrentPiecesLength: number = window.location.href.indexOf("advancedGame") !== -1 ? AdvancedPiecesLength : ClassicPiecesLength;

src/helpers/CalculateScore.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const CalculateScore = (line: number) => {
2+
let score: number = 0;
3+
switch (line) {
4+
case 2:
5+
score = 300;
6+
break;
7+
case 3:
8+
score = 500;
9+
break;
10+
case 4:
11+
score = 800;
12+
break
13+
default:
14+
score = 100;
15+
break;
16+
}
17+
return score;
18+
}

src/helpers/CreateMatrix.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ArenaTile } from "../constants/GameConstants";
2+
3+
export const CreateMatrix = function(width: number, height:number) {
4+
let matrix: Array<Array<ArenaTile>> = [];
5+
for(let i = height; i > 0; i--){
6+
matrix.push(new Array(width).fill(ArenaTile.empty));
7+
}
8+
return matrix;
9+
}

src/helpers/GameOverHelper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Player } from "../constants/GameConstants";
2+
3+
let isGameOver = false;
4+
export const GameOverHelper = () => {
5+
let divElement = document.createElement('div');
6+
divElement.classList.add('gameOverArea')
7+
divElement.innerHTML = '<h2>Game Over</h2><h3>'+Player.score+' points</h3>';
8+
document.body.appendChild(divElement);
9+
isGameOver = true;
10+
}
11+
12+
export const GetGameOverStatus = (): boolean => {
13+
return isGameOver
14+
}

0 commit comments

Comments
 (0)