-
制作一个简单的游戏需要什么技术? 游戏逻辑 技术 -HTML -css -JS -JQuery -美术查看全部
-
touch相关事件查看全部
-
手机端布局查看全部
-
游戏架构查看全部
-
mvc查看全部
-
所需技术:游戏逻辑,技术查看全部
-
手机显示查看全部
-
mvc查看全部
-
function showNumWithAnimation(i, j, num){ var numberCell = $("#number-cell-" + i + '-' + j); numberCell.css({ background: getNumberBackgroundColor(num), color: getNumberColor(num), "font-size": getFontSize(num) }); numberCell.text(num); numberCell.animate({ width: cellWidth, height: cellWidth, top: getPosTop(i, j), left: getPosLeft(i,j) }, 200); } function showMoveAnimation(startI, startJ, endI, endJ){ var numberCell = $("#number-cell-" + startI + '-' + startJ); numberCell.animate({ left: getPosLeft(endI, endJ), top: getPosTop(endI, endJ) }, 200); } </script> </body> </html>查看全部
-
function getNumberBackgroundColor(num){ switch(num){ case 2: return "#eee4da";break; case 4: return "#ede0c8";break; case 8: return "#f2b179";break; case 16: return "#f59563";break; case 32: return "#f67c5f";break; case 64: return "#f65e3b";break; case 128: return "#edcf72";break; case 256: return "#edcc61";break; case 512: return "#9c0";break; case 1024: return "#33b5e5";break; case 2048: return "#09c";break; case 4096: return "#a6c";break; case 8192: return "#93c";break; default: return "#000";break; } } function getNumberColor(num){ if(num <= 4){ return "#776e65"; } else{ return "#fff"; } }查看全部
-
function getFontSize(num){ var len = (num + "").length; switch(len){ case 1: return "150%";break; case 2: return "120%";break; case 3: return "90%";break; case 4: return "70%";break; default: return "50%"; } } function getPosTop(i, j){ return (0.04 + i * 0.22) * winWidth + "px"; } function getPosLeft(i, j){ return (0.04 + j * 0.22) * winWidth + "px"; } function getPosTopCenter(i, j){ return (0.04 + i * 0.22 + 0.09) * winWidth + "px"; } function getPosLeftCenter(i, j){ return (0.04 + j * 0.22 + 0.09) * winWidth + "px"; }查看全部
-
numberCell.text(num); } hasConflicted[i][j] = false; } } }查看全部
-
function updateBoardView(){ $(".number-cell").remove(); for(var i = 0; i < 4; i++){ for(var j = 0; j < 4; j++){ $(".grid-container").append('<div class="number-cell" id="number-cell-' + i + '-' + j + '"></div>'); var numberCell = $("#number-cell-" + i + '-' + j); var num = board[i][j]; if(num == 0){ numberCell.css({ width: 0, height: 0, left: getPosLeftCenter(i, j), top: getPosTopCenter(i, j), "border-radius": radiusSmall, "font-size": getFontSize(num), "line-height": cellWidth }); } else{ numberCell.css({ width: cellWidth, height: cellWidth, left: getPosLeft(i, j), top: getPosTop(i, j), background: getNumberBackgroundColor(num), color: getNumberColor(num), "border-radius": radiusSmall, "font-size": getFontSize(num), "line-height": cellWidth });查看全部
-
function generateOneNumber(){ var empty = findEmpty(); var len = empty.length; if(len > 0){ //随机一个位置 var pos = empty[Math.floor(Math.random() * len)]; var i = pos.x; var j = pos.y; //随机一个数字,2或4 var num = Math.random() < 0.5 ? 2 : 4; //在该位置显示该数字 board[i][j] = num; showNumWithAnimation(i, j, num); } } function findEmpty(){ var empty = []; var k = 0; for(var i = 0; i < 4; i++){ for(var j = 0; j < 4; j++){ if(board[i][j] == 0){ empty[k++] = { x: i, y: j } } } } return empty; }查看全部
-
function hasNoBlockHorizontal(row, start, end){ for(var j = start + 1; j < end; j++){ if(board[row][j] != 0){ return false; } } return true; } function hasNoBlockVertical(col, start, end){ for(var i = start + 1; i < end; i++){ if(board[i][col] != 0){ return false; } } return true; } function updateScore(score){ $("#score").text(score); } function newGame(){ //初始化 init(); //在随机两个格子上生成数字 generateOneNumber(); generateOneNumber(); } function init(){ for(var i = 0; i < 4; i++){ board[i] = []; hasConflicted[i] = []; for(var j = 0; j < 4; j++){ $("#grid-cell-" + i + '-' + j).css({ left: getPosLeft(i, j), top: getPosTop(i, j) }); board[i][j] = 0; hasConflicted[i][j] = false; } } updateBoardView(); score = 0; }查看全部
举报
0/150
提交
取消