当用户每次单击按钮时,我都会创建一个计数器,它会从计数器中减去 1 更新 firebase 中的节点,然后通过另一种方法使用 .valuechanges.subscribe 返回此更改,但每次发生这种情况时,它都会刷新整个页面,删除所有用户输入。
constructor(private dd: PlayerInfoProvider, private strge: Storage, private ss: Slot2machineProvider, private slotProvider: SlotProvider) {
this.slotProvider.getTries(this.dd.getCurrentUser()).valueChanges().subscribe(snapshot => this.gettries(snapshot));
}
gettries(snapshot) {
// this.playerObject = snapshot;
this.tries = snapshot;
}
runSlots() {
if (this.tries <= 0) {
alert("you cannot play anymore sorry!! but if you want you can purchase some more luck");
} else {
this.slotOne = Math.floor(Math.random() * 52) + 1;
this.slotTwo = Math.floor(Math.random() * 52) + 1;
this.slotThree = Math.floor(Math.random() * 52) + 1;
this.slotFour = Math.floor(Math.random() * 52) + 1;
this.slotFive = Math.floor(Math.random() * 52) + 1;
// this.sloty1 = '<p > "' + this.slotOne + '"</p>';
// this.sloty2 = '<p > "' + this.slotTwo + '"</p>';
// this.sloty3 = '<p > "' + this.slotThree + '"</p>';
// this.sloty4 = '<p > "' + this.slotFour + '"</p>';
// this.sloty5 = '<p > "' + this.slotFive + '"</p>';
if (this.slotOne !== this.slotTwo || this.slotTwo !== this.slotThree) {
this.loggerr = "<h2>sorry try again.. </h2>";
this.playerObject.tries = this.tries - 1;
//alert("you only have " + this.playerObject.tries + " chances left ");
// this.ss.substractTries(this.dd.getCurrentUser(), this.playerObject);
} else {
this.loggerr = "<p>jackpot!!!</p>";
}
}
}