Hello, I am very new to Greenfoot, and programming in general. I am working on a project in which I am making a game with the same concept as snakes and ladders. This is what my board looks like : https://imgur.com/YAptEIS
Here's the run-down of how the program works. The user clicks a button, which will begin the game. Each player will click on their pre-selected game pieces, which will then move to the start position. From there, each player rolls a die, and their game piece will move 100 pixels to the right if they roll a 1, 200 if they roll a 2, and so on up to 6 and 600.
Now the issue that I am having is that, let's say the user's game piece is on square 8...and they roll a 6, what do I do to my code, so that the game piece moves right, up, and then left to square 14. Below is my code, sorry for the long and repetitive code...
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.*;
public class GameBoard extends World
{
private DiceRoll dice = new DiceRoll();
Hippo p1 = new Hippo();
Wombat p2 = new Wombat();
Pelican p3 = new Pelican();
Fish p4 = new Fish();
Spider p5 = new Spider();
int[][] gridPositionX = {{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250},
{350, 450, 550, 650, 750, 850, 950, 1050, 1150, 1250}};
int[] gridPositionY = {80, 180, 280, 380, 480, 580, 680, 780, 880, 980};
public GameBoard()
{
super(1350, 1050, 1);
addObject(new Start_Button(), 215, 200);
addObject(new PlayerOne(), 85, 350);
addObject(p1, 200, 350);
addObject(new PlayerTwo(), 85, 430);
addObject(p2, 200, 430);
addObject(new PlayerThree(), 85, 510);
addObject(p3, 200, 510);
addObject(new PlayerFour(), 85, 590);
addObject(p4, 200, 590);
addObject(new PlayerFive(), 85, 670);
addObject(p5, 200, 670);
addObject(new Welcome(), 150, 65);
addObject(new ClickHere(), 94, 200);
//addObject(new DiceRoll(), 125, 840);
addObject(dice, 125, 840);
addObject(new RollDie(), 130, 770);
addObject(new Start(), 228, 930);
}
public void act()
{
if(Greenfoot.mouseClicked(dice))
{
int rollValue = dice.roll();
JOptionPane.showMessageDialog(new JInternalFrame(), "You have rolled a: " + rollValue,"Dice Roll", JOptionPane.INFORMATION_MESSAGE);
if (rollValue == 1)
{
//p1.setLocation(350, 980);
p1.move(100);
}
if (rollValue == 2)
{
//p1.setLocation(450, 980);
p1.move(200);
}
if (rollValue == 3)
{
//p1.setLocation(550, 980);
p1.move(300);
}
if (rollValue == 4)
{
//p1.setLocation(650, 980);
p1.move(400);
}
if (rollValue == 5)
{
//p1.setLocation(750, 980);
p1.move(500);
}
if (rollValue == 6)
{
//p1.setLocation(850, 980);
p1.move(600);
}
if (p1.getX() == gridPositionX[9][0] && p1.getY() == gridPositionY[9])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[6][2], gridPositionY[6]);
}
if (p1.getX() == gridPositionX[9][3] && p1.getY() == gridPositionY[9])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[8][6], gridPositionY[8]);
}
if (p1.getX() == gridPositionX[9][8] && p1.getY() == gridPositionY[9])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[6][9], gridPositionY[6]);
}
if (p1.getX() == gridPositionX[8][3] && p1.getY() == gridPositionY[8])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[9][5], gridPositionY[9]);
}
if (p1.getX() == gridPositionX[7][0] && p1.getY() == gridPositionY[7])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[5][1], gridPositionY[5]);
}
if (p1.getX() == gridPositionX[7][7] && p1.getY() == gridPositionY[7])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[1][3], gridPositionY[1]);
}
if (p1.getX() == gridPositionX[4][9] && p1.getY() == gridPositionY[4])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[3][6], gridPositionY[3]);
}
if (p1.getX() == gridPositionX[4][6] && p1.getY() == gridPositionY[4])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[6][6], gridPositionY[6]);
}
if (p1.getX() == gridPositionX[3][1] && p1.getY() == gridPositionY[3])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[8][1], gridPositionY[8]);
}
if (p1.getX() == gridPositionX[3][3] && p1.getY() == gridPositionY[3])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[4][0], gridPositionY[4]);
}
if (p1.getX() == gridPositionX[2][8] && p1.getY() == gridPositionY[2])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[0][9], gridPositionY[0]);
}
if (p1.getX() == gridPositionX[2][0] && p1.getY() == gridPositionY[2])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[0][1], gridPositionY[1]);
}
if (p1.getX() == gridPositionX[1][6] && p1.getY() == gridPositionY[1])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[6][4], gridPositionY[6]);
}
if (p1.getX() == gridPositionX[0][7] && p1.getY() == gridPositionY[0])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[2][7], gridPositionY[2]);
}
if (p1.getX() == gridPositionX[0][5] && p1.getY() == gridPositionY[0])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[2][2], gridPositionY[2]);
}
if (p1.getX() == gridPositionX[0][2] && p1.getY() == gridPositionY[0])
{
Greenfoot.delay(50);
p1.setLocation(gridPositionX[2][1], gridPositionY[2]);
}
}
}
}

