課程
/前端開(kāi)發(fā)
/WebApp
/慕課網(wǎng)2048私人訂制
求幫我解決一下
2015-11-26
源自:慕課網(wǎng)2048私人訂制 2-3
正在回答
那你得給出你的完整代碼。別人才能看出問(wèn)題。
我的問(wèn)題找到了,非常感謝你
菜菜say
風(fēng)之翼hzk
var board = new Array();var score = 0;$(document).ready(function(){ ? ?newgame();});function newgame(){ ? ?//初始化棋盤(pán)格 ? ?init(); ? ?//在隨機(jī)的兩個(gè)格子生成數(shù)字 ? ?generateOneNumber(); ? ?generateOneNumber();}function init(){ ? ?for(var i = 0;i < 4;i++) ? ? ? ?for(var j = 0;j<4;j++){ ? ? ? ? ? ?var gridCell = $('#grid-cell-'+i+"-"+j); ? ? ? ? ? ?gridCell.css('top',getPosTop(i,j)); ? ? ? ? ? ?gridCell.css('left',getPosLeft(i,j)); ? ? ? ?} ? ?for(var i = 0;i < 4;i++){ ? ? ? ?board[i] = new Array(); ? ? ? ?for(var j = 0;j < 4;j++){ ? ? ? ? ? ?board[i][j] = 0; ? ? ? ?} ? ?} ? ?updateBoardView();}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 theNumberCell = $('#number-cell-'+i+'-'+j); ? ? ? ? ? ?if(board[i][j]==0){ ? ? ? ? ? ? ? ?theNumberCell.css('width','0px'); ? ? ? ? ? ? ? ?theNumberCell.css('height','0px'); ? ? ? ? ? ? ? ?theNumberCell.css('top',getPosTop(i,j)+50); ? ? ? ? ? ? ? ?theNumberCell.css('left',getPosLeft(i,j)+50); ? ? ? ? ? ?} ? ? ? ? ? ?else{ ? ? ? ? ? ? ? ?theNumberCell.css('width','100px'); ? ? ? ? ? ? ? ?theNumberCell.css('height','100px'); ? ? ? ? ? ? ? ?theNumberCell.css('top',getPosTop(i,j)); ? ? ? ? ? ? ? ?theNumberCell.css('left',getPosLeft(i,j)); ? ? ? ? ? ? ? ?theNumberCell.css('background-color',getNumberBackgroundColor(board[i][j])); ? ? ? ? ? ? ? ?theNumberCell.css('color',getNumberColor(board[i][j])); ? ? ? ? ? ? ? ?theNumberCell.text(board[i][j]); ? ? ? ? ? ?} ? ? ? ?}}
把代碼帖上來(lái),不要放圖片,給完整。
我下載了老師的代碼,比較了是一樣的,那麻煩你幫我看一下吧,這是main.js的代碼
舉報(bào)
慕課網(wǎng)這款“2048私人訂制”通過(guò)大神老的講解學(xué)習(xí)到游戲結(jié)構(gòu)的開(kāi)發(fā)
4 回答代碼和老師一樣的,為什么沒(méi)效果,而且越來(lái)越大。
2 回答老師 您好 親問(wèn)一下這句代碼var theNumberCell = $('#number-cell-'+i+'-'+j); 為什么會(huì)報(bào)錯(cuò)呢
2 回答代碼一樣的,但是并沒(méi)有隨機(jī)生成兩個(gè)數(shù)字啊?求大神
1 回答向下函數(shù)的代碼里面的board[k]報(bào)錯(cuò),我輸出后顯示undefined,為什么會(huì)這樣,左上右都是正常的
1 回答對(duì)照老師的源代碼了,為啥效果變成只有一個(gè)格子?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-11-26
那你得給出你的完整代碼。別人才能看出問(wèn)題。
2015-11-26
我的問(wèn)題找到了,非常感謝你
2015-11-26
var board = new Array();
var score = 0;
$(document).ready(function(){
? ?newgame();
});
function newgame(){
? ?//初始化棋盤(pán)格
? ?init();
? ?//在隨機(jī)的兩個(gè)格子生成數(shù)字
? ?generateOneNumber();
? ?generateOneNumber();
}
function init(){
? ?for(var i = 0;i < 4;i++)
? ? ? ?for(var j = 0;j<4;j++){
? ? ? ? ? ?var gridCell = $('#grid-cell-'+i+"-"+j);
? ? ? ? ? ?gridCell.css('top',getPosTop(i,j));
? ? ? ? ? ?gridCell.css('left',getPosLeft(i,j));
? ? ? ?}
? ?for(var i = 0;i < 4;i++){
? ? ? ?board[i] = new Array();
? ? ? ?for(var j = 0;j < 4;j++){
? ? ? ? ? ?board[i][j] = 0;
? ? ? ?}
? ?}
? ?updateBoardView();
}
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 theNumberCell = $('#number-cell-'+i+'-'+j);
? ? ? ? ? ?if(board[i][j]==0){
? ? ? ? ? ? ? ?theNumberCell.css('width','0px');
? ? ? ? ? ? ? ?theNumberCell.css('height','0px');
? ? ? ? ? ? ? ?theNumberCell.css('top',getPosTop(i,j)+50);
? ? ? ? ? ? ? ?theNumberCell.css('left',getPosLeft(i,j)+50);
? ? ? ? ? ?}
? ? ? ? ? ?else{
? ? ? ? ? ? ? ?theNumberCell.css('width','100px');
? ? ? ? ? ? ? ?theNumberCell.css('height','100px');
? ? ? ? ? ? ? ?theNumberCell.css('top',getPosTop(i,j));
? ? ? ? ? ? ? ?theNumberCell.css('left',getPosLeft(i,j));
? ? ? ? ? ? ? ?theNumberCell.css('background-color',getNumberBackgroundColor(board[i][j]));
? ? ? ? ? ? ? ?theNumberCell.css('color',getNumberColor(board[i][j]));
? ? ? ? ? ? ? ?theNumberCell.text(board[i][j]);
? ? ? ? ? ?}
? ? ? ?}
}
2015-11-26
把代碼帖上來(lái),不要放圖片,給完整。
2015-11-26
我下載了老師的代碼,比較了是一樣的,那麻煩你幫我看一下吧,這是main.js的代碼