aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-18 17:41:57 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-18 17:41:57 -0500
commitdf83eaa9e4a0e2697859cda0c7a075259c147886 (patch)
tree0b4998fd9a3bc780dcb903f4f846e85d6d95ab8d /examples
parent92e1659c82243a05bb4819b825da112046ce6dca (diff)
Started jarvis
Diffstat (limited to 'examples')
-rw-r--r--examples/jarvis.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
new file mode 100644
index 0000000..a130f17
--- /dev/null
+++ b/examples/jarvis.js
@@ -0,0 +1,26 @@
+// A bot which responds to `jarvis` with a box
+
+const space = require('../space');
+const socket = require('../socket');
+
+var main = new socket.Socket();
+
+function equals(arg1,arg2){ // Just takes the specific case argument of each being an int pair
+ return arg1[0] == arg2[0] && arg1[1] == arg2[1]
+}
+
+main.on('open', ()=>{ // Tries to identify itself with a cursor movement
+ let coords = [Math.floor(Math.random()*100000+16),Math.floor(Math.random()*100000+16)];
+ main.cursor(coords);
+ main.on('cursor', detect);
+ function detect(pos, send){
+ if (equals(pos[0],coords)){
+ main.off('cursor', detect);
+ this.emit('identity', sender);
+ }
+ }
+})
+
+main.on('identity', (sender) => {
+
+}