https://github.com/firedreamgames/rock_scissors_paper_STEEM
RSP game is the standart Rock-Scissors-Paper game played on Steem blockchain.
The basic rules are standart:
The player makes a choice and a bid of 0.1SBD is transferred to game AI.
The transfer is done via Steemconnect so it is safe.
Since no key ( WIF ) is stored, every bid needs to be verified by steemconnect.
The AI choice is determined according to the unique transaction ID generated by this transfer.
The AI choice rules are clearly defined as follows :
The transaction ID is a hexadecimal number, so there are 16 choices.
To make the game equal chance, if the transaction ends with "0" it is considered as null and 90% of the bid is returned.
The winning conditions are as follows :
Go to the game website : https://rspgame.neocities.org/
Enter your UserName and press UserName button
You will be directed to Game Screen
Press on one of the icons ( Rock, Scissors or Paper ) according to your choice.
You will be directed to SteemConnect with the choice in memo in a pop-up window.
steem.api.getAccounts([user], function(err, result) {
if (result.length == 1) {
game_on(user);
Here we check if the account is in Steemit.
If true, the length of the array is 1 and if false the length of the array is 0
I am not sure if this is the best way but it works!
function r_ock() {
window.open('https://v2.steemconnect.com/sign/transfer?from=' + user + '&to=' + 'rocksciss' + '&amount=' + '0.100 SBD' + '&memo=' + 'rock', 100, 100);
choice = "rock";
}
Here we sent the choice as memo and initiate the steemconnect in a pop-up window.
// Start listening to block-chain
var release = steem.api.streamTransactions('head', function(err, result) {
// Check if result is a transfer from user to AI
if ((result.operations["0"]["0"] == 'transfer') && (result.operations["0"]["1"].to == 'rocksciss') && (result.operations["0"]["1"].from == user) && (choices.includes(result.operations["0"]["1"].memo))) {
The full code is here.
The server side is written in node-js as a complete back-end script.
It runs in a secure server.
It mainly listens to the block-chain and catches the transactions sent by client-side
/listen to blockchain
var release = steem.api.streamTransactions('head', function(err, result) {
if ((result.operations["0"]["0"] == 'transfer') && (result.operations["0"]["1"].to=='rocksciss')&&((result.operations["0"]["1"].memo=='rock')||(result.operations["0"]["1"].memo=='scissors')||(result.operations["0"]["1"].memo=='paper'))) {
When the correct transaction is catched, it makes the calculated transfer.
if ((choice == 'rock') && (AI_choice == 'scissors')) {
status_text = "You:Rock - AI:Scissors ..... WIN! ..... 0.2 SBD paid.";
steem.broadcast.transfer('xxxxxxx', 'rocksciss', user, '0.200 SBD', status_text, function(err, result) {
});
The full code can be found here
@FireDream - Steemit
@firedream#3528 - Discord
Rock-Scissors-Paper (RSP) Game
GitHub