From 1954ed67ef61c509560418a9d2da58083b822996 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 5 Dec 2015 20:40:32 +0100 Subject: Initial enzo --- .gitignore | 1 + common.js | 82 ++++++++ index.html | 545 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 248 +++++++++++++++++++++++ interactorindex.html | 228 +++++++++++++++++++++ package.json | 24 +++ 6 files changed, 1128 insertions(+) create mode 100644 .gitignore create mode 100644 common.js create mode 100644 index.html create mode 100755 index.js create mode 100644 interactorindex.html create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/common.js b/common.js new file mode 100644 index 0000000..e77db07 --- /dev/null +++ b/common.js @@ -0,0 +1,82 @@ +var W=8,H=9; + +if(typeof module=="undefined")module=false; //hack to support client-side importing + +if(module)module.exports["emptyboard"]=emptyboard; +function emptyboard(){ + return new Array(H).fill(0).map(function(){ + return new Array(W).fill(0).map(function(){ + return {n:0,c:0}; + }); + }); +} + +if(module)module.exports["bdcopy"]=bdcopy; +function bdcopy(bd){ + return bd.map(function(r){ + return r.map(function(c){ + return {n:c.n,c:c.c}; + }); + }); +} + +if(module)module.exports["checkwin"]=checkwin; +function checkwin(bd){ + var wincolour=-1,i; + for(i=0;i0)+(x>0)+(y=nnei){ + quo=~~(bd[y][x].n/nnei); + newbd[y][x].n-=quo*nnei; + if(y>0) {newbd[y-1][x].n+=quo;newbd[y-1][x].c=bd[y][x].c;} + if(x>0) {newbd[y][x-1].n+=quo;newbd[y][x-1].c=bd[y][x].c;} + if(y>>0,i=arguments[1],a=i>>0,e=0>a?Math.max(n+a,0):Math.min(a,n),o=arguments[2],h=void 0===o?n:o>>0,l=0>h?Math.max(n+h,0):Math.min(h,n);l>e;)r[e]=t,e++;return r}; diff --git a/index.html b/index.html new file mode 100644 index 0000000..dcf0b9b --- /dev/null +++ b/index.html @@ -0,0 +1,545 @@ + + + + +Multichain + + + + + + + +
+
Nickname:
+

Multichain

+
+
+
+
+ Online users: +
+
+ +
+
+
+ + diff --git a/index.js b/index.js new file mode 100755 index 0000000..d2432ac --- /dev/null +++ b/index.js @@ -0,0 +1,248 @@ +#!/usr/bin/env node + +"use strict"; + +var app=require("express")(), + http=require("http").Server(app), + io=require("socket.io")(http), + fs=require("fs"), + spawn=require("child_process").spawn, + mkdirp=require("mkdirp"), + C=require("./common.js"); + + +var HTTPPORT=8090; + +var uniqid=(function(){ + var id=0; + return function(){return id++;}; +})(); + +app.get("/",function(req,res){ + res.sendFile(__dirname+"/index.html"); +}); + +["index.html","common.js"].forEach(function(fname){ + app.get("/"+fname,function(req,res){ + res.sendFile(__dirname+"/"+fname); + }); +}); + +function Game(_np){ + if(!(this instanceof Game))return new Game(_np); + this.bd=emptyboard(); + this.np=np; + this.onturn=0; +} +Game.prototype.applymove=function(player,pos){ + if(this.onturn!=player)return false; + var x=pos%C.W,y=~~(pos/C.W); + if(this.bd[y][x].n&&this.bd[y][x].c!=player)return false; + this.bd[y][x].c=player; + this.bd[y][x].n++; + this.bd=C.stabilise(this.bd); + do this.onturn=(this.onturn+1)%this.np; + while C.countballs(this.bd,this.onturn)==0; + return true; +}; +Game.prototype.checkwin=function(){ + if(C.countballs(this.bd): {ids:[id's], game:Game}} + +function findid(id){ + var lo=0,mid,hi=connlist.length-1; + if(connlist[lo].id==id)return lo; + if(connlist[hi].id==id)return hi; + while(lo + + + +Interactor for Chain Reaction + + + + + +

Interactor for Chain Reaction

+
+ + + \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..8a258d0 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "multichain", + "version": "1.0.0", + "description": "Multiplayer chain reaction", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "chain", + "reaction", + "chainreaction", + "multiplayer", + "game", + "server" + ], + "author": "Tom Smeding (http://tomsmeding.com)", + "license": "MIT", + "dependencies": { + "express": "^4.13.3", + "mkdirp": "^0.5.1", + "socket.io": "^1.3.7" + } +} -- cgit v1.2.3-54-g00ecf