-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added Snake Game Component * added models removed my img * update packages, snake game updated * snake game updated to working added svg to footer * renamed fames to games
- Loading branch information
Showing
26 changed files
with
361 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,54 @@ | ||
.center{ | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: flex; | ||
max-width: 40%; | ||
filter: none; | ||
-webkit-filter:none; | ||
.center { | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: flex; | ||
max-width: 40%; | ||
filter: none; | ||
-webkit-filter: none; | ||
} | ||
|
||
.bg-image { | ||
/* The image used */ | ||
background-image: url("../assets/Zahid_nidhan.JPG"); | ||
|
||
/* Add the blur effect */ | ||
filter: blur(8px); | ||
-webkit-filter: blur(8px); | ||
|
||
/* Full height */ | ||
height: 100%; | ||
|
||
/* Center and scale the image nicely */ | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
} | ||
.bg-text { | ||
background-color: rgb(0,0,0); /* Fallback color */ | ||
background-color: rgba(0,0,0, 0.4); /* Black w/opacity/see-through */ | ||
color: white; | ||
font-weight: bold; | ||
border: 3px solid #f1f1f1; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
z-index: 2; | ||
width: 80%; | ||
padding: 20px; | ||
text-align: center; | ||
} | ||
.connect{ | ||
color: white; | ||
font-weight: bold; | ||
border: 3px solid #000; | ||
background-color: blue; | ||
position: absolute; | ||
} | ||
/* The image used */ | ||
/* background-image: url("../assets/Zahid_nidhan.JPG"); */ | ||
|
||
/* Add the blur effect */ | ||
filter: blur(8px); | ||
-webkit-filter: blur(8px); | ||
|
||
/* Full height */ | ||
height: 100%; | ||
|
||
/* Center and scale the image nicely */ | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
} | ||
|
||
.bg-text { | ||
background-color: rgb(0, 0, 0); | ||
/* Fallback color */ | ||
background-color: rgba(0, 0, 0, 0.4); | ||
/* Black w/opacity/see-through */ | ||
color: white; | ||
font-weight: bold; | ||
border: 3px solid #f1f1f1; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
z-index: 2; | ||
width: 80%; | ||
padding: 20px; | ||
text-align: center; | ||
} | ||
|
||
.connect { | ||
color: white; | ||
font-weight: bold; | ||
border: 3px solid #000; | ||
background-color: blue; | ||
position: absolute; | ||
} | ||
|
||
#body{ | ||
overflow: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<app-navbar></app-navbar> | ||
<router-outlet></router-outlet> | ||
<div id="body" class="container"> | ||
<router-outlet></router-outlet> | ||
</div> | ||
<app-footer></app-footer> |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
<p>games works!</p> | ||
<div id="games" class="container grid-container space-up text-center"> | ||
<div *ngFor="let game of games" class="grid-item"> | ||
<div class="card" style="width:400px"> | ||
<img class="card-img-top" src={{game.image}} alt="Game image"> | ||
<div class="card-body"> | ||
<h4 class="card-title">{{game.title}}</h4> | ||
<p class="card-text">{{game.description}}</p> | ||
<a routerLink={{game.link}} class="btn btn-primary">Play</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
interface ICell { | ||
x: number; | ||
y: number; | ||
color: string; | ||
} | ||
|
||
export class Cell { | ||
x: number = 0; | ||
y: number = 0; | ||
color: string = "yellow"; | ||
constructor(obj?: ICell) { | ||
if (obj) { | ||
this.color = obj.color; | ||
this.x = obj.x; | ||
this.y = obj.y; | ||
} | ||
} | ||
|
||
setNextRandomCell(W:number, H:number){ | ||
this.x = Math.round(Math.random()*(W-10)/20); | ||
this.y = Math.round(Math.random()*(H-10)/20); | ||
|
||
var colors = ["red","green","aqua","coral","orchid"]; | ||
this.color = colors[Math.round(Math.random() * colors.length)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface IGame{ | ||
title:string; | ||
description:string; | ||
image:string; | ||
link:string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Cell } from "./cell"; | ||
import { IStats } from "./stats"; | ||
|
||
export class Snake { | ||
init_length: number = 5; | ||
cells: Cell[] = []; | ||
direction: string = "down"; | ||
|
||
createSnake(canvasWidth: number): void { | ||
for (var i = this.init_length - 1; i >= 0; i--) { | ||
this.cells.push(new Cell({ x: canvasWidth / 20, y: i, color: "yellow" })); | ||
} | ||
} | ||
|
||
drawSnake(pen: any): void { | ||
for (var i = 0; i < this.cells.length; i++) { | ||
pen.fillStyle = this.cells[i].color; | ||
pen.strokeStyle = "black"; | ||
pen.lineWidth = 5; | ||
pen.strokeRect(this.cells[i].x * 10, this.cells[i].y * 10, 10, 10); | ||
pen.fillRect(this.cells[i].x * 10, this.cells[i].y * 10, 10, 10); | ||
} | ||
} | ||
|
||
updateSnake(obj: IStats): IStats { | ||
var headX = this.cells[0].x; | ||
var headY = this.cells[0].y; | ||
|
||
//if food strikes with snake | ||
for (var i = 1; i < this.cells.length; i++) { | ||
if (this.cells[i].x == headX && this.cells[i].y == headY) { | ||
obj.gameOver = true; | ||
} | ||
} | ||
|
||
if (headX == obj.food.x && headY == obj.food.y) { | ||
obj.score++; | ||
this.cells[0].color = obj.food.color; | ||
obj.food.setNextRandomCell(obj.canvasWidth, obj.canvasHeight); | ||
if (obj.score > obj.highScore) { | ||
obj.highScore = obj.score; | ||
} | ||
} | ||
else { | ||
//if food not taken; | ||
this.cells.pop(); | ||
} | ||
|
||
var nextX: number = 0; | ||
var nextY: number = 0; | ||
switch (this.direction) { | ||
case "right": { | ||
nextX = headX + 1; | ||
nextY = headY; | ||
break; | ||
} | ||
|
||
case "left": { | ||
nextX = headX - 1; | ||
nextY = headY; | ||
break; | ||
} | ||
|
||
case "down": { | ||
nextX = headX; | ||
nextY = headY + 1; | ||
break; | ||
} | ||
|
||
case "up": { | ||
nextX = headX; | ||
nextY = headY - 1; | ||
break; | ||
} | ||
|
||
} | ||
|
||
//insert the new cell at head | ||
this.cells.unshift(new Cell({ x: nextX, y: nextY, color: "yellow" })); | ||
|
||
//last coordinates condition | ||
var last_x = Math.round(obj.canvasWidth / 10); | ||
var last_y = Math.round(obj.canvasHeight / 10); | ||
|
||
if (this.cells[0].y < 0 || this.cells[0].x > last_x || this.cells[0].x < 0 || this.cells[0].y > last_y) { | ||
obj.gameOver = true; | ||
} | ||
return obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Cell } from "./cell"; | ||
|
||
export interface IStats { | ||
gameOver: boolean; | ||
canvasWidth: number; | ||
canvasHeight: number; | ||
food: Cell; | ||
score: number; | ||
highScore: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
canvas{ | ||
background-color: black; | ||
} | ||
|
||
#snake-game{ | ||
position: fixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div id="snake-game" class="container text-center space-up"> | ||
<canvas width="400" height="400" id="canvas" ></canvas> | ||
</div> |
12 changes: 6 additions & 6 deletions
12
src/app/games/game/game.component.spec.ts → ...s/snake-game/snake-game.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.