Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //allow the die to roll only once
- var rolled=false;
- //get the game id from the php to the javascript
- function roll(gid){
- if(!rolled){
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- var resp = xmlhttp.responseText;
- document.getElementById("die").innerHTML=resp;
- senddata(resp);
- }
- }
- xmlhttp.open("GET","die.php" ,true);
- xmlhttp.send();
- rolled=true;
- }
- }
- function nextgo(gid){
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- var resp = xmlhttp.responseText;
- rolled=false;
- }
- }
- xmlhttp.open("GET","nextgo.php?gid=" + gid ,true);
- xmlhttp.send();
- }
- function moveme(gid,uid,roll){
- var req = "move.php?gid=" + gid + "&uid=" + uid + "&roll=" + roll;
- //alert(req);
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- var resp = xmlhttp.responseText;
- getpos(gid);
- }
- }
- xmlhttp.open("GET",req,true);
- xmlhttp.send();
- }
- //global variable lines, holds each player's position in case of update
- var lines;
- function getpos(gid){
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- //returns a list of positions split by comma
- var resp = xmlhttp.responseText;
- //if this is the first time the function is called then inisiate lines
- if(lines ==null){
- lines = resp.split(",");
- //start construction of players in their positions
- drwplyrs(lines);
- }else{
- //otherwise update positions
- var income;
- income = resp.split(",");
- //start construction of players in their positions
- drwplyrs(income);
- clrplyrs(income);
- lines = income;
- }//end of else line != null
- } //end of ajax returned
- }//end of ajax onready state
- xmlhttp.open("GET","getpos.php?gid=" + gid ,true);
- xmlhttp.send();
- }//end of getpos function
- //variable to store the PID -> FBID
- var FBID;
- //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
- function FBIDret(gid){
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- var resp = xmlhttp.responseText;
- FBID = resp.split(",");
- getpos(gid);
- }
- }
- xmlhttp.open("GET","scripts/pidtoid.php?gid=" + gid ,true);
- xmlhttp.send();
- }
- //global array to store the property names to save time when updating player positions
- var propnames;
- //filling the array above
- function getPropNames(){
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- var resp = xmlhttp.responseText;
- //returns a list of positions split by comma
- propnames = resp.split(",");
- }
- }
- xmlhttp.open("GET","scripts/getpropertylist.php",true);
- xmlhttp.send();
- }
- //function to update the text on properties when players move around the board
- function chan(propertyID,text){
- if(text==0){
- text = propnames[propertyID];
- }
- var x = document.getElementById("P" + propertyID);
- //check for default text
- x.innerHTML = text;
- }
- //find a string in an array
- function doesListCont(needle,hay){
- var contains;
- contains = 0;
- for (i=0;i<hay.length;i++){
- if(needle==hay[i]){
- contains = 1;
- }
- }
- return contains;
- }
- //draw people in the right places
- function drwplyrs(income){
- var ardd; // string of all the lines[] that has alredy been used in past builds
- ardd = ".";
- var stri;
- for (i=0;i<income.length-1;i++){
- stri="";
- if(ardd.indexOf("." + i + ".") == -1){
- for (n=0;n<income.length-1;n++){
- if(income[n]==income[i]){
- //alert(income[n] + ":n=>" + n + "," + income[i] + ":i=>" + i);
- stri = stri + '<img class="profileimage" name="" src="https://graph.facebook.com/' + FBID[n] + '/picture" width="25" height="25" alt="">';
- ardd = ardd + n + ".";
- }
- chan(income[i],stri);
- }//end for(n)
- }
- }//end for(i)
- }//end of drwplyrs function
- //clear the squars in which people has exited
- function clrplyrs(income){
- //for each player
- for (n=0;n<income.length-1;n++){
- //alert(doesListCont(lines[n],income) + "," + lines[n] + "," +i); // debugging code
- //if there was someone I and now there isn't in position lines[i]
- if(doesListCont(lines[n],income) == 0){
- if(lines[n]!=null){
- chan(lines[n],0);
- }else{
- //lines[n] is null this shouldn't happen :/
- }
- }
- }
- }
- //variable to stop polling twice at once
- var inpoll;
- //variable to hold data
- var database = new Array();
- function poll(gid){
- //state that polling has started
- inpoll=true;
- //send request
- var xmlhttp;
- if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else{// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- var resp;
- resp=xmlhttp.responseText;
- var entries;
- entries = resp.split(";");
- for (i=0;i<entries.length;i++){
- database[i] = entries[i].split(",");
- }
- //state that polling has finished
- inpoll=false;
- }
- }
- xmlhttp.open("GET","scripts/poll.php?gid=" + gid,true);
- xmlhttp.send();
- }
Advertisement
Add Comment
Please, Sign In to add comment