Code Monkey home page Code Monkey logo

machine's Introduction

Machine

A simple fruit machine written in PHP.

/*
 * Add our reels, how many slots the reels have
 *
 * int reelSlots
 * bool canHold
 * bool canNudge
 */
$reels = [
    new Machine\Reel(200, 1, 0),
    new Machine\Reel(200, 1, 0),
    new Machine\Reel(200, 1, 0)
];

/*
 * Add a trail, set the function to run when trail is active.
 *
 * int trailLength
 * int award
 * int runs
 * function callbackFunction
*/
$trail = new Machine\Trail(12, 100, 5, function(){

    /*
     * A simple higher or lower function to run when the trail
     * is active. We need two buttons, a reel from 1 - 24
     * storage for previous number and conditions to test.
     *
     * if this callback returns false the trail ends.
    */
    $entry = new Machine\Button\Group(
        new Machine\Button("High", 1),
        new Machine\Button("Low", 2)
    );

    $n = new Machine\Reel\Number(24);
    $number = $number->spin();
    
    $previous = new Machine\Registry("previous-high-low", $number);
    
    if ($entry == 1 && $number > $previous){
        return true
    } else if ($entry == 2 && $number < $previous) {
        return true;
    } else {
        return false;
    }
});

/*
 * Add buttons to our machine, this will hold or nudge our reel.
*/
$button = new Machine\Button("Hold/Nudge", function($machine){
    $nudges = $machine->nudges();
    
    if ($nudges) {
        $machine->reel(1)->down(1);
    } else {
        $machine->reel(1)->toggleHold();
    }

    return true;
});

$button2 = new Machine\Button("Hold/Nudge", function($machine){
    $nudges = $machine->nudges();
    
    if ($nudges) {
        $machine->reel(2)->down(1);
    } else {
        $machine->reel(2)->toggleHold();
    }

    return true;
});

$button3 = new Machine\Button("Hold/Nudge", function($machine){
    $nudges = $machine->nudges();
    
    if ($nudges) {
        $machine->reel(3)->down(1);
    } else {
        $machine->reel(3)->toggleHold();
    }

    return true;
});

$collect = new Machine\Button("Collect", function(){
    return $machine->collect();
});

$buttons = new Machine\Button\Group([
    $button,
    $button2,
    $button3,
    $collect
]);

/*
 * Set some symbols for our machine to spin on its reels.
*/
$t = new Machine\Reel\Symbol;
$t->setName("tomato");

$x = new Machine\Reel\Symbol;
$x->setName("x");
$x->setPrize(10);

$o = new Machine\Reel\Symbol;
$o->setName("o");
$o->setPrize(20);

$bar = new Machine\Reel\Symbol;
$bar->setName("bar");
$bar->setPrize(50);

/*
 * Put our machine together.
*/
$machine = new Machine;

$machine->addReels($reels);

$machine->addSymbol($x);
$machine->addSymbol($o);
$machine->addSymbol($bar);
$machine->addSymbol($t);

$machine->addTrail($trail);

/*
 * how much does a spin cost.
*/
$machine->setSpin(5);

$machine->addButtons($buttons);

/*
 * Start our machine up and seed our reels.
*/
$machine->init();

/*
 * Now add some credit it and spin.
*/
$machine->addCredit(100);
$machine->spin();

machine's People

Contributors

waxim avatar

Stargazers

Giacomo Tüfekci avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

tuefekci

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.