Spit The Trough: "Today actually I wrestling, write a thing good!" The pen of the hand turns a half day .... Finally, give yourself some room! Look at them. Hotel Management system, call center system and the like .... It's a dead end to yourself! Feel the end of the feeling!!! We are programmers so I think it's more flexible to HoHo ... "
Today I just want to write an article about JavaScript arrays.
I used to think I had mastered the array completely! But I was asked to stay in the interview last year!! Instantly feel oneself Meng Meng da!! So the book is not counted! So this time in order to let my apprentice can no longer make my mistakes ... Hum! I decided to let her have a combat!!! Can't let her go out and throw my face (even though they all say I've been disgraced----embarrassed!! )
Okay, here's the key point.
A deck of Cards 54 cards 1-13*4+ size King 2 Zhang 14,15
var poker=new Array("1","1","1","1","2","2","2","2","3","3","3","3",......."14","15"
)一个长长的数组额,我也不知道争上游这个游戏!有木有12345这个排序,但貌似有23456,算了就算他有吧
好吧然后是一个神奇的发牌
循环吧,恶心的事情来了
大概的想法是
首先一个大的循环
for(i<0;i<54;i++){
因为逻辑太复杂了(所以我往简单的方法写了)
然后里面要产生个随机数(1-54)还要递减,//因为每次随机发一次牌,数组的长度-1
如果是复杂的写法的(要第一次发给A,第二次发给B,第三次发给C的)但是(貌似给你们难度大了点所以)
}
简单的方法把随机抽到的字放到一个新数组里面(然后重新排列)果然我还是很仁慈的-_-//
一共有3个人
A
B
C
JavaScript Slice ()
然后抽取数组第1个到第13给A
然后抽取数组第14个到第27给B
然后抽取数组第28个到第54给C
这个时候还要做出一个判定了(花色的判定!!!好吧好吧!我放过你了!就让你写在数组里面吧)
...然后你就把这里完成了!!!剩下的判定后天写吧
产生随机数的方法:在这里!!
random函数示例
document.write(Math.random()*(n-m)+m);
Homework: JavaScript (array article-poker) give my apprentice a question ... Remember to finish writing early, then 3 people can play cards earlier