2018 ソフトウェア設計及び演習用の班Wiki

18::gr08::result.js

データ取得や表示に関してはhiru.jsとほぼ同じ
後半部分にクリックで開示の処理を追加

var pjob = []; //各プレイヤーの役職
var ninzu; //自分も含めたプレイヤー数
var pname = [];
var num = 2;
var lod = [];
var cnt = 0; //クリック数をカウント

var jobimg = [	"aka.png" ,//あか
  		"pan.png" ,//ぱん
  		"esper.png" ,//えすぱー
  		"ghost.png" ,//ごーすと
  		"super.png" ,//スーパー
  		"psycho.png" ,//サイコ
  		"wolf.png"  //ウルフ
             ];

//app.jsから情報を受け取る
var socketio = io.connect();

socketio.on("connected", function(name) {});
socketio.on("s_to_c", function (data) { addMessage(data.value); });
socketio.on("disconnect", function () {});

function inqury(){
    socketio.emit("Uinfo_inqury",0);
    socketio.emit("UJinfo_inqury",0);
}

function reset(){
    socketio.emit("all_reset",0);
}

socketio.on("Uinfo_respons" , function(data){ //人数,プレイヤー名,生死

    var UInfo = [];
    var i=0;

    UInfo = data.value.split(",");
    console.log(UInfo);
    for(var j=0;j<10;j++){
	if(UInfo[i] == "undefined"){
	    ninzu = j;
	    break;
	}
	lod[j] = UInfo[i+1];
	pname[j] = UInfo[i];
	i+=2;
    }
});

socketio.on("UJinfo_respons" , function(data){ //役職

    var UJInfo = [];
    var i=0;

    UJInfo = data.value.split(",");
    console.log(UJInfo);
    for(j=0;j<10;j++){
   	if(UJInfo[i] == "undefined"){
	    break;
	}
  	pjob[j]  = UJInfo[i+1] - 1;
	i+=2;
		
	console.log(pjob[2]);
    }
});

inqury();

window.onload =function(){   
    //各プレイヤー名を表示
    document.getElementById("text1").innerHTML=pname[0];
    document.getElementById("text2").innerHTML=pname[1];
    document.getElementById("text3").innerHTML=pname[2];
    document.getElementById("text4").innerHTML=pname[3];
    document.getElementById("text5").innerHTML=pname[4];
    document.getElementById("text6").innerHTML=pname[5];
    document.getElementById("text7").innerHTML=pname[6];
    document.getElementById("text8").innerHTML=pname[7];
    document.getElementById("text9").innerHTML=pname[8];
    document.getElementById("text10").innerHTML=pname[9];
    result_lod();
    hyoji(); 
}

function hyoji(){
    //余計なカードを削除   
    switch(ninzu){
    case 4:
	document.getElementById("text5").innerHTML="";
	document.getElementById("img5").src = "about:blank";
    case 5:
	document.getElementById("text6").innerHTML="";
	document.getElementById("img6").src = "about:blank";
    case 6:
	document.getElementById("text7").innerHTML="";
	document.getElementById("img7").src = "about:blank";
    case 7:
	document.getElementById("text8").innerHTML="";
	document.getElementById("img8").src = "about:blank";
    case 8:
	document.getElementById("text9").innerHTML="";
	document.getElementById("img9").src = "about:blank";
    case 9:
	document.getElementById("text10").innerHTML="";
	document.getElementById("img10").src = "about:blank";
	break;

    default:
	break;
    }
};

function result_lod(){
    if(lod[0] == 1){
	document.getElementById("img1").src = "dead.png";
    }    
    if(lod[1] == 1){
	document.getElementById("img2").src = "dead.png";
    }    
    if(lod[2] == 1){
	document.getElementById("img3").src = "dead.png";
    }
    if(lod[3] == 1){
	document.getElementById("img4").src = "dead.png";
    }
    if(lod[4] == 1){
	document.getElementById("img5").src = "dead.png";
    }
    if(lod[5] == 1){
	document.getElementById("img6").src = "dead.png";
    }
    if(lod[6] == 1){
	document.getElementById("img7").src = "dead.png";
    }
    if(lod[7] == 1){
	document.getElementById("img8").src = "dead.png";
    }
    if(lod[8] == 1){	
	document.getElementById("img9").src = "dead.png";
    }
    if(lod[9] == 1){
	document.getElementById("img10").src = "dead.png";
    }
};

//ボタンをクリックでカードを開示
function kaiji(){
    cnt++;
    if( (cnt % num) == 0) { //デフォルト表示
	document.getElementById("img1").src = "alive.png";
	document.getElementById("img2").src = "alive.png";
	document.getElementById("img3").src = "alive.png";
	document.getElementById("img4").src = "alive.png";
	document.getElementById("img5").src = "alive.png";
	document.getElementById("img6").src = "alive.png";
	document.getElementById("img7").src = "alive.png";
	document.getElementById("img8").src = "alive.png";
	document.getElementById("img9").src = "alive.png";
	document.getElementById("img10").src = "alive.png";
	result_lod();
	hyoji();
    }
    else{ //各プレイヤーのカードを表示
	document.getElementById("img1").src = jobimg[pjob[0]];
	document.getElementById("img2").src = jobimg[pjob[1]];
	document.getElementById("img3").src = jobimg[pjob[2]];
	document.getElementById("img4").src = jobimg[pjob[3]];
	document.getElementById("img5").src = jobimg[pjob[4]];
	document.getElementById("img6").src = jobimg[pjob[5]];
	document.getElementById("img7").src = jobimg[pjob[6]];
	document.getElementById("img8").src = jobimg[pjob[7]];
	document.getElementById("img9").src = jobimg[pjob[8]];
	document.getElementById("img10").src = jobimg[pjob[9]];
	hyoji();
    }
};


最終更新日:2018/08/03 00:10:50