Quote (SelfTaught @ Mar 22 2013 10:52pm)
I think you should. I've been wanting to get into this for a while but just haven't got around to it, maybe now's the time. It'd be nice to be able to ask questions instead of getting stumped on tutorials and not have that option.
i jsut finished my game ill will be doing tests/documents on.
not the funnest game in the world but it will show the basics of function hooking and general game modifying.
i will prolly make another game later on to show how to parse/find structs of information like in most FPS games where theres a giant array of structs for every player in the game showing their position, hp, armor, etc.
Code
#include <stdio.h>
#include <stdlib.h>
char print_intro();
void print_directions();
char ask_attack();
void do_turn(int *HP, int *EN, int player);
int main()
{
int pHP = 100, pEN = 20;
int cHP = 100;
int turn = 0;
if(print_intro() == 'n')
{
printf("Thanks for playing!\n");
return 0;
}
system("cls");
print_directions();
system("cls");
do
{
if(turn == 0)
{
do_turn(&cHP, &pEN, turn);
turn++;
}
else if(turn == 1)
{
do_turn(&pHP, 0, turn);
turn--;
}
}while(pHP >= 0 && cHP >= 0);
if(cHP >= 0)
{
printf("Sorry you lost!\n");
}
else if(pHP >= 0)
{
printf("Congrats you won!\n");
}
return 0;
}
char print_intro()
{
char input;
printf("Welcome to the most awesome best game ever made!\n");
printf("Purpose of this game is to kill the npc before he kills you\nin a turn based fashion\n\n");
printf("Would you like to play? y/n: ");
input = fgetc(stdin);
getchar();
return input;
}
void print_directions()
{
printf("To play simply enter in a command and it will attack your oponent.\n");
printf("You have two attacks. A basic punch and a special energy attack which consumes 5 energy per attack but deals more damage.\n");
printf("The first one to zero HP loses good luck!\n\nPress any key to continue...\n\n");
getchar();
}
char ask_attack()
{
char input;
printf("\n[1] Punch\n");
printf("[2] Kick\n");
printf("[3] Fireball\n");
printf("Which attack do you want to do: ");
input = fgetc(stdin);
getchar();
printf("\n\n");
return input;
}
void do_turn(int *HP, int *EN, int player)
{
char attack = 0;
int dmg = 0;
if(player == 0)
{
attack = ask_attack();
while(attack != '1' && attack != '2' && attack != '3')
{
printf("Invalid attack. Please try again.\n");
attack = ask_attack();
}
if(attack == '1') //punch
{
dmg = rand()%5;
}
else if(attack == '2') //kick
{
dmg = rand()%10+2;
}
else if(attack == '3' && *EN >= 2)
{
dmg = rand()%20+10;
*EN -= 2;
}
printf("You delt %d damage!\n", dmg);
*HP -= dmg;
if(*HP <=0)
{
printf("NPC HP is at %d/100 and you have %d energy\n\n", 0, *EN);
}
else
{
printf("NPC HP is at %d/100 and you have %d energy\n\n", *HP, *EN);
}
}
else
{
dmg = rand()%20+1;
printf("NPC delt %d damage!\n", dmg);
*HP -= dmg;
if(*HP <=0)
{
printf("Your HP is at %d/100\n\n", 0);
}
else
{
printf("Your HP is at %d/100\n\n", *HP);
}
}
}
This post was edited by AbDuCt on Mar 22 2013 10:52pm