Tuesday, December 19, 2017

An updated game for testing the dashboard

Some time ago I did a  Node_RED flow just for learning how to use Freeboard Dashboard (click here for the link)

I stopped using Freeboard since NodeRED team incorporated dashboard nodes to the core of Node-RED.


I decided then to update that game ,also for learning purposes.


Here is how the dashboard looks like while the game is running:




This is how the flow looks like:




Flow:

[{"id":"8b9c16c1.9d2c78","type":"inject","z":"ab22dba5.2bb948","name":"Fire","topic":"none","payload":"fire","payloadType":"str","repeat":"","crontab":"","once":false,"x":240,"y":411.0000171661377,"wires":[["90f89153.24b3e"]]},{"id":"2099b281.cc909e","type":"function","z":"ab22dba5.2bb948","name":"Random","func":"msg.value1=Math.floor(Math.random()*100);\nmsg.value2=Math.floor(Math.random()*100);\nmsg.light1=0;\nmsg.light2=0;\nmsg.light3=0;\n\nmsg.runs +=1;\nif (msg.value1>msg.value2) {\n    msg.win1+=1\n    msg.light1=1;\n    msg.light2=0;\n}else if (msg.value2>msg.value1) {\n    msg.win2+=1;\n    msg.light1=0;\n    msg.light2=1;\n}else {\n    msg.light1=1;\n    msg.light2=1;\n    msg.light3=1;\n    msg.stop = true;\n    if (msg.win1 > msg.win2) {\n        msg.winner = \"Player 1\";\n    } else if (msg.win2 > msg.win1) {\n            msg.winner = \"Player 2\";\n        } else {\n            msg.winner = \"It is a draw ! !\";\n        }\n    }\n\n\nreturn msg;","outputs":1,"noerr":0,"x":412.00001525878906,"y":318.0000114440918,"wires":[["f41892a5.e7945","29835b6a.459594","28416391.e7b69c"]]},{"id":"29835b6a.459594","type":"function","z":"ab22dba5.2bb948","name":"Test Stop","func":"\nif (msg.stop) {\n    \n    return null;  \n} else {return msg;}\n\nif (msg.start) {\n    return msg;\n}\n\n","outputs":1,"noerr":0,"x":550,"y":411.0000171661377,"wires":[["68f31cc0.517654"]]},{"id":"68f31cc0.517654","type":"delay","z":"ab22dba5.2bb948","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":252.00001525878906,"y":318.0000114440918,"wires":[["2099b281.cc909e"]]},{"id":"90f89153.24b3e","type":"function","z":"ab22dba5.2bb948","name":"Start","func":"msg.start = true;\nmsg.stop = false;\n\nif (msg.start) {\n    msg.value1=0;\n    msg.value2=0;\n    msg.light1=0;\n    msg.light2=0;\n    msg.light3=0;\n    msg.win1=0;\n    msg.win2=0;\n    msg.runs=0;\n    msg.winner=\"open game\";\n    msg.start=false;\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":380,"y":411.0000171661377,"wires":[["29835b6a.459594","ef05496a.38a308"]]},{"id":"f41892a5.e7945","type":"debug","z":"ab22dba5.2bb948","name":"","active":true,"console":"false","complete":"true","x":582.0000152587891,"y":318.0000114440918,"wires":[]},{"id":"28416391.e7b69c","type":"function","z":"ab22dba5.2bb948","name":"Format Dashboard","func":"var msg1={payload:msg.value1};\nvar msg2={payload:msg.value2};\nvar msg3={payload:msg.runs};\nvar msg4={payload:msg.win1};\nvar msg5={payload:msg.win2};\nvar msg6={payload:msg.winner};\nreturn [msg1, msg2, msg3, msg4, msg5, msg6];","outputs":"6","noerr":0,"x":350,"y":120,"wires":[["f19a4aae.e10238"],["5f728cb7.96f5b4"],["66a9bc7c.0a63e4"],["7a6e1f5f.f64fe"],["456203cc.1a91dc"],["1ca0211e.906b1f"]]},{"id":"f19a4aae.e10238","type":"ui_gauge","z":"ab22dba5.2bb948","name":"","group":"d3e8886d.948888","order":1,"width":0,"height":0,"gtype":"donut","title":"Player 1","label":"","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":560,"y":60,"wires":[]},{"id":"5f728cb7.96f5b4","type":"ui_gauge","z":"ab22dba5.2bb948","name":"","group":"d3e8886d.948888","order":2,"width":0,"height":0,"gtype":"donut","title":"Player 2","label":"","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":560,"y":100,"wires":[]},{"id":"66a9bc7c.0a63e4","type":"ui_text","z":"ab22dba5.2bb948","group":"d3e8886d.948888","order":3,"width":"3","height":"1","name":"","label":"RUNS","format":"{{msg.payload}}","layout":"row-spread","x":550,"y":140,"wires":[]},{"id":"7a6e1f5f.f64fe","type":"ui_text","z":"ab22dba5.2bb948","group":"d3e8886d.948888","order":4,"width":0,"height":0,"name":"","label":"Wins Player 1","format":"{{msg.payload}}","layout":"row-spread","x":580,"y":180,"wires":[]},{"id":"456203cc.1a91dc","type":"ui_text","z":"ab22dba5.2bb948","group":"d3e8886d.948888","order":5,"width":0,"height":0,"name":"","label":"Wins Player 2","format":"{{msg.payload}}","layout":"row-spread","x":580,"y":220,"wires":[]},{"id":"1ca0211e.906b1f","type":"ui_text","z":"ab22dba5.2bb948","group":"d3e8886d.948888","order":5,"width":0,"height":0,"name":"","label":"The Winner is...","format":"{{msg.payload}}","layout":"row-spread","x":580,"y":260,"wires":[]},{"id":"ef05496a.38a308","type":"debug","z":"ab22dba5.2bb948","name":"","active":true,"console":"false","complete":"true","x":518.1000061035156,"y":493.0000171661377,"wires":[]},{"id":"d3e8886d.948888","type":"ui_group","z":"","name":"Button1","tab":"4ce637e8.4ba768","disp":true,"width":"6"},{"id":"4ce637e8.4ba768","type":"ui_tab","z":"","name":"Button Panel","icon":"dashboard"}]

No comments: