This server is intended for use for Academic Classwork related Git repositories only. Projects/repositories will generally be removed after 6 months following close of the semester. Inactive repositories from previous semester are now being archived when no activity for 365 days. They are renamed and marked as 'archived'. After 90 days in that state they will be removed from the system completely.

Commit a8bbd5dd authored by Pamela Petterchak's avatar Pamela Petterchak

implementing service

parent 37bc6b41
import { Component } from '@angular/core';
import { GamePlayService } from '../game-play.service';
@Component({
selector: 'app-accumulators',
......@@ -7,24 +8,24 @@ import { Component } from '@angular/core';
})
export class AccumulatorsComponent {
// Not correct yet - need to figure out how to communicate btw click and accumulator
totalClicks = 0;
clickMulti = 1;
readonly totalClicks = this.service.pickleCount;
readonly clickMulti = this.service.incrementVal;
constructor() {}
constructor(private service: GamePlayService) {}
jarUpgrade() {
this.clickMulti += 5;
this.service.jarUpgrade().catch((err) => console.log(err));
}
barrelUpgrade() {
this.clickMulti += 50;
this.service.barrelUpgrade().catch((err) => console.log(err));
}
siloUpgrade() {
this.clickMulti += 500;
this.service.siloUpgrade().catch((err) => console.log(err));
}
reservoirUpgrade() {
this.clickMulti += 5000;
this.service.reservoirUpgrade().catch((err) => console.log(err));
}
}
<button mat-raised-button>
<img src="assets/pickle-fingers.png" (click)="increment()" />
</button>
<h4># of Clicks: {{ totalClicks }}</h4>
<h4># of Clicks: {{ totalClicks | async }}</h4>
import { Component } from '@angular/core';
import { GamePlayService } from '../game-play.service';
@Component({
selector: 'app-click',
......@@ -6,28 +7,12 @@ import { Component } from '@angular/core';
styleUrls: ['./click.component.scss'],
})
export class ClickComponent {
totalClicks = 0;
clickMulti = 1;
readonly totalClicks = this.service.pickleCount;
readonly clickMulti = this.service.incrementVal;
constructor() {}
constructor(private service: GamePlayService) {}
increment() {
this.totalClicks += this.clickMulti;
}
jarUpgrade() {
this.clickMulti += 5;
}
barrelUpgrade() {
this.clickMulti += 50;
}
siloUpgrade() {
this.clickMulti += 500;
}
reservoirUpgrade() {
this.clickMulti += 5000;
this.service.increment().catch((err) => console.log(err));
}
}
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class GamePlayService {
// There are various ways to achieve an Observable that emits a
// current value on subscribe; this is one of the more common.
private readonly pickles = new BehaviorSubject<number>(0);
readonly pickleCount = this.pickles.asObservable();
private readonly increments = new BehaviorSubject<number>(1);
readonly incrementVal = this.increments.asObservable();
constructor() {
console.log('Game service activated');
}
async increment() {
this.pickles.next(this.pickles.value + this.increments.value);
}
async jarUpgrade() {
this.increments.next(this.increments.value + 5);
this.pickles.next(this.pickles.value - 5);
}
async barrelUpgrade() {
this.increments.next(this.increments.value + 50);
this.pickles.next(this.pickles.value - 50);
}
async siloUpgrade() {
this.increments.next(this.increments.value + 500);
this.pickles.next(this.pickles.value - 500);
}
async reservoirUpgrade() {
this.increments.next(this.increments.value + 5000);
this.pickles.next(this.pickles.value - 500);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment