Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

java - Creating a Ludo game

I've been given an assignment the hand in on Wednesday and it is to create a Ludo game. I have the jist of everything working but I cannot figure out how to make the player pawns take a set path. so obviously the board is in a + looking shape and the pawns move around the board. Is there anyway I can set it so that they all follow that path.

My idea would be to have a int[][] pos of each "tile" and depending on which player you are, it starts at a different position in the list. So e.g:

pos[0][5]
pos[5][10]<First tile a red pawn should start
pos[10][15]
pos[15][20]<First tile  a blue pawn should start
pos[20][25]

and then loop through this list of positions until the win condition is satisfied. This is my idea but I was hoping there maybe another way

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As Daan van der Kallen mentioned, for games which include tiles and multiple pieces, you can implement a tile class which can keep track of the pieces on that tile. For Ludo, you may want a subclass for tiles in the home run which only red/blue/... can travel on. Maybe a home tile which is the finish place as well as a "start"/"park"/[I've heard many names given to this tile, so depends on your version of Ludo] tile (where the pieces start and return to).

This will also allow you to display each tile for later, and can also help you implement certain rules e.g. 2 blue on a tile does not allow other colours through. etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...