Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <stdbool.h>
- struct player {
- char name[20];
- float health;
- float attack;
- int level;
- float media;
- int age;
- bool defeated;
- };
- void remove_all_chars(char* str, char c) { //http://stackoverflow.com/questions/9895216/how-to-remove-all-occurrences-of-a-given-character-from-string-in-c
- char *pr = str, *pw = str;
- while (*pr) {
- *pw = *pr++;
- pw += (*pw != c);
- }
- *pw = '\0';
- }
- struct player player = {
- .health = 100,
- .attack = 10,
- .level = 1,
- .media = 10,
- .defeated = false
- };
- struct player otavio = {
- .health = 100,
- .defeated = false
- };
- struct player toninho = {
- .health = 100,
- .level = 4,
- .defeated = false
- };
- int i, room, levelToninho = 1;
- time_t timerStart;
- char topico[3];
- bool gameStarted = false, gameWon = false;
- void damage(struct player *a, float damage) {
- a->health -= damage;
- if (a->health <= 0) {
- a->health = 0;
- a->defeated = true;
- }
- }
- void printTitle(bool clearScreen) {
- if (clearScreen)
- system("cls");
- printf("************************************"); if(gameStarted) printf(" Nome: %s", player.name); printf("\n");
- printf("** **"); if(gameStarted) printf(" Idade: %i", player.age); printf("\n");
- printf("** WELCOME TO THE **"); if(gameStarted) printf(" Level: %i", player.level); printf("\n");
- printf("** EDILSON'S SURVIVING **"); if(gameStarted) printf(" HP: %.0f", player.health); printf("\n");
- printf("** ADVENTURE **"); if(gameStarted) printf(" Media: %.1f", player.media); printf("\n");
- printf("** **"); if(gameStarted) printf(" Ataque: %.1f", player.attack); printf("\n");
- printf("************************************"); printf("\n");
- }
- void printRooms() {
- printf("\nEscolha uma sala para entrar:\n\n");
- printf("************** ************** \n");
- printf("************** ************** \n");
- printf("*** OTAVIO *** *** TONINHO ** \n");
- printf("*** SALA 1 *** *** SALA 2 *** \n");
- printf("************** ************** \n");
- printf("**********( )* **********( )* \n");
- printf("************** ************** \n");
- printf("************** ************** \n");
- roomChoose:
- printf("Sala: ");
- scanf("%i", &room);
- if (room < 1 || room > 2)
- goto roomChoose;
- printTitle(true);
- }
- float passedTime() {
- return time(0) - timerStart;
- }
- void resetTimer() {
- timerStart = time(0);
- }
- void levelUp() {
- player.level++;
- player.attack *= 1.25;
- }
- void otavioCreate(int topicos, int timer) {
- if (otavio.health > 0) {
- printf("Um Otavio (HP: %.0f) selvagem acaba de entrar na sala!\nRapido, vc tem %i segundos para digitar %i topicos\n\n", otavio.health, timer, topicos);
- resetTimer();
- for (i = 0; i < topicos; i++) {
- getTopic:
- printf("Digite o topico %i: ", i + 1);
- fflush(stdin);
- gets(topico);
- if (strlen(topico) < 3) {
- printf("Seu topico eh muito curto!\n");
- goto getTopic;
- }
- }
- if (passedTime() > timer) {
- player.media -= 0.5;
- damage(&player, 5);
- printTitle(true);
- printf("\nVc nao digitou a tempo. Vc perdeu 5 hp e meio ponto na media.");
- } else {
- damage(&otavio, player.attack);
- if (otavio.defeated) {
- printf("Parabens, %s! Voce conseguiu vencer o Otavio neste semestre!", player.name);
- } else
- printf("\nVc venceu o Otavio (HP: %.1f) nesta batalha! Prepare-se para a proxima.", otavio.health);
- levelUp();
- }
- } else {
- printf("Voce ja venceu o otavio!");
- otavio.defeated = true;
- system("pause");
- }
- }
- bool toninhoFunction(char derivada[30]) {
- char resposta[30];
- printf("\nDigite sua resposta: ");
- fflush(stdin);
- gets(resposta);
- for(i = 0; resposta[i]; i++){
- resposta[i] = tolower(resposta[i]);
- }
- remove_all_chars(resposta, '(');
- remove_all_chars(resposta, ')');
- remove_all_chars(resposta, '*');
- remove_all_chars(resposta, ' ');
- if (strcmp(resposta, derivada) == 0)
- return true;
- else
- return false;
- }
- void toninhoCreate(int timer) {
- if (toninho.defeated) {
- printf("Voce ja venceu o jovem Toninho!");
- } else {
- printf("Um jovem Toninho acaba de entrar na sala com oculos escuros!\nRapido, vc tem %i segundos para derivar a funcao: \n\n", timer);
- resetTimer();
- bool beatToninho = false;
- switch(levelToninho) {
- case 1:
- printf("x^2 + 5x^5");
- beatToninho = toninhoFunction("2x+25x^4");
- break;
- case 2:
- printf("sen(2x)");
- beatToninho = toninhoFunction("2cos2x");
- break;
- case 3:
- printf("ln(27x)");
- beatToninho = toninhoFunction("27/27x");
- break;
- case 4:
- printf("e^(4x^2)");
- beatToninho = toninhoFunction("8xe^4x^2");
- break;
- default:
- toninho.health = 0;
- printf("Voce ja venceu o jovem Toninho!");
- break;
- }
- if (passedTime() > timer)
- beatToninho = false;
- if (beatToninho) {
- levelToninho++;
- if (levelToninho > toninho.level) {
- damage(&toninho, 100);
- printf("Parabens, %s! Voce conseguiu vencer o Toninho neste semestre!", player.name);
- } else
- printf("Voce venceu o toninho nesta batalha!");
- levelUp();
- } else {
- damage(&player, 10);
- printTitle(true);
- printf("Voce nao conseguiu vencer o toninho desta vez! -10hp e -0.5 na media.");
- player.media -= 0.5;
- }
- }
- }
- int main() {
- printTitle(true);
- getName:
- printf("Digite seu nome: ");
- fflush(stdin);
- gets(player.name);
- printTitle(true);
- if (strlen(player.name) > 15) {
- printf("Vsf nome grande da porra, digita isso direito\n");
- goto getName;
- }
- if (strlen(player.name) < 4) {
- printf("Eh pra digitar seu nome, nao as siglas dele\nfdp\n");
- goto getName;
- }
- printTitle(true);
- printf("Ola, %s. Digite sua idade: ", player.name);
- getAge:
- scanf("%i", &player.age);
- printTitle(true);
- bool ageProblem = true;
- if (player.age < 17) {
- if (player.age < 6)
- printf("Parabens, vc aprendeu a ler cedo, hein?\n");
- else
- printf("Parabens, vc entrou na faculdade cedo, hein?\n");
- printf("fdp digite sua idade: ");
- }
- else if (player.age > 100) {
- printf("PARABENS VC EH UM ANCIAO E TA ESTUDANDO NA UNAERP\nVC VENCEU NA VIDA\nVai digitar sua idade de verdade cusao: ");
- }
- else if (player.age > 70)
- printf("Ta velho hein cusao. Digita isso direito: ");
- else
- ageProblem = false;
- if (ageProblem)
- goto getAge;
- gameStarted = true;
- do {
- printTitle(true);
- printRooms();
- if (room == 1) {
- otavioCreate(4 + player.level, 20 - player.level * 2);
- }
- if (room == 2) {
- toninhoCreate(30);
- }
- printf("\n");
- if (!player.defeated)
- system("PAUSE");
- if (toninho.defeated && otavio.defeated)
- gameWon = true;
- } while (player.health > 0 && player.media >= 5 && !gameWon);
- printTitle(true);
- if (gameWon) {
- printf("Parabens, %s! Voce ganhou! Considere fazer alguma coisa da vida agora.", player.name);
- } else {
- printf("Voce perdeu o jogo do edilson. Que triste, cara");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement