CSS 🛠⛶ BODY { background: #000000; } #stage { position: relative; margin: 0px auto; background: #87e0fd; background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%); background: -webkit-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%); background: linear-gradient(to bottom, #87e0fd 0%,#53cbf1 40%,#05abe0 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0',GradientType=0 ); width: 900px; height: 400px; border-radius: 10px; } .tile { position: absolute; width: 50px; height: 50px; background-color:#07b313; border-radius: 10px; } .coin { position: absolute; width: 30px; height: 30px; margin: 10px; background-color:#E0E800; border-radius: 50%; }
JavaScript ⛶ //Level Generator - www.101computing.net var rows = 8; var cols = 18; var grid = [ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0], [0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0], [0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], [1,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ]; function displayLevel() { var stage = document.getElementById("stage"); for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { if (grid[row][col]==2) { var coin = document.createElement('div'); coin.className = "coin"; coin.style.top = row*50 + 'px'; coin.style.left = col*50 + 'px'; stage.appendChild(coin); } else if (grid[row][col]==1) { var tile = document.createElement('div'); tile.className = "tile"; tile.style.top = row*50 + 'px'; tile.style.left = col*50 + 'px'; //Merge tiles which are next to each other if (col<cols-1) { if (grid[row][col+1]==1) {tile.style.borderBottomRightRadius='0px';tile.style.borderTopRightRadius='0px';}} if (col>0) { if (grid[row][col-1]==1) {tile.style.borderBottomLeftRadius='0px';tile.style.borderTopLeftRadius='0px';}} if (row<rows-1) { if (grid[row+1][col]==1) {tile.style.borderBottomLeftRadius='0px';tile.style.borderBottomRightRadius='0px';}} if (row>0) { if (grid[row-1][col]==1) {tile.style.borderTopLeftRadius='0px';tile.style.borderTopRightRadius='0px';}} //Add tile to the stage stage.appendChild(tile); } } } } displayLevel();