我想知道如何移动我的碎片并用多维数组中的碎片打印回来。我的棋盘游戏没有完成。我不能继续,直到我弄清楚如何用骰子移动阵列中的碎片。 这是我到目前为止我的蛇和梯子棋盘游戏的代码。
//Function to determine if the player wants to play the game or not
function enter(){
var play=prompt("Want to start the game?\n O/N");
if(play=="o"||play=="O"){
table(col1,col2,col3,col4,col5,col6,col7,col8);
var start=prompt("Against System/Player:");
if (start=="Player"||start=="player"){
commencer();
}
else if(start=="System"||start=="system"){
system();
}
}
else if(play=="N"||play=="n"||play==null){
print("If you want to play type enter()");
}
}
//Function to start the game
function commencer(){
alert("The dice will be rolled to determine who will start p1 or p2");
var roll1=reroll();
var roll2=reroll();
var p1=roll1;
var p2=roll2;
alert("P1 rolled: " +roll1+ "\nP2 rolled: " +roll2);
if(p1>p2){
alert("P1 will start...");
player1();
}
else if(p2>p1){
alert("P2 will start...");
}
else
reroll();
}
//Function to start the game with p1
function system(){//function Not done
var p1=prompt("Would you like to roll the dice?\n O/N");
var p1position=1;
var systemposition=1;
var diceroll1=0;
var p1roll=1;
var systemroll=1;
var snakeladder=new Array(8);
snakeladder[0]=col3[5][3];
snakeladder[1]=col8[4][1];
snakeladder[2]=col4[3][2];
snakeladder[3]=col1[2][0];
snakeladder[4]=col3[0][2];
snakeladder[5]=col3[4][1];
snakeladder[6]=col6[3][2];
snakeladder[7]=col7[0][2];
while(p1=="o"||p1=="O"){
p1roll=de();
systemroll=de();
print("P1 a lance:" +p1roll+ "\nSystem a lance:" +systemroll);
p1position+=p1roll;
systemposition+=systemroll;
p1position=getp(p1position,p1roll,snakeladder);
//not done..
}
}
//Function to reroll the dice
function reroll(){
var relancer1=de();
var relancer2=de();
return relancer1 && relancer2;
}
//Function for rolling the dice
function de(){
return Math.floor((Math.random() * 6) + 1);
}
//Function to print the board without the players
function table(col1,col2,col3,col4,col5,col6,col7,col8){
for(var i=0; i<col1.length;i++){
for(var j=0; j<col1[i].length;j++){
print(col1[i][j]+col2[i][j]+col3[i][j]+col4[i][j]+col5[i][j]+col6[i][j]+col7[i][j]+col8[i][j]);
}
}
}
var col1=[[" ___","| |","| |","|___|"],
["| |","| |","|___|","| |"],
["| E |","|___|","| |","| |"],
["|___|","| |","| |","|___|"],
["| |","| |","|___|","| |"],
["| P |","|___|","| |","| |"],
["|___|"]];
var col2=[[" ___"," |"," |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"," |"," |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"]];
var col3=[[" ___"," |", " S |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"," |"," |","___|"],
[" |"," S |","___|"," |"],
[" |","___|"," |"," E |"],
["___|"]];
var col4=[[" ___"," |"," |","___|"],
[" |"," P |","___|"," |"],
[" |","___|"," |"," |"],
["___|"," |"," E |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"]];
var col5=[[" ___"," |"," |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"," |"," |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"]];
var col6=[[" ___"," |"," P |","___|"],
[" |"," |","___|"," |"],
[" P |","___|"," |"," |"],
["___|"," |"," S |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"]];
var col7=[[" ___"," |"," S |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"," |"," |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"]];
var col8=[[" ___"," |"," |","___|"],
[" |"," |","___|"," |"],
[" |","___|"," |"," |"],
["___|"," |"," |","___|"],
[" |"," E |","___|"," |"],
[" |","___|"," |"," |"],
["___|"]];
enter();
这是没有数字的电路板的样子。使用这个侧板作为职位的参考。
c1 c2 c3 c4 c5 c6 c7 c8
___ ___ ___ ___ ___ ___ ___ ___
|64 |63 |62 |61 |60 |59 |58 |57 |
| |E4 |S4 | | | P |S3 | |
|___|___|___|___|___|___|___|___|
|49 |50 |51 |52 |53 |54 |55 |56 |
| | | | P |E3 | | | |
|___|___|___|___|___|___|___|___|
|48 |47 |46 |45 |44 |43 |42 |41 |
|E4 | | | | | P | |S3 |
|___|___|___|___|___|___|___|___|
|33 |34 |35 |36 |37 |38 |39 |40 |
| | | | | | |E2 | |
|___|___|___|___|___|___|___|___|
|32 |31 |30 |29 |28 |27 |26 |25 |
|S4 | | |E3 | |S2 | | |
|___|___|___|___|___|___|___|___|
|17 |18 |19 |20 |21 |22 |23 |24 |
| |E1 |S1 | | | | |E2 |
|___|___|___|___|___|___|___|___|
|16 |15 |14 |13 |12 |11 |10 |9 |
| P | | | | | | | |
|___|___|___|___|___|___|___|___|
| 1 |2 |3 |4 |5 |6 |7 |8 |
| | |E1 | |S1 | | |S2 |
|___|___|___|___|___|___|___|___|