| キャラの場所の変更 |
| A地点からB地点への変更処理 |

.container{
position: sticky;
}
.layer{
width: 200px;
height: 200px;
position: absolute;
}
.layer1{
top: 0px;
left: 150px;
z-index:1;
}
.layer2{
width: 50px;
height: 50px;
}
copy
let index = 0;
const aryX=[150,150,150,150,100,50,0,0,0,0];
const aryY=[0,50,100,150,150,150,150,100,50,0];
intiMap();
//マップの通り道を設定
function intiMap()
{
//通り道
for(i=0; i < aryX.length; i++)
{
const obj = document.getElementById("map"+i);
obj.style.left = aryX[i] +'px';
obj.style.top = aryY[i] +'px';
}
//ひよこを初期位置にします
moveChick()
}
const b1 = document.getElementById("btn1");
b1.addEventListener("click", () =>
{
//サイコロを振る
diceNumber();
});
const b2 = document.getElementById("btn2");
b2.addEventListener("click", () =>
{
//リセット
mapReset();
});
//サイコロを振る
function diceNumber()
{
//サイコロの目を取得
let number = dice();
//サイコロを表示
displayDice(number);
index += number;
//ゴール判定処理
judgeGoal();
}
//ゴール判定処理
function judgeGoal()
{
if(index >= 9)
{
//最後の位置にします
index=9;
}
//ひよこを移動します。
moveChick();
setTimeout(() =>
{
if(index < 9)
{
return;
}
//ボタンを非表示にします。
const b1 = document.getElementById("btn1");
b1.style.visibility="hidden";
//ゴールのメッセージを表示します。
alert("おめでとうございます。\nゴールしました。");
}, 0);
}
//サイコロの目を取得
function dice()
{
const start = 1;
const end = 6;
//指定の範囲の整数を返します
return Math.floor(Math.random() * (end - start + 1)) + start;
}
//サイコロを表示
function displayDice(number)
{
//サイコロの画像は準備してください
let file = "";
switch(number)
{
case 1:
file = "dice1.png";
break;
case 2:
file = "dice2.png";
break;
case 3:
file = "dice3.png";
break;
case 4:
file = "dice4.png";
break;
case 5:
file = "dice5.png";
break;
case 6:
file = "dice6.png";
break;
}
const img = document.getElementById("dice");
img.src = img;
}
//ひよこの場所変更
function moveChick()
{
//ひよこ
const obj = document.getElementById("hiyoko");
obj.style.left = aryX[index] +'px';
obj.style.top = aryY[index] +'px';
}
//リセット
function mapReset()
{
index = 0;
moveChick();
const b1 = document.getElementById("btn1");
b1.style.visibility="visible";
}
| [URL]イラスト:農民イラスト | |
| URL[https://nawmin.stores.jp][クリックすると開きます]) |
| Change the character's location |
| Processing a change from point A to point B |

.container{
position: sticky;
}
.layer{
width: 200px;
height: 200px;
position: absolute;
}
.layer1{
top: 0px;
left: 150px;
z-index:1;
}
.layer2{
width: 50px;
height: 50px;
}
copy
let index = 0;
const aryX=[150,150,150,150,100,50,0,0,0,0];
const aryY=[0,50,100,150,150,150,150,100,50,0];
intiMap();
//Set the map route
function intiMap()
{
//path
for(i=0; i < aryX.length; i++)
{
const obj = document.getElementById("map"+i);
obj.style.left = aryX[i] +'px';
obj.style.top = aryY[i] +'px';
}
//Set the chick to its initial position
moveChick()
}
const b1 = document.getElementById("btn1");
b1.addEventListener("click", () =>
{
//Roll the dice
diceNumber();
});
const b2 = document.getElementById("btn2");
b2.addEventListener("click", () =>
{
//Reset
mapReset();
});
//Roll the dice
function diceNumber()
{
//Get the number on the dice
let number = dice();
//Show Dice
displayDice(number);
index += number;
//Goal determination process
judgeGoal();
}
//Goal determination process
function judgeGoal()
{
if(index >= 9)
{
//Make it the last position
index=9;
}
//Move the chick.
moveChick();
setTimeout(() =>
{
if(index < 9)
{
return;
}
//Hide the button.
const b1 = document.getElementById("btn1");
b1.style.visibility="hidden";
//Shows the goal message。
alert("Congratulations! \nreached the goal.");
}, 0);
}
//Get the number on the dice
function dice()
{
const start = 1;
const end = 6;
//Returns an integer in the specified range
return Math.floor(Math.random() * (end - start + 1)) + start;
}
//Show Dice
function displayDice(number)
{
//Please prepare a picture of the dice
let file = "";
switch(number)
{
case 1:
file = "dice1.png";
break;
case 2:
file = "dice2.png";
break;
case 3:
file = "dice3.png";
break;
case 4:
file = "dice4.png";
break;
case 5:
file = "dice5.png";
break;
case 6:
file = "dice6.png";
break;
}
const img = document.getElementById("dice");
img.src = img;
}
//Change chick location
function moveChick()
{
//chick
const obj = document.getElementById("hiyoko");
obj.style.left = aryX[index] +'px';
obj.style.top = aryY[index] +'px';
}
//Reset
function mapReset()
{
index = 0;
moveChick();
const b1 = document.getElementById("btn1");
b1.style.visibility="visible";
}
| [URL]illustration by nawmin.com | |
| URL[https://nawmin.stores.jp][click to open the homepage]) |
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |