Skip to content

Commit

Permalink
improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
tolbon committed Oct 5, 2017
1 parent 581c26a commit 38dba09
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 84 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"devDependencies": {
"@ionic/app-scripts": "2.1.3",
"@ionic/cli-plugin-ionic-angular": "1.4.1",
"@types/angular": "^1.6.32",
"@types/ionic": "0.0.35",
"ionic": "3.10.3",
"typescript": "2.3.4"
},
Expand Down
41 changes: 22 additions & 19 deletions src/pages/easy/easy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,60 @@ export class EasyPage {
constructor(public navCtrl: NavController, public navParams: NavParams, private shareService: ShareService, private storage: Storage) {
}

possible: Array<any> = [
possible: Array<string> = [
"AliceBlue","Aqua","Aquamarine","Azure","Beige","Black","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","DarkOrange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Grey","Green","GreenYellow","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGrey","LightGreen","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGrey","LightSteelBlue","LightYellow","LimeGreen","Magenta","Maroon","MidnightBlue","Olive","Orange","OrangeRed","Orchid","PaleGreen","PaleTurquoise","PaleVioletRed","Pink","Purple","Red","RoyalBlue","SaddleBrown","Salmon","SeaGreen","Silver","SkyBlue","Snow","SpringGreen","SteelBlue","Teal","Tomato","Turquoise","Violet","White","WhiteSmoke","Yellow","YellowGreen"
];
point: number = 0;
bestPoint: boolean;
nbColors: number[] = [2, 4, 6, 8];
difficulty: number = 0;
hexa: string = "#";
goodColor: string ="";
goodColor: string = "";
color: string;
colors: Array<any> = [];
colors: Array<string> = [];
fail: number = 0;
testcolor: boolean;
record: number;

i: number = 0;
k: number = 1;

getRandomInt(min, max) {
getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

generateColorCode(){
generateColorCode(): string {
this.color = this.possible[this.getRandomInt(0, this.possible.length - 1)];
return this.color;
}

setDifficulty(){
if (this.point == 0 && this.point < 5) return this.difficulty = 0;
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 && this.point < 15) return this.difficulty = 2;
if (this.point >= 15) return this.difficulty = 3;
}
checkResponse(userChoice){
if(userChoice != this.goodColor) return this.wrongResponse();
checkResponse(userChoice: string): void {
if(userChoice != this.goodColor){
this.wrongResponse();
return;
}
this.point++;
this.ngOnInit();
}
wrongResponse(){
wrongResponse(): void {
this.fail = 1;
this.defineBestScore();
}
checkColorArray(obj){
checkColorArray(obj: string): void {
for(let i = 0; i<=this.colors.length; i++) {
if (this.colors[i] == obj){
this.color = this.generateColorCode();
this.checkColorArray(this.color);
}
}
}
defineBestScore(){
defineBestScore(): void {
this.storage.get('bestScoreEasy').then((val) => {
if (val == null || this.point > val) {
this.storage.set('bestScoreEasy', this.point);
Expand All @@ -71,21 +74,21 @@ export class EasyPage {
this.record = val;
});
}
reset(){
reset(): void {
this.point = 0;
this.fail = 0;
this.bestPoint = false;
}
shareScore(){
shareScore(): void {
this.shareService.shareScreenshot();
}
ngOnInit(){
if(this.fail == 1) this.reset();
ngOnInit(): void {
if(this.fail === 1) this.reset();

this.colors = [];
this.setDifficulty();

for(this.k=1 ; this.k <= this.nbColors[this.difficulty] ; this.k++){
for(this.k = 1 ; this.k <= this.nbColors[this.difficulty] ; this.k++){

this.color = this.generateColorCode();
this.checkColorArray(this.color);
Expand All @@ -96,10 +99,10 @@ export class EasyPage {
}
this.goodColor = this.colors[Math.floor(Math.random() * this.colors.length)];
}
goToNavPage() {
goToNavPage(): void {
this.navCtrl.pop()
}
ionViewWillLeave() {
ionViewWillLeave(): void {
this.navParams.get("parentPage").ngOnInit();
}
}
57 changes: 29 additions & 28 deletions src/pages/hard/hard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,45 @@ export class HardPage {
nbColors: number[] = [2, 4, 6];
difficulty: number = 0;
hexa: string = "#";
goodColor: string ="";
color: string;
colors: Array<any> = [];
goodColor: string = "";
colors: Array<string> = [];
fail: number = 0;
record: number;


i: number = 0;
k: number = 1;

getRandomInt(min, max) {
getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

generateColorCode(){
this.i = 0;
this.hexa = "#";
for( this.i=1 ; this.i <= 6 ; this.i++){
var randomInt = this.getRandomInt(0, this.possible.length - 1);
this.hexa += this.possible[randomInt];
generateColorCode(): string {
let hexa: string = "#";
let len: number = this.possible.length - 1;

for(let i: number = 1 ; i <= 6 ; i++){
let randomInt: number = this.getRandomInt(0, len);
hexa += this.possible[randomInt];
}
return this.hexa;
return hexa;
}

setDifficulty(){
if (this.point == 0 && this.point < 5) return this.difficulty = 0;
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){
if(userChoice != this.goodColor) return this.wrongResponse();
checkResponse(userChoice: string): void{
if(userChoice != this.goodColor)
{
this.wrongResponse();
return;
}
this.point++;
this.ngOnInit();
}
wrongResponse(){
wrongResponse(): void {
this.fail = 1;
this.defineBestScore();
}
defineBestScore(){
defineBestScore(): void {
this.storage.get('bestScoreHard').then((val) => {
if (val == null || this.point > val) {
this.storage.set('bestScoreHard', this.point);
Expand All @@ -63,23 +63,24 @@ export class HardPage {
this.record = val;
});
}
reset(){
reset(): void {
this.point = 0;
this.fail = 0;
this.bestPoint = false;
}
shareScore(){
shareScore(): void {
this.shareService.shareScreenshot();
}
ngOnInit(){
if(this.fail == 1) this.reset();
ngOnInit(): void {
if(this.fail === 1) this.reset();

this.colors = [];
this.setDifficulty();

for(this.k=1 ; this.k <= this.nbColors[this.difficulty] ; this.k++){
this.color = this.generateColorCode();
this.colors.push(this.color);
let color:string = "";
for(let k:number = 1 ; k <= this.nbColors[this.difficulty] ; k++){
color = this.generateColorCode();
this.colors.push(color);
}
this.goodColor = this.colors[Math.floor(Math.random() * this.colors.length)];
}
Expand Down
26 changes: 13 additions & 13 deletions src/pages/nav/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ export class NavPage {
recordNormal: number;
recordHard: number;

toggleHelp(difficulty){
toggleHelp(difficulty: string){
switch(difficulty) {
case "easy": {
this.helpEasy = (this.helpEasy == false) ? true : false;
this.helpEasy = !this.helpEasy;
break;
}
case "normal": {
this.helpNormal = (this.helpNormal == false) ? true : false;
this.helpNormal = !this.helpNormal;
break;
}
case "hard": {
this.helpHard = (this.helpHard == false) ? true : false;
this.helpHard = !this.helpHard;
break;
}
case "doom": {
this.helpDoom = (this.helpDoom == false) ? true : false;
this.helpDoom = !this.helpDoom;
break;
}
}
}

getBestScore() {
this.storage.get('bestScoreEasy').then((val) => {
getBestScore(): void {
this.storage.get('bestScoreEasy').then((val: number) => {
this.recordEasy = val;
});
this.storage.get('bestScoreNormal').then((val) => {
this.storage.get('bestScoreNormal').then((val: number) => {
this.recordNormal = val;
});
this.storage.get('bestScoreHard').then((val) => {
this.storage.get('bestScoreHard').then((val: number) => {
this.recordHard = val;
});
}
Expand All @@ -65,17 +65,17 @@ export class NavPage {
this.slides.slideTo(2, 500);
}

goToEasyPage() {
goToEasyPage(): void {
this.navCtrl.push(EasyPage, { "parentPage": this });
}
goToNormalPage() {
goToNormalPage(): void {
this.navCtrl.push(NormalPage, { "parentPage": this });
}
goToHardPage() {
goToHardPage(): void {
this.navCtrl.push(HardPage, { "parentPage": this });
}

ngOnInit(){
ngOnInit(): void {
this.getBestScore();
}
}
Loading

0 comments on commit 38dba09

Please sign in to comment.