I have very limited knowledge on APIs and this is also my first time creating a randomiser for games. I am trying to come up with a game where the user will have to pick from one of the 3 buttons to win a prize that is stored in the inventory. However, this game will be randomized and only randomly selected users picked by the randomizer can win. The prizes they will be winning will be randomly picked as well.
Basically, each time the user clicks on any of the 3 buttons, the randomizer will determine if the user will win the prize or not. The user can only click on the buttons once per day.
- If the user wins, we will then call the API to get the list of inventory data and randomly select an item from that API. The selected item will then be displayed on another page.
- If the user doesn’t win, we will then display an alert message to the user.
Regardless of whether the user wins/lose, we will then post the data to the API.
Currently, I have a 3 APIS that I need to use:
- API to get the list of available users
Provider
getStaff(){
return this.http.get(`${this.staffApiUrl}//some api,
{headers: new HttpHeaders().set('X-XSRF-TOKEN', this.getCookie('XSRF-TOKEN'))});
}
.ts of the page
constructor(public navCtrl: NavController, private alertCtrl: AlertController, private christmasProvider: ChristmasProvider) {
this.christmasProvider.getStaff().pipe(
map((staffResult: StaffRecords) => staffResult && staffResult.records)
).subscribe(staffed => {
if (staffed){
this.staff = staffed;
console.log(this.staff);
}
});}
- API to get the list of inventory data
Provider
getInventory(){
return this.http.get(`${this.dataApiUrl}//some api,
{ headers: new HttpHeaders().set('X-XSRF-TOKEN', this.getCookie('XSRF-TOKEN'))});
}
- API to post the results after the user has clicked on any of the 3 buttons
Provider
getSpin(){
return this.http.get(`${this.dataApiUrl}//some api,
{ headers: new HttpHeaders().set('X-XSRF-TOKEN', this.getCookie('XSRF-TOKEN'))});
}
My problem now is that I do not know how to come up with a randomizer to pick the user and the prize for the users that win with the APIs I have. I think I might be able to work something out from there once I have an idea of how to come up with a randomizer. I would gladly appreciate if anyone can help me. Thanks!