javascript
資料夾 jquery
檔案 jquery-3.2.1.min.js
下載路徑 https://jquery.com/download/
資料夾 image
圖檔 poker.png
範例圖檔(Google 標記為允許再利用)(960*575)
https://pixabay.com/zh/%E5%8D%A1%E7%89%87%E7%BB%84-%E7%94%B2%E6%9D%BF-%E5%8D%A1-%E7%8E%A9%E6%89%91%E5%85%8B%E7%89%8C-%E6%B8%B8%E6%88%8F-%E8%B5%8C%E5%8D%9A-%E5%A8%B1%E4%B9%90-%E8%B5%8C%E5%9C%BA-161536/
<HTML>
<HEAD>
<script type="text/javascript" src="jquery/jquery-3.2.1.min.js"></script><!--jquery-->
</HEAD>
<body bgColor="#ffffff">
<!-- 資料輸入 -->
資金 <input type="text" name="intFunding" id="intFunding" value="10000">
總下注 <input type="text" name="intBettingAll" id="intBettingAll" value="">
下注 <input type="text" name="intBetting" id="intBetting" value="100">
<!-- 送出 -->
<br>
<input type="button" value="next" id="dcExcel" onClick="next();">
<input type="button" value="顯示" id="dcExcel" onClick="showResult();">
<!-- 顯示 -->
<div id="divDataP1">
</div>
<div id="divDataP2">
</div>
<div id="divDataShow">
</div>
</body>
</HTML>
<script type="text/javascript" language="javascript">
var Basic = []; //基本牌
var P1 = []; //1號
var P2 = []; //2號
var Points = 0; //點1~13
var Color = 0; //色4
var intRound = 0; //回合
var intRoundP1 = 0; //回合
var intRoundP2 = 0; //回合
var intFunding = 10000; //資金
var intBettingAll = 0; //總下注
var intBetting = 0; //下注
reset();
//重設
function reset(){
//A最大=14
Basic[0] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
Basic[1] = [0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
Basic[2] = [0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
Basic[3] = [0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
Basic[4] = [0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
intRound = 0;
intRoundP1 = 0; //回合
intRoundP2 = 0; //回合
P1 = [];
P2 = [];
intBettingAll = 0;
intBetting = 0;
$('#divDataP1').html("");
$('#divDataP2').html("");
$('#divDataShow').html("");
}
//下一個
function next() {
intRound++;
//確保一定有牌
if (intRound <= 10) {
//發牌
if (intRound % 2 == 1) {
//下錢
intBetting = $("#intBetting").val();
intBettingAll = intBettingAll*1 + intBetting*1;
intFunding = intFunding - intBetting;
$("#intBettingAll").val(intBettingAll);
$("#intFunding").val(intFunding);
intRoundP1++;
send();
P1[intRoundP1] = [0, Color, Points];
showSend(1);
}
if (intRound % 2 == 0) {
intRoundP2++;
send();
P2[intRoundP2] = [0, Color, Points];
showSend(2);
}
}
else if(intRound == 11){
showResult();
}
else{
reset()
}
}
//發送找確認卡
function send() {
var ColorSe = TrRandom(1, 4);
var PointsSe = TrRandom(2, 14);
if (Basic[ColorSe][PointsSe] != 0) {
Color = ColorSe;
Points = PointsSe;
Basic[ColorSe][PointsSe] = 0;
}
else {
send();
}
}
//品質
function TrQuality(p) {
var returnData = 0;
var intPoMax = 0 //點最大點
var intPoMin = 14; //點最小點
var intPoAll = 0; //點數加總
var intCoRepeat = 0; //花重複數量
var intPoRepeat = 0; //點重複數量
var intPoRepeatMax = 0; //點重複數量中最大的直
var intPo3Quantity = 0; //點重複的次數
var intPo3RepeatMax = 0;//點重複3次的點數
var q = [0, 0, 0]; //排序
var intStrTail = "0."; //將數字用小數串總
//排序
for (var i = 1; i < p.length - 1; i++) {
for (var j = i; j < p.length - 1 ; j++) {
if (p[i][2] < p[j + 1][2]) {
q = p[i];
p[i] = p[j + 1];
p[j + 1] = q;
}
}
}
//判斷極質
for (var i = 1; i < p.length; i++) {
intStrTail = intStrTail + "" + TRsupplement(p[i][2]);
intStrTail = intStrTail * 1;
intPoAll = intPoAll * 1 + p[i][2] * 1;
if (intPoMax < p[i][2]) {
intPoMax = p[i][2];
}
if (intPoMin > p[i][2]) {
intPoMin = p[i][2];
}
}
//判斷重複次數
for (var i = 1; i < p.length - 1; i++) {
intPo3Quantity = 0;
if (p[i][1] == p[(i + 1)][1]) {
intCoRepeat++;
}
for (var j = i; j < p.length - 1 ; j++) {
if (p[i][2] == p[(j + 1)][2]) {
intPoRepeat++;
intPo3Quantity++;
if (intPoRepeatMax < p[i][2]) {
intPoRepeatMax = p[i][2];
}
if (intPo3Quantity >= 2)//三張相同牌
{
intPo3RepeatMax = p[i][2];
}
}
}
}
//當有超過三次重複的牌,才是真實的最大點數
if (intPo3RepeatMax > 0) {
intPoRepeatMax = intPo3RepeatMax;
}
//開始比值
//2
if (intPoRepeat == 1) {
returnData = 100 + intPoRepeatMax + intStrTail;
}
//2+2
else if (intPoRepeat == 2) {
returnData = 200 + intPoRepeatMax + intStrTail;
}
//3
else if (intPoRepeat == 3) {
returnData = 300 + intPoRepeatMax;
}
//葫3+2
else if (intPoRepeat == 4) {
returnData = 600 + intPoRepeatMax;
}
//鐵4+1
else if (intPoRepeat == 6) {
returnData = 700 + intPoRepeatMax;
}
//同+12345
else if ((intPoRepeat == 0) && (((intPoMax - intPoMin) == 4) || (((intPoMax - intPoMin) == 12) && (intPoAll == 28))) && (intCoRepeat == 4)) {
returnData = 800 + intPoMax;
}
//同
else if (intCoRepeat == 4) {
returnData = 500 + intPoMax + intStrTail;
}
//12345
else if ((intPoRepeat == 0) && (((intPoMax - intPoMin) == 4) || (((intPoMax - intPoMin) == 12) && (intPoAll == 28)))) {
returnData = 400 + intPoMax;
}
//無
else {
returnData = 0 + intPoMax + intStrTail;
}
return returnData;
}
//顯示1
function showSend(intPi) {
var P1P2 = [];
var strJpg = "";
var pA = "";
var pB = "";
if(intPi == 1){
P1P2 = P1;
}
else if (intPi == 2){
P1P2 = P2;
}
for (var i = 1; i <= P1P2.length - 1; i++) {
pA = P1P2[i][1];
pB = P1P2[i][2];
//圖形修正 14=A
if (pB == 14) { pB = 1 }
//擷取圖片範圍
strJpg = strJpg + ""
+ " <td>"
+ " <div style='height:115px; width:74px; margin:0; padding:0; "
+ " background:#ffffff url(image/poker.png) no-repeat -" + ((pB - 1) * (74)) + "px -" + ((pA - 1) * (115)) + "px; "
+ " overflow:hidden;'>"
+ " </div>"
+ " </td>"
}
var show = " <table style='border:3px #cccccc;' border='1'>"
+ " <tr> "
+ " " + strJpg
+ " </tr> "
+ " </table>";
$('#divDataP'+intPi).html(show);
}
//結果
function showResult() {
var TqP1 = TrQuality(P1);
var TqP2 = TrQuality(P2);
var stringResult = "平手"
if ((TqP1 * 1) < (TqP2 * 1)) {
stringResult = "敗北"
}
else if ((TqP1 * 1) > (TqP2 * 1)) {
stringResult = "勝利"
intFunding = (intFunding * 1) + (intBettingAll * 2)
}
//投注
$("#intFunding").val(intFunding);
intBettingAll = 0;
$("#intBettingAll").val(intBettingAll);
var show = " <table style='border:3px #cccccc;' border='1'>"
+ " <tr> "
+ " <td> "
+ " " + TqP1 + " --" + stringResult + "-- " + TqP2
+ " </td> "
+ " </tr> "
+ " </table>";
$('#divDataShow').html(show);
}
//亂數 1 ~ n
function TrRandom(minNum, maxNum) {
var returnData = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
return returnData;
}
//補0
function TRsupplement(stringA) {
var returnData = "";
stringA = "0" + stringA;
returnData = stringA.substring(stringA.length - 2, stringA.length)
return returnData
}
//alert(returnData);
</script>
我只是一棵樹