jhylands

play.js (final [hopefully])

Jun 22nd, 2013
189
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(gid){
  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.                                 getpos(gid);
  77.                             }
  78.                         }
  79.                         xmlhttp.open("GET",req,true);
  80.                         xmlhttp.send();
  81. }    
  82. function splayerstraid(uid,id,gid){
  83. loading();
  84. var req = "tradingfloor.php?gid=" + gid  + "&uid=" + uid + "&id=" + id;
  85. var xmlhttp;
  86.                         if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  87.                             xmlhttp=new XMLHttpRequest();
  88.                         }
  89.                         else{// code for IE6, IE5
  90.                             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  91.                         }
  92.                             xmlhttp.onreadystatechange=function(){
  93.                             if (xmlhttp.readyState==4 && xmlhttp.status==200){
  94.                               var resp = xmlhttp.responseText;
  95.                                                         document.getElementById("the").innerHTML=resp;
  96.                             }
  97.                         }
  98.                         xmlhttp.open("GET",req,true);
  99.                         xmlhttp.send();
  100. }
  101. //code used in the tradesfriend script to make the pictures have a yellow border onmousover
  102. function createbd(id){
  103. $("#" + id).css({"border-style":"solid","border-width":"5px"});
  104. }
  105. function erasebd(id){
  106. $("#" + id).css({"color":"black","border":"0","border-color":"yellow"});
  107. }
  108. //global variable lines, holds each player's position in case of update
  109. var lines;
  110. function getpos(gid){
  111. var xmlhttp;
  112. if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  113.     xmlhttp=new XMLHttpRequest();
  114. }else{// code for IE6, IE5
  115.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  116. }
  117. xmlhttp.onreadystatechange=function(){
  118.     if (xmlhttp.readyState==4 && xmlhttp.status==200){
  119.         //returns a list of positions split by comma
  120.         var resp = xmlhttp.responseText;
  121.         //if this is the first time the function is called then inisiate lines
  122.         if(lines ==null){
  123.             lines = resp.split(",");
  124.             //start construction of players in their positions
  125.             drwplyrs(lines);
  126.         }else{
  127.         //otherwise update positions
  128.         var income;
  129.         income = resp.split(",");
  130.         //start construction of players in their positions
  131.         drwplyrs(income);
  132.         clrplyrs(income);
  133.         lines = income;
  134.         }//end of else line != null
  135.     } //end of ajax returned
  136. }//end of ajax onready state
  137. xmlhttp.open("GET","getpos.php?gid=" + gid ,true);
  138. xmlhttp.send();
  139. }//end of getpos function
  140. //variable to store the PID -> FBID
  141. var FBID;
  142. //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
  143. function FBIDret(gid){
  144. var xmlhttp;
  145. if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  146. xmlhttp=new XMLHttpRequest();
  147. }
  148. else{// code for IE6, IE5
  149. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  150. }
  151. xmlhttp.onreadystatechange=function(){
  152. if (xmlhttp.readyState==4 && xmlhttp.status==200){
  153. var resp = xmlhttp.responseText;
  154. FBID = resp.split(",");
  155. getpos(gid);
  156. }
  157. }
  158. xmlhttp.open("GET","scripts/pidtoid.php?gid=" + gid ,true);
  159. xmlhttp.send();
  160. }
  161. //global array to store the property names to save time when updating player positions
  162. var propnames;
  163. //filling the array above
  164. function getPropNames(){
  165. var xmlhttp;
  166. if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  167.     xmlhttp=new XMLHttpRequest();
  168. }else{// code for IE6, IE5
  169.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  170. }
  171. xmlhttp.onreadystatechange=function(){
  172.     if (xmlhttp.readyState==4 && xmlhttp.status==200){
  173.         var resp = xmlhttp.responseText;
  174.         //returns a list of positions split by comma
  175.         propnames = resp.split(",");
  176.     }
  177. }
  178. xmlhttp.open("GET","scripts/getpropertylist.php",true);
  179. xmlhttp.send();
  180. }
  181. //function to update the text on properties when players move around the board
  182. function chan(propertyID,text){
  183. if(text==0){
  184. text = propnames[propertyID];
  185. }
  186. var x = document.getElementById("P" + propertyID);
  187. //check for default text
  188. x.innerHTML = text;
  189. }
  190.  
  191. //find a string in an array
  192. function doesListCont(needle,hay){
  193. var contains;
  194. contains = 0;
  195. for (i=0;i<hay.length;i++){
  196.     if(needle==hay[i]){
  197.         contains = 1;
  198.     }
  199. }
  200. return contains;
  201. }
  202. //draw people in the right places
  203. function drwplyrs(income){
  204. var ardd; // string of all the lines[] that has alredy been used in past builds
  205. ardd = ".";
  206. var stri;
  207. for (i=0;i<income.length-1;i++){
  208. stri="";
  209. if(ardd.indexOf("." + i + ".") == -1){
  210.     for (n=0;n<income.length-1;n++){
  211.         if(income[n]==income[i]){
  212.         //alert(income[n] + ":n=>" + n + "," + income[i] + ":i=>" + i);
  213.         stri = stri + '<img class="profileimage" name="" src="https://graph.facebook.com/' + FBID[n] + '/picture" width="25" height="25" alt="">';
  214.         ardd = ardd + n + ".";
  215.         }
  216.         chan(income[i],stri);
  217.     }//end for(n)
  218. }
  219. }//end for(i)
  220. }//end of drwplyrs function
  221.  
  222. //clear the squars in which people has exited
  223. function clrplyrs(income){
  224. //for each player
  225. for (n=0;n<income.length-1;n++){
  226. //alert(doesListCont(lines[n],income) + "," + lines[n] + "," +i); // debugging code
  227. //if there was someone I and now there isn't in position lines[i]
  228.     if(doesListCont(lines[n],income) == 0){
  229.         if(lines[n]!=null){
  230.         chan(lines[n],0);
  231.         }else{
  232.         //lines[n] is null this shouldn't happen :/
  233.         }
  234.     }
  235. }
  236. }
  237.  
  238. //variable to stop polling twice at once
  239. var inpoll;
  240. //variable to hold data
  241. var database = new Array();
  242. function poll(gid){
  243.     //state that polling has started
  244.     inpoll=true;
  245.     //send request
  246.         var xmlhttp;
  247.     if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
  248.     xmlhttp=new XMLHttpRequest();
  249.     }
  250.     else{// code for IE6, IE5
  251.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  252.     }
  253.     xmlhttp.onreadystatechange=function(){
  254.     if (xmlhttp.readyState==4 && xmlhttp.status==200){
  255.         var resp;
  256.         resp=xmlhttp.responseText;
  257.         var entries;
  258.         entries = resp.split(";");
  259.         for (i=0;i<entries.length;i++){
  260.             database[i] = entries[i].split(",");
  261.         }
  262.         //state that polling has finished
  263.         inpoll=false;
  264.     }
  265.     }
  266.     xmlhttp.open("GET","scripts/poll.php?gid=" + gid,true);
  267.     xmlhttp.send();
  268. }
Advertisement
Add Comment
Please, Sign In to add comment