<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>拼图游戏</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
a{
color:#FF0000;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
body{
background-repeat:no-repeat;
font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
height:100%;
width:100%;
margin:10px;
padding-left:0px;
text-align:left;
}
#puzzle_container{
line-height:500px;
text-align:center;
vertical-align:center;
border:10px outset #CCCCCC;
position:relative;
color: #FFFFFF;
background-color: #707070;
width: 520px; /* IE 5.x */
width/* */:/**/500px; /* Other browsers */
width: /**/500px;
height: 520px; /* IE 5.x */
height/* */:/**/500px; /* Other browsers */
height: /**/500px;
}
#puzzle_container .square{
overflow:hidden;
border-left:1px solid #FFF;
border-top:1px solid #FFF;
position:absolute;
}
.activeImageIndicator{
border:1px solid #FF0000;
position:absolute;
z-index:10000;
}
.revealedImage{
position:absolute;
left:0px;
opacity:0;
filter:alpha(opacity=50);
top:0px;
z-index:50000;
}
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 188px;
top: 94px;
}
#Layer2 {
position:absolute;
width:416px;
height:27px;
z-index:2;
top: 60px;
left: 251px;
}
.STYLE1 {color: #003366}
.STYLE2 {color: #339966}
.STYLE3 {
font-size: 36px;
font-weight: bold;
}
</style>
<script type="text/javascript">
var puzzleImages = ['images/cf.jpg','images/SG.jpg'];
var rows = 3;
var cols = 4;
var imageArray = new Array();
var imageInUse = false;
var puzzleContainer;
var activeImageIndicator = false;
var activeSquare = false; // Reference to active puzzle square
var squareArray = new Array(); // Array with references to all the squares
var emptySquare_x;
var emptySquare_y;
var colWidth;
var rowHeight;
var gameInProgress = false;
var revealedImage = false;
for(var no=0;no<puzzleImages.length;no++){
imageArray[no] = new Image();
imageArray[no].src = puzzleImages[no];
}
function initPuzzle()
{
gameInProgress = false;
var tmpInUse = imageInUse;
imageInUse = imageArray[Math.floor(Math.random() * puzzleImages.length)];
if(imageInUse==tmpInUse && puzzleImages.length>1)
initPuzzle();
else{
puzzleContainer = document.getElementById('puzzle_container');
getImageWidth();
}
}
function getImageWidth()
{
if(imageInUse.width>0){
startPuzzle();
}else{
setTimeout('getImageWidth()',100);
}
}
function scramble()
{
gameInProgress = true;
var currentRow = cols-1;
var currentCol = rows-1;
document.getElementById('revealedImage').style.display='none';
for(var no=0;no<rows;no++){
for(var no2=0;no2<cols;no2++){
if(no<rows.length || no2<cols.length){
var el = document.getElementById('square_' + no2 + '_' + no);
if(el){
el.style.left = (no2 * colWidth) + (no2) + 'px';
el.style.top = (no * rowHeight) + (no) + 'px';
}else{
initPuzzle();
return;
}
}
}
}
var lastPos=false;
var countMoves = 0;
while(countMoves<(50*cols*rows)){
var dir = Math.floor(Math.random()*4);
var readyToMove = false;
if(dir==0 && currentRow>0 && lastPos!=1){ // Moving peice down
currentRow = currentRow-1;
readyToMove = true;
}
if(dir==1 && currentRow<(rows-1) && lastPos!=0){ // Moving peice up
currentRow = currentRow+1;
readyToMove = true;
}
if(dir==2 && currentCol>0 && lastPos!=3){ // Moving peice right
currentCol = currentCol -1;
readyToMove = true;
}
if(dir==3 && currentCol<(cols-1) && lastPos!=2){ // Moving peice right
currentCol = currentCol + 1;
readyToMove = true;
}
if(readyToMove){
activeSquare = document.getElementById('square_' + currentCol + '_' + currentRow);
moveImage(false,true);
lastPos = dir;
countMoves++;
}
}
return;
}
function gameFinished()
{
var string = "";
var squareWidth = colWidth + 1;
var squareHeight = rowHeight + 1;
var squareCounter = 0;
var errorsFound = false;
var correctSquares = 0;
for(var prop in squareArray){
var currentCol = squareCounter % cols;
var currentRow = Math.floor(squareCounter/cols);
var correctLeft = currentCol * squareWidth;
var correctTop = currentRow * squareHeight;
if(squareArray[prop].style.left.replace('px','') != correctLeft || squareArray[prop].style.top.replace('px','') != correctTop){
//return;
}else{
correctSquares++;
}
squareCounter++;
}
if(correctSquares == ((cols * rows) -1)){
document.getElementById('messageDiv').innerHTML = '<h2>Fantastic! You did it!</h2>';
gameInProgress = false;
revealImage();
}else{
document.getElementById('messageDiv').innerHTML = 'Currently, you have ' + correctSquares + ' out of ' + ((cols * rows) -1) + ' pieces placed correctly';
}
}
var currentOpacity = 0;
function revealImage()
{
if(currentOpacity==100)currentOpacity=0;
var obj = document.getElementById('revealedImage');
obj.style.display = 'block';
currentOpacity = currentOpacity +2;
if(document.all){
obj.style.filter = 'alpha(opacity='+currentOpacity+')';
}else{
obj.style.opacity = currentOpacity/100;
}
if(currentOpacity<100)setTimeout('revealImage()',10);
}
function displayActiveImage()
{
if(!gameInProgress)return;
if(!activeImageIndicator){
activeImageIndicator = document.createElement('DIV');
activeImageIndicator.className = 'activeImageIndicator';
puzzleContainer.appendChild(activeImageIndicator);
activeImageIndicator.onclick = moveImage;
}
activeImageIndicator.style.display='block';
activeImageIndicator.style.left = this.offsetLeft + 'px';
activeImageIndicator.style.top = this.offsetTop + 'px';
activeImageIndicator.style.width = this.style.width;
activeImageIndicator.style.height = this.style.height;
activeImageIndicator.innerHTML = '<span></span>';
activeSquare = this;
}
function moveImage(e,fromShuffleFunction)
{
if(!activeSquare)return;
if(!gameInProgress && !fromShuffleFunction){
alert('You have to shuffle the cards first');
return;
}
var currentLeft = activeSquare.style.left.replace('px','') /1;
var currentTop = activeSquare.style.top.replace('px','') /1;
var diffLeft = Math.round((currentLeft - emptySquare_x) / colWidth);
var diffTop = Math.round((currentTop - emptySquare_y) / rowHeight);
if(((diffLeft==-1 || diffLeft==1) && diffTop==0) || ((diffTop==-1 || diffTop==1) && diffLeft==0)){ // Moving right
activeSquare.style.left = emptySquare_x + 'px';
activeSquare.style.top = emptySquare_y + 'px';
emptySquare_x = currentLeft;
emptySquare_y = currentTop;
activeSquare = false;
if(activeImageIndicator)activeImageIndicator.style.display = 'none';
if(!fromShuffleFunction)gameFinished();
}
}
function startPuzzle()
{
puzzleContainer.innerHTML = '';
var subDivs = puzzleContainer.getElementsByTagName('DIV');
for(var no=0;no<subDivs.length;no++){
subDivs[no].parentNode.removeChild(subDivs[no]);
}
activeImageIndicator = false;
squareArray.length = 0;
if(document.getElementById('revealedImage')){
var obj = document.getElementById('revealedImage');
obj.parentNode.removeChild(obj);
}
var revealedImage = document.createElement('DIV');
revealedImage.style.display='none';
revealedImage.id='revealedImage';;
revealedImage.className='revealedImage';;
var img = document.createElement('IMG');
img.src = imageInUse.src;
revealedImage.appendChild(img);
p
没有合适的资源?快使用搜索试试~ 我知道了~
dreamover个人主页设计
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共94个文件
gif:51个
jpg:30个
html:9个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 9 38 下载量 187 浏览量
2009-12-29
16:45:38
上传
评论 1
收藏 8.41MB RAR 举报
温馨提示
个人主页 内容齐全 跟QQ空间相近!保证你下载后满意。不齐全的自己可以稍微添加就好
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![slx](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/SWF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
共 94 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/deb2c39282e541449c5b3422434bb81f_xiaoamge995.jpg!1)
xiaoamge995
- 粉丝: 4
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)