Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm working on a project called treasure hunt game board, where we have to make a 10x10 2d array and there will be 5 treasures and 5 pirates. Whenever the player encounters a treasure, they gain 100, then if they encounter the second one, they gain another 200, and so on. But if they encounter a pirate they lose 100. It should display the total of gold they have each time.

What I have tried:

if(board[x][y] == 'T')
{
    treasureCount++;
    doubloons = doubloons + (treasureCount * 100);
}
else if(board[x][y] == 'P')
{
    pirateCount++;
    doubloons = doubloons - (pirateCount * 100);
}
else if(board[x][y] == 'B')
{
    treasureCount++;
    pirateCount++;
    doubloons = doubloons + (treasureCount * 50);
}
else if(board[x][y] == 'X')
{
Posted
Updated 7-Apr-21 8:01am
v2
Comments
CHill60 7-Apr-21 14:03pm    
So display the value of doubloons. What's the problem?
SeanChupas 7-Apr-21 14:20pm    
And?
Richard MacCutchan 8-Apr-21 4:27am    
You are subtracting too many values when the player encounters a pirate. It should subtract just 100 each time according to your description. And you should add a System.out.print statement at the end of the code block to display the latest data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900