Git Product home page Git Product logo

airconsole-gambling's Introduction

This is a javascript AirConsole library to extend your game with gambling features.

You can assign every player an amount of start coins. Players can then bet on something and earn or lose coins.

Player can also transfer coins to other players.

How To

Including files:

Clone this repository into your project and add the following files:

ALSO check out the /example files

SCREEN:

<script type="text/javascript" src="https://www.airconsole.com/api/airconsole-1.6.0.js"></script>
<script type="text/javascript" src="airconsole-gambling/shared.js"></script>
<script type="text/javascript" src="airconsole-gambling/bank.js"></script>

CONTROLLER:

<script type="text/javascript" src="https://www.airconsole.com/api/airconsole-1.6.0.js"></script>
<script type="text/javascript" src="airconsole-gambling/shared.js"></script>
<script type="text/javascript" src="airconsole-gambling/gambler.js"></script>

The Bank (screen)

The screen is the bank. It receives and manages all transactions and bets.

Setup
var airconsole = new AirConsole();
var bank = new Bank(airconsole, {
  // The bet-mode. If none set, default is: Bank.Mode.Default
  mode: Bank.Mode.Winner_Takes_All,
  // The inital amount of coins all devices should get on start
  start_value: 2000
});

There are currently two different modes:

  • Default: If you want players to place multiple bets and have a bet-quota.
  • Winner-Takes-All: If player can only bet on one thing.
airconsole.onReady = function () {
  // Init the bank as soon as AirConsole is ready
  bank.init();
  // If you want to set certain quoats for your bet tags
  bank.setTagQuota('turtle_wins', 1);
  // If the rabbit wins, the player will get 2-times the amount of placed coins back
  bank.setTagQuota('rabbit_wins', 2);
};

Add the following methods to the airconsole methods

airconsole.onMessage = function (device_id, data) {
  bank.onMessage(device_id, data);
};

airconsole.onConnect = function(device_id) {
  bank.onConnect(device_id);
};

airconsole.onDisconnect = function(device_id) {
  bank.onDisconnect(device_id);
};
Bank methods
// Resets the bank and all gamblers
bank.reset();

// Call this method to open a new round. ALWAYS DO THIS BEFORE PLACING NEW BETS!
bank.openRound();

// Call this method to close the current round. No new bets are accepted
bank.closeRound();

// If the round is closed or not
bank.isLocked();

// Triggered when each devices has at least placed one bet
bank.onAllGamblersBet();

// Evaluates the round. Call this when your games round is over.
// success_tags: Array of tags which won ['rabbit_wins', 'device_2_wins']
bank.evaluateRound(success_tags);

// Sets a quota for a bet tag
bank.setTagQuota('rabbit_wins', 1.5);

bank.getTagQuota('rabbit_wins'); // Returns 1.5

/**
  Returns the custom device data of the bank
  {
    devices: {},
    bet_round_id: 0,
    bets_locked: false
  };
*/
bank.getCustomData();

The Gambler (controller)

Setup
var airconsole = new AirConsole();
var gambler = new Gambler(airconsole);

airconsole.onReady = function () {
  gambler.init();
};

airconsole.onMessage = function (device_id, data) {
  gambler.onMessage(device_id, data);
};

airconsole.onCustomDeviceStateChange = function (device_id, data) {
  gambler.onCustomDeviceStateChange(device_id, data);

  // E.g. to set the amount
  var amount = gambler.getCurrentAmount();
  yourRenderAmountFunction(amount);
};
Gambler methods
// Place a bet of 100 coins on the turtle
$("#bet_button_turtle").on('click', function() {
  if (!gambler.isRoundClosed()) {
    gambler.placeBet(100, "turtle_wins");
  }
});

// Make a transaction to device_id 2
$("#transfer_button").on('click', function() {
  gambler.makeTransaction(100, 2);
});

airconsole-gambling's People

Contributors

franzeus avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.