課程
/前端開發
/WebApp
/慕課網2048私人訂制
求幫我解決一下
2015-11-26
源自:慕課網2048私人訂制 2-3
正在回答
那你得給出你的完整代碼。別人才能看出問題。
我的問題找到了,非常感謝你
菜菜say
風之翼hzk
var board = new Array();var score = 0;$(document).ready(function(){ ? ?newgame();});function newgame(){ ? ?//初始化棋盤格 ? ?init(); ? ?//在隨機的兩個格子生成數字 ? ?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]); ? ? ? ? ? ?} ? ? ? ?}}
把代碼帖上來,不要放圖片,給完整。
我下載了老師的代碼,比較了是一樣的,那麻煩你幫我看一下吧,這是main.js的代碼
舉報
慕課網這款“2048私人訂制”通過大神老的講解學習到游戲結構的開發
4 回答代碼和老師一樣的,為什么沒效果,而且越來越大。
2 回答老師 您好 親問一下這句代碼var theNumberCell = $('#number-cell-'+i+'-'+j); 為什么會報錯呢
2 回答代碼一樣的,但是并沒有隨機生成兩個數字???求大神
1 回答向下函數的代碼里面的board[k]報錯,我輸出后顯示undefined,為什么會這樣,左上右都是正常的
2 回答代碼是什么?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-11-26
那你得給出你的完整代碼。別人才能看出問題。
2015-11-26
我的問題找到了,非常感謝你
2015-11-26
var board = new Array();
var score = 0;
$(document).ready(function(){
? ?newgame();
});
function newgame(){
? ?//初始化棋盤格
? ?init();
? ?//在隨機的兩個格子生成數字
? ?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
把代碼帖上來,不要放圖片,給完整。
2015-11-26
我下載了老師的代碼,比較了是一樣的,那麻煩你幫我看一下吧,這是main.js的代碼