Question: I need to do this in C Color.c #include #include color.h /* Prints the entire string in red */ void printColor(char * string, char *

I need to do this in C

I need to do this in C Color.c #include #include "color.h" /*

Color.c

#include

#include "color.h"

/*

Prints the entire string in red

*/

void printColor(char * string, char * color)

{

printf("%s%s%s", color, string, ANSI_COLOR_RESET);

}

/*

Prints the string in red from i through j indices

*/

void printSubstringRed(char string[], int i, int j, char * color)

{

int k = 0;

printf("%s", color);

for(k = i; k

{

printf("%c", string[k]);

}

printf("%s", ANSI_COLOR_RESET);

}

void printColorSubstring(char string[], int i, int j, int ri, int rj, char * color)

{

int k = 0;

// print up to i,j

for(k = i; k

{

printf("%c", string[k]);

}

printf("%s", color);

// print the substring

for(; k

{

printf("%c", string[k]);

}

printf("%s", ANSI_COLOR_RESET);

for(; k

{

printf("%c", string[k]);

}

}

Color.H

#ifndef RED_H #define RED_H

// These are preprocessor directives which tell the compiler to turn the color on the console a certain // color when it sees them in code #define COLOR_RED "\x1b[31m" #define COLOR_GREEN "\x1b[32m" #define COLOR_YELLOW "\x1b[33m" #define COLOR_BLUE "\x1b[34m" #define COLOR_MAGENTA "\x1b[35m" #define COLOR_CYAN "\x1b[36m" #define ANSI_COLOR_RESET "\x1b[0m"

void printColor(char * string, char * color); void printSubstringColor(char string[], int i, int j, char * color);

#endif

What I have so far (main.c)

#include

#include

#include

#include

struct superHero

{

char name [100];

double strength;

double charisma;

double intelligence;

double totalHealth;

};

struct Villains

{

char name [100];

double strength;

double charisma;

double intelligence;

double totalHealth;

int bossLevel;

};

int health (int startHealth, double CA, double SA, double IA, double CD, double SD, double ID)

{

int endHealth;

double hitPoints;

hitPoints = CA/CD + SA/SD + IA/ID;

endHealth = startHealth - ceil(hitPoints);

return endHealth;

}

void printStats(int bossLevel)

{

printf(" Let's Play! ");

printf(" Level: %i ", bossLevel);

printf(" \tCurrent Villain:");

if (bossLevel == 1)

printf(" \t\t\t\tMindEraser");

else if (bossLevel == 2)

printf(" \t\t\t\tAsbestosAlice");

else

printf(" \t\t\t\tBoringBoris");

}

int main()

{

int i;

struct superHero hero[4];

//super man

hero[0].strength = 7;

hero[0].charisma = 2;

hero[0].intelligence = 1;

hero[0].totalHealth = 10;

//batman

hero[1].strength = 2;

hero[1].charisma = 7;

hero[1].intelligence = 1;

hero[1].totalHealth = 10;

//wonder woman

hero[2].strength = 3;

hero[2].charisma = 3;

hero[2].intelligence = 4;

hero[2].totalHealth = 10;

//awesome man

hero[3].strength = 1;

hero[3].charisma = 1;

hero[3].intelligence = 8;

hero[3].totalHealth = 10;

strcpy(hero[0].name, "Superman");

strcpy(hero[1].name, "Batman");

strcpy(hero[2].name, "WonderWoman");

strcpy(hero[3].name, "Awesomeman");

struct Villains villain[3];

//mind eraser - boss level 1

villain[0].strength = 3;

villain[0].charisma = 2;

villain[0].intelligence = 10;

villain[0].totalHealth = 15;

villain[0].bossLevel = 1;

//asbestos alice - boss level 2

villain[1].strength = 10;

villain[1].charisma = 2;

villain[1].intelligence = 3;

villain[1].totalHealth = 15;

villain[1].bossLevel = 2;

//boring boris - boss level 3

villain[2].strength = 2;

villain[2].charisma = 11;

villain[2].intelligence = 2;

villain[2].totalHealth = 15;

villain[2].bossLevel = 1;

strcpy(villain[0].name, "MindEraser");

strcpy(villain[1].name, "AsbestosAlice");

strcpy(villain[2].name, "BoringBoris");

printStats(villain[0].bossLevel);

while(villain[i].totalHealth != 0)

return 0;

}

//while loop and for

Prints the entire string in red */ void printColor(char * string, char* color) { printf("%s%s%s", color, string, ANSI_COLOR_RESET); } /* Prints the stringin red from i through j indices */ void printSubstringRed(char string[], int example output:

i, int j, char * color) { int k = 0; printf("%s",

Coding Requirements You have to use a struct to maintain the name and attribute of the heroes and villains o You should use the same structure for both -simplify your design You should be writing functions for printing statistics, and searching .You should be using string.h for strcpy, and strcmp to initialize the characters, and to find the hero character the game player wants to attack with Suhmission and Grading Coding Requirements You have to use a struct to maintain the name and attribute of the heroes and villains o You should use the same structure for both -simplify your design You should be writing functions for printing statistics, and searching .You should be using string.h for strcpy, and strcmp to initialize the characters, and to find the hero character the game player wants to attack with Suhmission and Grading

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!