jhylands

Play.js (stable)

May 22nd, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //allow the die to roll only once
  2. var rolled=false;
  3. //get the game id from the php to the javascript
  4.  
  5. function roll(){
  6. if(!rolled){
  7.                         var xmlhttp;
  8.                         if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  9.                             xmlhttp=new XMLHttpRequest();
  10.                         }
  11.                         else{// code for IE6, IE5
  12.                             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  13.                         }
  14.                             xmlhttp.onreadystatechange=function(){
  15.                             if (xmlhttp.readyState==4 && xmlhttp.status==200){
  16.                                                                 var resp = xmlhttp.responseText;
  17.                                 document.getElementById("die").innerHTML=resp;
  18.                                     senddata(resp);
  19.                                                         }
  20.                         }
  21.                         xmlhttp.open("GET","die.php" ,true);
  22.                         xmlhttp.send();
  23.                                                 
  24.                                                 rolled=true;
  25.                                                 }
  26.                    
  27. }
  28. function nextgo(gid){
  29.                         var xmlhttp;
  30.                         if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  31.                             xmlhttp=new XMLHttpRequest();
  32.                         }
  33.                         else{// code for IE6, IE5
  34.                             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  35.                         }
  36.                             xmlhttp.onreadystatechange=function(){
  37.                             if (xmlhttp.readyState==4 && xmlhttp.status==200){
  38.                               var resp = xmlhttp.responseText;
  39.                                 rolled=false;
  40.                             }
  41.                         }
  42.                         xmlhttp.open("GET","nextgo.php?gid=" + gid ,true);
  43.                         xmlhttp.send();
  44. }     
  45. function trade(gid,uid){
  46. loading();
  47.                         var xmlhttp;
  48.                         if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  49.                             xmlhttp=new XMLHttpRequest();
  50.                         }
  51.                         else{// code for IE6, IE5
  52.                             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  53.                         }
  54.                             xmlhttp.onreadystatechange=function(){
  55.                             if (xmlhttp.readyState==4 && xmlhttp.status==200){
  56.                               var resp = xmlhttp.responseText;
  57.                                                         document.getElementById("the").innerHTML=resp;
  58.                             }
  59.                         }
  60.                         xmlhttp.open("GET","tradesfriend.php?gid=" + gid + "&uid=" + uid ,true);
  61.                         xmlhttp.send();
  62. }
  63. function moveme(gid,uid,roll){
  64. var req = "move.php?gid=" + gid  + "&uid=" + uid + "&roll=" + roll;
  65. //alert(req);
  66.                         var xmlhttp;
  67.                         if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  68.                             xmlhttp=new XMLHttpRequest();
  69.                         }
  70.                         else{// code for IE6, IE5
  71.                             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  72.                         }
  73.                             xmlhttp.onreadystatechange=function(){
  74.                             if (xmlhttp.readyState==4 && xmlhttp.status==200){
  75.                               var resp = xmlhttp.responseText;
  76.                             }
  77.                         }
  78.                         xmlhttp.open("GET",req,true);
  79.                         xmlhttp.send();
  80. }    
  81. function splayerstraid(uid,id,gid){
  82. loading();
  83. var req = "tradingfloor.php?gid=" + gid  + "&uid=" + uid + "&id=" + id;
  84. var xmlhttp;
  85.                         if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  86.                             xmlhttp=new XMLHttpRequest();
  87.                         }
  88.                         else{// code for IE6, IE5
  89.                             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  90.                         }
  91.                             xmlhttp.onreadystatechange=function(){
  92.                             if (xmlhttp.readyState==4 && xmlhttp.status==200){
  93.                               var resp = xmlhttp.responseText;
  94.                                                         document.getElementById("the").innerHTML=resp;
  95.                             }
  96.                         }
  97.                         xmlhttp.open("GET",req,true);
  98.                         xmlhttp.send();
  99. }
  100. //code used in the tradesfriend script to make the pictures have a yellow border onmousover
  101. function createbd(id){
  102. $("#" + id).css({"border-style":"solid","border-width":"5px"});
  103. }
  104. function erasebd(id){
  105. $("#" + id).css({"color":"black","border":"0","border-color":"yellow"});
  106. }
  107. //global variable lines, holds each player's position in case of update
  108. var lines;
  109. function getPos(gid){
  110. var xmlhttp;
  111. if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  112.     xmlhttp=new XMLHttpRequest();
  113. }else{// code for IE6, IE5
  114.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  115. }
  116. xmlhttp.onreadystatechange=function(){
  117.     if (xmlhttp.readyState==4 && xmlhttp.status==200){
  118.         //returns a list of positions split by comma
  119.         var resp = xmlhttp.responseText;
  120.         //if this is the first time the function is called then inisiate lines
  121.         if(lines ==null){
  122.             lines = resp.split(",");
  123.             //fill the array FBID so that it can be referenced to
  124.             //pausable cause of error gid is initiated in the parent function
  125.             FBIDret(gid);
  126.             //start construction of players in their positions
  127.             for(i=0;i<lines.length;i++){
  128.             }
  129.         }else{
  130.         //otherwise check the new set of positions against the old ones
  131.         var income;
  132.         income = resp.split(",");
  133.         //for loop through each player
  134.         for (i=0;i<income.length;i++){
  135.             //if there is a change from the old value to the new one
  136.             if(income[i]!=lines[i]){//found the changed position
  137.                 if(doesListCont(lines[i],income)){//if contained in list 2 rewrite the innerHTML for that cell
  138.                 //rewrite cell by looking for the users who are still in that cell
  139.                 //look through to see who is in the square and generate the image of the square
  140.                
  141.                 //update cell with new innerhtml
  142.                 chan(lines[i],stri);
  143.                 }else{
  144.                 chan(lines[i],0);
  145.                 }
  146.             }//end of if change from old list to new list
  147.         }//end of for loop through players
  148.         }//end of else line != null
  149.     } //end of ajax returned
  150. }//end of ajax onready state
  151. xmlhttp.open("GET","getpos.php?gid=" + gid ,true);
  152. xmlhttp.send();
  153. }//end of getpos function
  154. //variable to store the PID -> FBID
  155. var FBID;
  156. //the start of a function that gets the FBID of a user and adds it to a locally stored array so profile pics can be referenced to when the game finds changes in the position on the board
  157. function FBIDret(gid){
  158. var xmlhttp;
  159. if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  160. xmlhttp=new XMLHttpRequest();
  161. }
  162. else{// code for IE6, IE5
  163. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  164. }
  165. xmlhttp.onreadystatechange=function(){
  166. if (xmlhttp.readyState==4 && xmlhttp.status==200){
  167. var resp = xmlhttp.responseText;
  168. FBID = resp.split(",");
  169. }
  170. }
  171. xmlhttp.open("GET","scripts/pidtoid.php?gid=" + gid ,true);
  172. xmlhttp.send();
  173. }
  174. //global array to store the property names to save time when updating player positions
  175. var propnames;
  176. //filling the array above
  177. function getPropNames(){
  178. var xmlhttp;
  179. if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  180.     xmlhttp=new XMLHttpRequest();
  181. }else{// code for IE6, IE5
  182.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  183. }
  184. xmlhttp.onreadystatechange=function(){
  185.     if (xmlhttp.readyState==4 && xmlhttp.status==200){
  186.         var resp = xmlhttp.responseText;
  187.         //returns a list of positions split by comma
  188.         propnames = resp.split(",");
  189.     }
  190. }
  191. xmlhttp.open("GET","scripts/getpropertylist.php",true);
  192. xmlhttp.send();
  193. }
  194. //function to update the text on properties when players move around the board
  195. function chan(propertyID,text){
  196. if(text==0){
  197. text = propnames[propertyID];
  198. }
  199. var x = document.getElementById("P" + propertyID);
  200. //check for default text
  201. x.innerHTML = text;
  202. }
  203.  
  204. //find a string in an array
  205. function doesListCont(needle,hay){
  206. var contains;
  207. contains = 0;
  208. for (i=0;i<hay.length;i++){
  209.     if(needle==hay){
  210.         contains = 1;
  211.     }
  212. }
  213. return contains;
  214. }
  215. //draw people in the right places
  216. function drwPlyrs(income){
  217. var ardd; // string of all the lines[] that has alredy been used in past builds
  218. ardd = ".";
  219. for (i=0;i<income.length-1;i++){
  220. if(ardd.indexOf("." + i + ".") == -1){
  221.     for (n=0;n<income.length;n++){
  222.         if(income[n]==income[i]){
  223.         stri = stri + '<img class="profileimage" name="" src="https://graph.facebook.com/' + FBID[n] + '/picture" width="10" height="10" alt="">';
  224.         ardd = ardd + n + ".";
  225.         }
  226.         chan(income[i],stri);
  227.     }//end for(n)
  228. }
  229. }//end for(i)
  230. }//end of drwplyrs function
  231.  
  232. //clear the squars in which people has exited
  233. function clrplyrs(lines,income){
  234. for (i=0;i<lines.length;i++){
  235.     if(doeslistcont(lines[i],income) == 0){
  236.         chan(line,0);
  237.     }
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment