修改moveship.js:
var shipposition1=0;//代表船上的位置1没人
var shipposition2=0;//代表船上的位置2没人
var arr = [1,1,1,1,1,1,1,1];//初始化左侧位置,1代表有人。每个位置对应一人。
var arr2=[0,0,0,0,0,0,0,0];//初始化右侧位置,0代表没有人。每个位置对应一人。
var div01;//位置1上的人
var div02;//位置2上的人
var moveToRight=0;
//妈妈不在,爸爸打儿子
function judge(){
if(arr[0]==arr[1]&&arr[1]==arr[6]&&arr[0]==1){
alert("只有爸爸妈妈警察能开船!");
return 1;//提示不能开船
}
if(arr[1]==0 && arr[0]==1&& arr[2]==1){
alert("妈妈不在,爸爸打儿子!");
return 1;
}
else if(arr[1]==0&arr[0]==1&arr[3]==1){
alert("妈妈不在,爸爸打儿子!");
return 1;
}
else if(arr[0]==0 && arr[1]==1&& arr[4]==1){
alert("爸爸不在,妈妈打女儿!");
return 1;
}
else if(arr[0]==0&arr[1]==1&arr[5]==1){
alert("爸爸不在,妈妈打女儿!");
return 1;
}
else if(arr[6]==0 && arr[7]==1){
alert("警察不在,匪徒杀人!");
return 1;
}
}
<!--上船/下船-->
function upship(div11){
//上船
var div1=document.getElementById(div11);
if(div1.style.marginLeft=="0px"||div1.style.marginLeft==""){
if(shipposition1==1&shipposition2==1){
return alert("船上人已满!");
}
div1.style.marginTop="600px";
if(shipposition1==0){
div1.style.marginLeft="210px";
shipposition1=1;
div01=div11;
}
else if(shipposition2==0){
div1.style.marginLeft="110px";
shipposition2=1;
div02=div11;
}
else{
alert('船上人已满!');
}
}
//左侧下船
else if(div1.style.marginLeft=="210px"||div1.style.marginLeft=="110px"){
if(div1.style.marginLeft=="210px"){
shipposition1=0;
}
else if(div1.style.marginLeft=="110px"){
shipposition2=0;
}
if(div11=="div1"){
div1.style.marginTop=0;
//alert(arr[0]);
}
else if(div11=="div2"){
div1.style.marginTop="100px";
}
else if(div11=="div3"){
div1.style.marginTop="200px";
}
else if(div11=="div4"){
div1.style.marginTop="300px";
}
else if(div11=="div5"){
div1.style.marginTop="400px";
}
else if(div11=="div6"){
div1.style.marginTop="500px";
}
else if(div11=="div7"){
div1.style.marginTop="600px";
}
else if(div11=="div8"){
div1.style.marginTop="700px";
}
div1.style.marginLeft=0;
}
//右侧下船
else if(div1.style.marginLeft=="450px"||div1.style.marginLeft=="550px"){
if(div1.style.marginLeft=="550px"){
shipposition1=0;
}
else if(div1.style.marginLeft=="450px"){
shipposition2=0;
}
if(div11=="div1"){
div1.style.marginTop=0;
//alert(arr[0]);
}
else if(div11=="div2"){
div1.style.marginTop="100px";
}
else if(div11=="div3"){
div1.style.marginTop="200px";
}
else if(div11=="div4"){
div1.style.marginTop="300px";
}
else if(div11=="div5"){
div1.style.marginTop="400px";
}
else if(div11=="div6"){
div1.style.marginTop="500px";
}
else if(div11=="div7"){
div1.style.marginTop="600px";
}
else if(div11=="div8"){
div1.style.marginTop="700px";
}
div1.style.marginLeft="650px";
}
}
<!--爸爸上船-->
function fathermove1(){
upship("div1");
if(arr[0]==1){
arr[0]=0;
}
else{
arr[0]=1;
}
//alert(arr[0]);
}
<!--妈妈上船-->
function mothermove1(){
upship("div2");
if(arr[1]==1){
arr[1]=0;
}
else{
arr[1]=1;
}
}
<!--儿子一上船-->
function son1move(){
upship("div3");
}
<!--儿子二上船-->
function son2move(){
upship("div4");
}
<!--女儿一上船-->
function daughter1move(){
upship("div5");
}
<!--女儿二上船-->
function daughter2move(){
upship("div6");
}
<!--警察上船-->
function policemanmove(){
var div7=document.getElementById("div7");
if(div7.style.marginLeft=="0px"||div7.style.marginLeft=="110px"||div7.style.marginLeft=="210px"||div7.style.marginLeft==""){
alert("3333");
upship("div7");
if(arr[6]==1){
arr[6]=0;
}
else{
arr[6]=1;
}
}
/*if(div7.style.marginLeft=="650px"){
alert("2222222");
}
if(div7.style.marginLeft=="550px"){
alert("44444");
}*/
}
<!--匪徒上船-->
function banditmove(){
upship("div8");
if(arr[7]==1){
arr[7]=0;
}
else{
arr[7]=1;
}
}
function moveship(){
if(moveToRight==0){
if(judge()==1)
{
return;
}
else{
var div10=document.getElementById("div10");
var div9=document.getElementById("div9");
var div1=document.getElementById(div01);
var div2=document.getElementById(div02);
if(div10.style.marginLeft=="400px"){
div9.style.marginLeft="100px";
div10.style.marginLeft="120px";
div1.style.marginLeft="210px";
div2.style.marginLeft="110px";
}
else{
div9.style.marginLeft="400px";
div10.style.marginLeft="400px";
div1.style.marginLeft="550px";
div2.style.marginLeft="450px";
}
}
moveToRight=1;
return;
}
else{
alert("1111111111111111");
if(judge2()==1)
{
return;
}
moveToRight=0;
return;
}
}