Skip to content

Instantly share code, notes, and snippets.

@mururu mururu/web-game.js
Created Oct 26, 2011

Embed
What would you like to do?
web-game .devquiz2011
var card_num = 0;
var card_array = new Array();
var card_twin = new Array();
//カードの要素を取得
for (var ai = 0; true; ai++){
if(document.getElementById('card' + ai) == null){
card_num = ai;
break;
}
}
//全てのカードの色を取得
for(var app = 0; app < card_num; app++){
var myevent = document.createEvent('MouseEvents');
myevent.initEvent('click', false, true);
var element = document.getElementById('card' + app);
element.dispatchEvent(myevent);
var ppp = element.style.backgroundColor;
card_array[app] = ppp;
}
//同じ色のカードの組を作成
for(var woo = 0; woo < card_num; woo++){
for(var hoo = 0; hoo < card_num; hoo++){
if((woo !== hoo) && (card_array[woo] === card_array[hoo])){
card_twin[woo] = hoo;
}
}
}
//組になったカードを開けていく
for(var qqq = 0; qqq < card_num; qqq++){
var myevent2 = document.createEvent('MouseEvents');
myevent2.initEvent('click', false, true);
var element2 = document.getElementById('card' + qqq);
element2.dispatchEvent(myevent2);
var element2 = document.getElementById('card' + card_twin[qqq]);
element2.dispatchEvent(myevent2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.