-
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.
- Loading branch information
Showing
10 changed files
with
8,164 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,42 @@ | ||
<ion-header> | ||
<ion-navbar> | ||
<ion-title> | ||
<span class='question'>{{goodColor}}</span><span class='point'>{{point}}</span> | ||
</ion-title> | ||
</ion-navbar> | ||
</ion-header> | ||
|
||
<ion-content> | ||
<div *ngFor='let color of colors; trackBy: index;' [ngStyle]="{'background':color}" class="color" (click)="checkResponse(color)" > | ||
<img src="assets/img/response.svg" class="check-response" *ngIf='fail && color == goodColor'> | ||
</div> | ||
<div class="start-block" [hidden]="!fail"> | ||
<div class='score-container' [hidden]="bestPoint"> | ||
<div class="show-point"> | ||
<div class="circle"> | ||
<h1>{{point}}</h1> | ||
<h2>Best : {{record}}</h2> | ||
</div> | ||
</div> | ||
</div> | ||
<div class='best-score-container' [hidden]="!bestPoint"> | ||
<trophy class="trophy"></trophy> | ||
<div class="score-trophy"> | ||
{{point}} | ||
</div> | ||
</div> | ||
<div class="content-restart"> | ||
<button ion-button block (click)="goToNavPage()"> | ||
<ion-icon ios="ios-home" md="md-home"></ion-icon> | ||
</button> | ||
<button ion-button block (click)="ngOnInit()"> | ||
<ion-icon ios="ios-refresh" md="md-refresh"></ion-icon> | ||
</button> | ||
<button ion-button block (click)='shareScore();'> | ||
<ion-icon ios="ios-share" md="md-share"></ion-icon> | ||
</button> | ||
</div> | ||
|
||
</div> | ||
|
||
</ion-content> |
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,4 @@ | ||
page-initiated { | ||
@include border-difficulty($initiated-color-secondary); | ||
@include toolbar-border($initiated-color-secondary); | ||
} |
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,143 @@ | ||
import { Component } from '@angular/core'; | ||
import { NavController, NavParams } from 'ionic-angular'; | ||
import { ShareService} from '../../providers/share-service'; | ||
import { Storage } from '@ionic/storage'; | ||
|
||
|
||
@Component({ | ||
selector: 'page-initiated', | ||
templateUrl: 'initiated.html' | ||
}) | ||
export class InitiatedPage { | ||
constructor(public navCtrl: NavController, public navParams: NavParams, private shareService: ShareService, private storage: Storage) { | ||
} | ||
|
||
readonly possible: Array<string> = [ | ||
"red","yellow","green","blue","brown","grey" | ||
]; | ||
readonly red: Array<string> = [ | ||
"LightSalmon","DarkSalmon","LightCoral","IndianRed","Crimson","Red","FireBrick","DarkRed" | ||
]; | ||
readonly yellow: Array<string> = [ | ||
"Gold","Yellow","LightYellow","LemonChiffon","PapayaWhip","Moccasin","PaleGoldenRod","Khaki","DarkKhaki" | ||
]; | ||
readonly green: Array<string> = [ | ||
"GreenYellow","Chartreuse","LimeGreen","Lime","PaleGreen","SpringGreen","SeaGreen","Green","ForestGreen","YellowGreen","Olive" | ||
]; | ||
readonly blue: Array<string> = [ | ||
"Cyan","Aquamarine","Turquoise","SteelBlue","CadetBlue","SkyBlue","RoyalBlue","Blue","Navy" | ||
]; | ||
readonly brown: Array<string> = [ | ||
"BurlyWood","GoldenRod","Chocolate","SaddleBrown","Brown","Maroon","Sienna","SandyBrown","DarkGoldenRod" | ||
]; | ||
readonly grey: Array<string> = [ | ||
"Gainsboro","Silver","DarkGray","DimGray","Gray","SlateGray","DarkSlateGray","Black" | ||
]; | ||
readonly purple: Array<string> = [ | ||
"Orchid","Fuchsia","DarkOrchid","BlueViolet","Purple","MediumPurple","MediumSlateBlue","DarkSlateBlue","Indigo" | ||
]; | ||
|
||
colorType: string = ""; | ||
point: number = 0; | ||
bestPoint: boolean; | ||
readonly nbColors: number[] = [2, 4, 6]; | ||
difficulty: number = 0; | ||
goodColor: string = ""; | ||
colors: Array<string> = []; | ||
fail: number = 0; | ||
record: number; | ||
|
||
getRandomInt(min: number, max: number): number { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
|
||
generateColorCode(type): string { | ||
switch(type) { | ||
case "red": { | ||
return this.red[this.getRandomInt(0, this.red.length - 1)]; | ||
} | ||
case "blue": { | ||
return this.blue[this.getRandomInt(0, this.blue.length - 1)]; | ||
} | ||
case "yellow": { | ||
return this.yellow[this.getRandomInt(0, this.yellow.length - 1)]; | ||
} | ||
case "brown": { | ||
return this.brown[this.getRandomInt(0, this.brown.length - 1)]; | ||
} | ||
case "green": { | ||
return this.green[this.getRandomInt(0, this.green.length - 1)]; | ||
} | ||
case "grey": { | ||
return this.grey[this.getRandomInt(0, this.grey.length - 1)]; | ||
} | ||
} | ||
} | ||
|
||
setDifficulty(): number { | ||
if (this.point === 0 && this.point < 5) return this.difficulty = 0; | ||
if (this.point >= 5 && this.point < 10) return this.difficulty = 1; | ||
if (this.point >= 10) return this.difficulty = 2; | ||
} | ||
checkResponse(userChoice: string): void { | ||
if(userChoice != this.goodColor){ | ||
this.wrongResponse(); | ||
return; | ||
} | ||
this.point++; | ||
this.ngOnInit(); | ||
} | ||
wrongResponse(): void { | ||
this.fail = 1; | ||
this.defineBestScore(); | ||
} | ||
isColorAlreadyChoose(obj: string): boolean { | ||
if (this.colors.indexOf(obj) !== -1) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
defineBestScore(): void { | ||
this.storage.get('bestScoreInitiated').then((val) => { | ||
if (val == null || this.point > val) { | ||
this.storage.set('bestScoreInitiated', this.point); | ||
this.bestPoint = true; | ||
} | ||
this.record = val; | ||
}); | ||
} | ||
reset(): void { | ||
this.point = 0; | ||
this.fail = 0; | ||
this.bestPoint = false; | ||
} | ||
shareScore(): void { | ||
this.shareService.shareScreenshot(); | ||
} | ||
ngOnInit(): void { | ||
if(this.fail === 1) this.reset(); | ||
|
||
this.colors = []; | ||
this.setDifficulty(); | ||
|
||
let nb_color: number = this.nbColors[this.difficulty]; | ||
let color: string = ""; | ||
|
||
this.colorType = this.possible[this.getRandomInt(0, this.possible.length - 1)]; | ||
for(let k:number = 1 ; k <= nb_color; k++){ | ||
do | ||
{ | ||
color = this.generateColorCode(this.colorType); | ||
} while(this.isColorAlreadyChoose(color) === true) | ||
this.colors.push(color); | ||
} | ||
this.goodColor = this.colors[Math.floor(Math.random() * this.colors.length)]; | ||
} | ||
goToNavPage(): void { | ||
this.navCtrl.pop() | ||
} | ||
ionViewWillLeave(): void { | ||
this.navParams.get("parentPage").ngOnInit(); | ||
} | ||
} |
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