Ir para conteúdo

[Source] Player


Posts Recomendados

[source] Player

Player.dev

 

[unit1]
FileName=main.cpp
CompileCpp=0
Folder=Player
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Project]
UnitCount=5
FileName=Player.dev
Name=Player
Type=1
Ver=1
ObjFiles=""
Includes=""
Libs=
PrivateResource=Player_private.rc
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-D__PLAYER___@@_-D__MONSTER___@@_
Linker=-lconio_@@_
IsCpp=1
Icon=
ExeOutput=
ObjectOutput=
OverrideOutput=0
OverrideOutputName=Player.exe
HostApplication=
Folders=
CommandLine=
UseCustomMakefile=0
CustomMakefile=
IncludeVersionInfo=1
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000000000000000100

[VersionInfo]
Major=1
Minor=0
Release=0
Build=0
LanguageID=1046
CharsetID=1252
CompanyName=
FileVersion=1.0
FileDescription=
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=1.0
AutoIncBuildNr=0

[unit3]
FileName=monster.h
CompileCpp=0
Folder=Player
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[unit5]
FileName=player.h
CompileCpp=0
Folder=Player
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[unit7]
FileName=character.h
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[unit2]
FileName=monster.cpp
CompileCpp=0
Folder=Player
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[unit4]
FileName=player.cpp
CompileCpp=0
Folder=Player
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

 

main.cpp:

 

#include <windows.h>
#include <conio.h>
#include <vector>

#include "player.h"
#include "monster.h"

std::vector<char *> generatePlayerName;

template <class objectType> objectType Character::convertCharacter(__int64 convertType, objectType characterConvert) const
{
char *convertedCharacter = (char *) malloc(MAX_PATH);

switch (convertType)
{
 case 0x10:
 {
  CharToOem(characterConvert, convertedCharacter);
  ZeroMemory((void *) characterConvert, 0);

  return convertedCharacter;
 }

 case 0x20:
 {
  for (int convertSize = 0; convertSize < strlen(characterConvert); convertSize++)
  {
   characterConvert[convertSize] = characterConvert[convertSize] ^ 0x01;
  }

  return characterConvert;
 }
}
}

Character *character;
Player player[MAX_PATH];
Player::Spell::Attack *attack;
Monster monster[MAX_PATH];

int main()
{
SetConsoleTitle("Jogo Feito em C++");
textcolor(WHITE);
textbackground(BLACK);
system("color 00");
srand(time(NULL));

generatePlayerName.push_back("Aluxes");
generatePlayerName.push_back("Splasy");
generatePlayerName.push_back("Rauron");
generatePlayerName.push_back("Fafain");
generatePlayerName.push_back("Stracy");
generatePlayerName.push_back("Morgan");

player->setName(player);
monster->setName("Draptor", monster);

if (strlen(player->playerName) <= 4)
{
 player->playerName = generatePlayerName[rand() % 6];

 clrscr();
 printf("\n O nome do jogador %s.", character->convertCharacter<char *>(0x10, "é inválido"));
 getch();
 clrscr();
}
else if (!strcmp(player->playerName, "Draptor"))
{
 player->playerName = generatePlayerName[rand() % 6];

 clrscr();
 printf("\n O nome do jogador %s.", character->convertCharacter<char *>(0x10, "é inválido"));
 getch();
 clrscr();
}

while (!player->playerDie && !monster->monsterDie)
{
 if (attack->attackMonster(player, monster))
 {
  player->firstAttack = true;
 }
}

if (player->playerDie && !monster->monsterDie)
{
 printf("\n %s morreu.", player->playerName);
}
else if (monster->monsterDie && !player->playerDie)
{
 printf("\n %s morreu.", monster->monsterName);
}
else if (player->playerDie && monster->monsterDie)
{
 printf("\n %s e %s morreram.", player->playerName, monster->monsterName);
}

getch();
}

 

monster.cpp

 

#include <windows.h>

#include "monster.h"

void Monster::setName(char *inputName, Monster *monster)
{
if (strlen(inputName) <= 0)
{
 monster->monsterName = NULL;
}
else if (!strlen(inputName) <= 0)
{
 monster->monsterName = inputName;
}
}

