Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C, I am creating a board game. I have to display the board after both computer and human roll the dice to show where

Using C, I am creating a board game. I have to display the board after both computer and human roll the dice to show where the players are on the board. It has to be its own function called printBoard. it must have two parameters and can NOT have a return value (void). the board must be printed like this:

[1] [2] [3] [4] [5] *[6] +[7] [8] [9] [10] +[11] [12]

-[13] [14] +[15] [16] [17] [18] [19] -[20] [21] [22] [23]

The "+", "-", and "*" is because of this:

image text in transcribedI have already implemented what goose, bridge, maze and skull do.

The human player is denoted as $ and the computer player is denoted as %

When the players land on a space, the numbers are not displayed, only the player. If both players are in the same space, the human's character is always shown first.

Heres an example of how it might look while playing the game:

image text in transcribed

#include

#include

#include

#define NUM_GOOSE_SPACES 3

const int gooseSpaces[NUM_GOOSE_SPACES] = {7,11,15};

#define NUM_BRIDGE_SPACES 1

const int bridgeSpaces[NUM_BRIDGE_SPACES] = {6};

#define NUM_MAZE_SPACES 2

const int mazeSpaces[NUM_MAZE_SPACES] = {13,20};

#define NUM_SKULL_SPACES 1

const int skullSpaces[NUM_SKULL_SPACES] = {23};

#define WON 0

#define LOSE 1

int rollDice(void);

int playGame(void);

int rollDice(void) {

return ((rand() % 6) + 1);

}

int playGame(void)

{

int dice_1 = 0;

int dice_2 = 0;

int dice_3 = 0;

int dice_4 = 0;

int humanPlayer;

int computerPlayer;

int humanSum = 0;

int computerSum = 0;

int humanTotal = 0;

int computerTotal = 0;

int result;

int point = 0;

time_t t;

bool playForPoint = false;

srand(time(&t)); // Initialize random seed

while(humanTotal

{

printf("ROLL THE DICE WITH [ENTER] ");

fgetc(stdin);

dice_1 = rollDice();

dice_2 = rollDice();

dice_3 = rollDice();

dice_4 = rollDice();

humanSum = dice_1 + dice_2;

computerSum = dice_3 + dice_4;

printf("Dice 1:%2d Dice 2:%2d : Total Dice Count:%2d ", dice_1, dice_2, humanSum);

printf("Dice 1:%2d Dice 2:%2d : Total Dice Count:%2d ", dice_3, dice_4, computerSum);

humanTotal = humanSum + humanTotal;

computerTotal = computerSum + computerTotal;

printf("Human on space : %2d ",humanTotal);

printf("Computer on space : %2d ", computerTotal);

if (humanTotal == gooseSpaces[0] || humanTotal == gooseSpaces[1] || humanTotal == gooseSpaces[2])

{

printf("You landed on a Goose! You must move your piece an extra : %2d spaces ", humanSum);

humanTotal = humanTotal + humanSum;

printf("Human is now on space: %2d ", humanTotal);

}

if(computerTotal ==gooseSpaces[0] || computerTotal == gooseSpaces[1] || computerTotal == gooseSpaces[2])

{

printf("Computer landed on a Goose! Computer must move your piece an extra : %2d spaces ", computerSum);

computerTotal = computerTotal + computerSum;

printf("Computer is now on space: %2d ", computerTotal);

}

if(humanTotal == bridgeSpaces[0])

{

humanTotal = 12;

printf("You landed on Bridge! You must move your piece to space : %2d ", humanTotal);

}

if(computerTotal == bridgeSpaces[0])

{

computerTotal = 12;

printf("Computer landed on Bridge! Computer must move your piece to space : %2d ", computerTotal);

}

if(humanTotal == mazeSpaces[0] || humanTotal == mazeSpaces[1])

{

humanTotal = humanTotal - humanSum;

printf("You landed on the Maze! You must go back to your previous space : %2d ", humanTotal);

}

if(computerTotal == computerTotal == mazeSpaces[0] || computerTotal == mazeSpaces[1])

{

computerTotal = computerTotal - computerSum;

printf("Computer landed on the Maze! Computer must go back to your previous space : %2d ", computerTotal);

}

if(humanTotal == skullSpaces[0])

{

humanTotal = 0;

printf("You landed on the skull! You must return back to the beginning! You are now at space : %2d ", humanTotal);

}

if(computerTotal == skullSpaces[0])

{

computerTotal = 0;

printf("Computer landed on the skull! Computer must return back to the beginning! Computer is now at space : %2d ", computerTotal);

}

if (humanTotal > 24)

{

humanTotal = 24 / humanSum;

printf("You have gone past 24, and your place will be deducted");

printf("You are now on space : %2d ", humanTotal);

}

if (computerTotal > 24)

{

computerTotal = 24 / computerSum;

printf("You have gone past 24, and your place will be deducted");

printf("You are now on space : %2d ", computerTotal);

}

}

}

int main (void){

int result = playGame();

switch ( result )

{

case WON:

printf("You won the game. ");

break;

case LOSE:

printf("You lost the game. ");

break;

default:

printf("Something went wrong in the program. ");

break;

}

return 0;

}

Symbol Spaces Action goose 7, 11, 15 move your piece again by the same distance bridge go to space 12 maze 13,20 go back to your previous space skull 23 return to the beginning | [] [2] [3] [4] [5] *[6] + [7] [8] [9] [$] + [11] [12] - [13] [14] + [15] [16] [17] [18] [19] - [20] [21] [22] ![23] Symbol Spaces Action goose 7, 11, 15 move your piece again by the same distance bridge go to space 12 maze 13,20 go back to your previous space skull 23 return to the beginning | [] [2] [3] [4] [5] *[6] + [7] [8] [9] [$] + [11] [12] - [13] [14] + [15] [16] [17] [18] [19] - [20] [21] [22] ![23]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions

Question

Name and describe two anxiety disorders.

Answered: 1 week ago