jens.lauer's picture

Overview & Installation

Have you been in Las Vegas and have you played a slot machine? Now you can play in ARIS Business Architect, too. Attached to this post, you will find an ARIS based slot machine.

I use the ARIS Slot Machine to show how ARIS macros can be executed automatically after opening a model or double-clicking on an object.

To play ARIS Slot Machine, you need the following:

You can download those three items following the links. Please note, you can only download if you are currently logged in to ARIS Community.

The macros were developed for and tested with ARIS Platform 7.1 and it might not run on older versions. Make sure that you have ARIS Business Architect, because you need the administration module to import the macros. In case you only got ARIS Business Designer on your machine, you must ask your ARIS administrator to install the macro for you. For more information about downloading & setting up macros in ARIS, read the article “Reports and macros in ARIS”. Please install the macros before you proceed with importing the database as described below.

Setup Database

Before we start, install the database. In Explorer of ARIS Business Architect choose “Restore” in the context menu.

The restore wizard opens and you can select the downloaded database.

After hitting the Open button, the database gets imported. After the successful import of the database, a dialog is shown. Close this dialog by pressing the OK button.

You can now open the newly imported database “ARIS gambling edition”. Make sure to use the filter “Entire Method”. You now imported the database and belonging macros. It’s time to start gambling :-)

Playing ARIS Slot Machine

The database contains a single model. Open this model to start playing. If you open the model, the macro named „Start Slot Machine“ is executed automatically and a dialog containing the game instructions is shown.

Confirm and you can play!

If you double-click on the hand gear, the next macro named „Slot Machine“ is executed. The symbols in the slots change and after a few seconds you get the result of the run.

Start Slot Machine macro

While playing the ARIS Slot Machine, the two mentioned macros were used. But what do they do exactly? First we have a look at “Start Slot Machine” macro.

By opening the model the macro is executed:

var model = Context.getSelectedModels()[0];

To ensure that the macro is only run on the model of the ARIS Slot Machine, the GUID of the model is checked.

if(Designer.getGUID(model).equals("12831a80-04b0-11dd-69a5-0010c6dc92ea")){
    main();
}

The main function shows a small visual animation in the model, changing the color of several objects to green. The animation consists of multiple occurrences of the same object definition. We first load the object definition. Then we load the occurrences for the animation and sort them. The animation is shown by coloring the object from the left to the right. The main function calls other functions like the sort function and the setColor function, which are explained a little bit further down.

function main(){
    //the progress consists of multiple occs of the same objdef. So we first load the objdef
    var def = Designer.getObjDefByGUID( // returns the object definition to the specified GUID
        Context.getLoginInfo(model).getDatabase(), //the database
        "6613ce67-5a15-11dd-4890-005056c00001");//the guid of the objdef

    //load the occs for the progress        
    var occs = Designer.getOccs(def);// returns all occurences of a given object definition
    //sort the occs by their x-coordinate
    occs.sort(sortFunc);
    for(var i=0; i<occs.length; i++){
        //change the color of the progress objects from left to right from red to green
        setColor(occs[i]);
    }

The sort function sorts the occurrences by x-coordinates.

function sortFunc(a, b){
    return (Designer.getPosition(model, a).getX()>Designer.getPosition(model, b).getX());
}

The setColor function colors the animation objects green and refreshes the model so that the new color of the object occurrences is shown.

function setColor(occ){
    Designer.setFillColor(model, occ,java.awt.Color.GREEN);
    Designer.refresh(model); 
}

After running the main function, the previously shown dialog with the gaming instruction opens and the user can start gambling.

Slot Machine macro

By double-clicking on the hand gear of the slot machine, the macro “Slot Machine” starts. The GUID is checked again. The main function of the “Slot Machine“ macro is called.

Usually a double-click on an object occurrence opens the property dialog of the object. We set a veto for this, so that the dialog won't open.

The hand gear object occurrence, the position and the size of the hand gear are fetched. The possible symbols and the slots of the slot machine are defined. The moving of the hand gear is described. The objects of the last run are deleted. The slots are filled with new occurrences by deleting randomly created occurrences of the last run, creating new occurrences and saving them in the appropriate slot.

function main(){
    //usuallly a double click on an object occurence opens the property dialog. We set a veto for this, so that the dialog won't opened.
    Context.setProperty(Constants.EVENT_VETO, true);
    //fetch the handgear object occurence
    occ = Designer.getOccs(
        Designer.getObjDefByGUID( //returns all occurences of a given object definition to the specified GUID
            Context.getLoginInfo(Designer.getDefinition(Context.getSelectedObjOccs()[0])).getDatabase(), 
            HANDGEAR_OBJECT_GUID)
            )[0];
    //fetch the position of the handgear    
    var pos = Designer.getPosition(model, occ);
    //fetch the size of the handgear
    var size = Designer.getSize(model, occ);
    
    var positions = new Array(3);
    positions[0] = createPosition(290, 600);
    positions[1] = createPosition(744,600);
    positions[2] = createPosition(1194,600);
    var dimension = new java.awt.Dimension(312, 188);
    
    //the possible symbols for the different slots
    var possibleObjectTypes = new Array(2);
    possibleObjectTypes[0] = Constants.ST_BUSINESS_SERVICE;
    possibleObjectTypes[1] = Constants.ST_SW_SERVICE_TYPE;

    //the three slots of the slot machine
    var slots = new Array(3);
    slots[0] = null;
    slots[1] = null;
    slots[2] = null;
        
    //now we visualize the hand gear
    //move the hand gear down
    for(var i=0; i<21; i++){
        pos.setLocation(pos.getX(), pos.getY()+i);
        Designer.setPosition(model, occ, pos);
    }
    
    //move the hand gear back to the original position
    for(var i=0; i<21; i++){
        pos.setLocation(pos.getX(), pos.getY()-i);
        Designer.setPosition(model, occ, pos);
    }
    
    //delete the objects from the last slot machine run.
    for(var i=0; i<3; i++){
        Designer.deleteOcc(model, 
            Designer.getOccAt(model, 
                            createPosition(positions[i].getX()+60, positions[i].getY()+60)
                            )
            );
    }

    // fills the slots with new occs
    for(var i=0; i<30; i++){
        var occ = slots[i%3];
        //delete randomly created occ from the last run
        if(occ != null){
            Designer.deleteOcc(model, occ);
        }
        //turn up your speakers:)
        java.awt.Toolkit.getDefaultToolkit().beep();
        //create the new occ
        occ = Designer.createObjOccAndDefinition(model, possibleObjectTypes[GetRandom(0,1)], positions[i%3]);
        //save the occ in the appropriate slot
        slots[i%3] = occ;
    }

The code above uses a GetRandom function, which generates a random number between minimum and maximum using a function of the Math library.

function GetRandom( min, max ) {
      if( min > max ) {
          return( -1 );
      }
      if( min == max ) {
          return( min );
      }
      var r = parseInt( Math.random() * ( max+1 ) );
      return( r + min <= max ? r + min : r );
}

Finally, the randomly generated symbols in the slots are checked and the result is shown.

 if((Designer.getSymbol(model, slots[0]) == Designer.getSymbol(model, slots[1])) &&
        (Designer.getSymbol(model, slots[1]) == Designer.getSymbol(model, slots[2]))){
        Dialogs.MsgBox("Winner!");
     
    }else{
        Dialogs.MsgBox("Loser!");
    }

Summary

It is now up to you to implement your own small game and extend the ARIS gambling edition. If you do so, please share your scripts with the community, because we all love to play a small game from time to time during work ;-)

Tags: javascript ARIS script