void Monster::setHealth(Monster *monster)
{
if (!monster->firstHealth)
{
 if (!strcmp(monster->monsterName, "Draptor"))
 {
  monster->monsterHealth = 6000;
  monster->firstHealth = true;
 }
}
}

__int32 Monster::getAttack(Monster *monster) const
{
if (!strcmp(monster->monsterName, "Draptor"))
{
 return rand() % 301 + 1300;
}
}

 

monster.h

 

#ifndef __MONSTER__
#define __MONSTER__

class Monster
{
public:
 void setName(char *inputName, Monster *monster);
 void setHealth(Monster *monster);
 __int32 getAttack(Monster *monster) const;

char *monsterName;
bool firstHealth;
__int32 monsterHealth, monsterAttack, monsterDie;
};

#endif

 

player.cpp

 

#include <windows.h>
#include <conio.h>

#include "player.h"

void Player::setName(Player *player)
{
player->inputName = (char *) malloc(MAX_PATH);

printf("\n Digite o nome da pessoa: ");
gets(player->inputName);
clrscr();

player->playerName = player->inputName;
}

void Player::setHealth(Player *player)
{
if (!player->firstHealth && !player->firstAttack)
{
 player->playerHealth = 10000;
}
}

__int32 Player::getAttack(Player *player) const
{
if (player->playerHealth && !player->firstAttack)
{
 if (!player->firstHealth)
 {
  player->firstAttack = true;
 }

 return rand() % 301 + 1000;
}
else if (player->playerHealth && player->firstAttack)
{
 return rand() % 301 + 1000;
}
else if (!player->playerHealth && !player->firstAttack)
{
 return rand() % 301 + 1000;
}
else if (!player->playerHealth && player->firstAttack)
{
 return -1;
}
}

signed short Player::Spell::Attack::attackMonster(Player *player, Monster *monster) const
{
Character *character;

if (player->firstAttack)
{
 if (player->playerHealth <= 0 && monster->monsterHealth > 0)
 {
  player->playerDie = true;
 }
 else if (monster->monsterHealth <= 0 && player->playerHealth > 0)
 {
  monster->monsterDie = true;
 }
 else if (monster->monsterHealth <= 0 && player->playerHealth <= 0)
 {
  player->playerDie = true;
  monster->monsterDie = true;
 }
}

if (!player->playerDie && !monster->monsterDie)
{
 player->playerAttack = player->getAttack(player);
 player->setHealth(player);
 monster->monsterAttack = monster->getAttack(monster);
 monster->setHealth(monster);

 if (player->playerHealth <= 1300)
 {
  monster->monsterAttack -= monster->monsterAttack - player->playerHealth;
 }
 else if (monster->monsterHealth <= 1300)
 {
  player->playerAttack -= player->playerAttack - monster->monsterHealth;
 }

 printf("\n %s tirou %d de life. (%s: %d)\n ", monster->monsterName, monster->monsterAttack, monster->monsterName, monster->monsterHealth - player->playerAttack);
 printf("%s tirou %d de life. (%s: %d)\n", character->convertCharacter<char *>(0x10, "Você"), player->playerAttack, player->playerName, player->playerHealth - monster->monsterAttack);

 monster->monsterHealth -= player->playerAttack;
 player->playerHealth -= monster->monsterAttack;

 return true;
}

return false;
}

 

player.h

 

#ifndef __PLAYER__
#define __PLAYER__

#include "monster.h"

class Character
{
public:
 template <class objectType> objectType convertCharacter(__int64 convertType, objectType characterConvert) const;
};

class Player : public Monster
{
public:
 void setName(Player *player);
 void setHealth(Player *player);
 __int32 getAttack(Player *player) const;

 class Spell
 {
  public:
   class Attack
   {
    public:
     signed short attackMonster(Player *player, Monster *monster) const;
   };
 };

 char *inputName, *playerName;
 bool firstAttack, firstHealth, playerDie;
 __int32 playerHealth, playerAttack;
};

#endif

 

Utilize a lib: -lconio para compilar.

Gostou? Dê-me rep++.

 

Crédito:

  • Aluxes (100%).

Player.rar

Conio.rar

Editado por Aluxes
Link para o comentário
Compartilhar em outros sites

  • 4 years later...
×
×
  • Criar Novo...