Code:
#include <allegro.h>
#include "standard_tcg.h"
#include "card.h"
#include "buttons.h"
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cstring>
using namespace std;
Card::Card(char id[7])
{
Name[0] = '\0';
char set[4];
char card[5];
char fname[255];
// parse the id into a set and card number
for(int i = 0; i < 3; i++)
{
set[i] = id[i];
}
set[3] = '\0';
for(int i = 0; i < 4; i++)
{
card[i] = id[i+3];
}
card[4] = '\0';
strcpy(fname, "card_data//set");
strcat(fname, set);
strcat(fname, ".tcg");
strcpy(filename, fname);
ifstream IFP (fname);
if(IFP == NULL)
allegro_message("could not open: %s", fname);
char comp_card[5];
char send_buffer[512];
char check;
int Icheck;
int index = 0;
while(!IFP.eof())
{
if(check == '[')
{
//get the id
for(int i = 0; i < 4; i++)
{
IFP >> check;
comp_card[i] = check;
}
comp_card[4] = '\0';
if(strcmp(card, comp_card) != 0)
allegro_message("comp_card: %s\nCard : %s", comp_card, card);
if(strcmp(card, comp_card) == 0)
{
IFP >> noskipws >> check;
// get card name
while(check != '#')
{
IFP >> check;
send_buffer[index] = check;
index++;
}
send_buffer[index-1] = '\0';
strcpy(Name, send_buffer);
index = 0;
// get HP
while(check != '>')
IFP >> check;
IFP >> Icheck;
health = Icheck;
// get type 1
while(check != '>')
IFP >> check;
IFP >> Icheck;
type1 = Icheck;
// get type 2
while(check != '>')
IFP >> check;
IFP >> Icheck;
type2 = Icheck;
// Get ability type 1
while(check != '>')
IFP >> check;
IFP >> Icheck;
ab_type_1 = Icheck;
// get ability type 2
while(check != '>')
IFP >> check;
IFP >> Icheck;
ab_type_2 = Icheck;
// get ability cost 1
while(check != '>')
IFP >> check;
IFP >> Icheck;
ab_cost_1 = Icheck;
// get ability cost 2
while(check != '>')
IFP >> check;
IFP >> Icheck;
ab_cost_2 = Icheck;
// get ability dmg 1
while(check != '>')
IFP >> check;
IFP >> Icheck;
ab_dmg_1 = Icheck;
// get ability dmg 2
while(check != '>')
IFP >> check;
IFP >> Icheck;
ab_dmg_2 = Icheck;
// get ability desc 1;
IFP >> check; // because it will be # right now
while(check != '#')
{
IFP >> check;
send_buffer[index] = check;
index++;
}
send_buffer[index-1] = '\0';
strcpy(ability_1, send_buffer);
index = 0;
// get ability desc 2
while(check != '#')
{
IFP >> check;
send_buffer[index] = check;
index++;
}
send_buffer[index-1] = '\0';
strcpy(ability_2, send_buffer);
index = 0;
// get retreat type 1
while(check != '>')
IFP >> check;
IFP >> Icheck;
rt_cost_type_1 = Icheck;
// get retreat type 2
while(check != '>')
IFP >> check;
IFP >> Icheck;
rt_cost_type_2 = Icheck;
// get retreat cost 1
while(check != '>')
IFP >> check;
IFP >> Icheck;
rt_cost_1 = Icheck;
// get retreat cost 2
while(check != '>')
IFP >> check;
IFP >> Icheck;
rt_cost_2 = Icheck;
// get weakness
while(check != '>')
IFP >> check;
IFP >> Icheck;
weakness = Icheck;
// get resistance
while(check != '>')
IFP >> check;
IFP >> Icheck;
resistance = Icheck;
// get resistance strength
while(check != '>')
IFP >> check;
IFP >> Icheck;
strength_res = Icheck;
// get evolve
while(check != '>')
IFP >> check;
IFP >> Icheck;
evolve = Icheck;
// move the iterator over one
IFP >> check;
// get evolve name
if(evolve == 1)
{
while(check != '#')
{
IFP >> check;
send_buffer[index] = check;
index++;
}
send_buffer[index-1] = '\0';
strcpy(ev_name, send_buffer);
}
else
ev_name[0] = '\0';
}
}
IFP >> check;
}
IFP.close();
}
int Card::Print_Card(BITMAP *bmp, int x, int y)
{
if(Name[0] != '\0')
{
textprintf_ex(bmp, font, x, y+10, WHITE, -1,"%s", Name);
textprintf_ex(bmp, font, x, y+20, WHITE, -1,"%d", health);
textprintf_ex(bmp, font, x, y+30, WHITE, -1,"%d", type1);
textprintf_ex(bmp, font, x, y+40, WHITE, -1,"%d", type2);
textprintf_ex(bmp, font, x, y+50, WHITE, -1,"%d", ab_type_1);
textprintf_ex(bmp, font, x, y+60, WHITE, -1,"%d", ab_type_2);
textprintf_ex(bmp, font, x, y+70, WHITE, -1,"%d", ab_cost_1);
textprintf_ex(bmp, font, x, y+80, WHITE, -1,"%d", ab_cost_2);
textprintf_ex(bmp, font, x, y+90, WHITE, -1,"%d", ab_dmg_1);
textprintf_ex(bmp, font, x, y+100, WHITE, -1,"%d", ab_dmg_2);
textprintf_ex(bmp, font, x, y+110, WHITE, -1,"%s", ability_1);
textprintf_ex(bmp, font, x, y+120, WHITE, -1,"%s", ability_2);
textprintf_ex(bmp, font, x, y+130, WHITE, -1,"%s", filename);
}
else
textprintf_ex(bmp, font, x, y+10, WHITE, -1, "No info was read");
return 0;
}