News: 11 March 2016 - Forum Rules

Author Topic: Trouble with card game I'm making..  (Read 4144 times)

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Trouble with card game I'm making..
« on: February 26, 2013, 10:42:15 pm »
So I'm making a triple triad clone from ff8. But it appears its telling me that I never declared the variables I returned..

here's the code:
http://pastebin.com/tt5WiGDa

Doesn't do a whole lot so far. Just assigns values. And one more thing, is there an easier way of doing this? I'm still learning and I'm sure everyone else is too.

Klarth

  • Sr. Member
  • ****
  • Posts: 498
    • View Profile
Re: Trouble with card game I'm making..
« Reply #1 on: February 26, 2013, 11:22:09 pm »
Short version: You forgot a semicolon after declaring cards edeck[6].
Long version: There's a lot that needs to be cleaned up. I'll try to work on a version that drastically improves the readability if I have time to complete it.

http://pastebin.com/VUYkUCFR is a reworked version. I may be willing to do a more complete rework once the game is in a playable state and some complexity is added.
« Last Edit: February 27, 2013, 12:21:09 am by Klarth »

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Trouble with card game I'm making..
« Reply #2 on: February 27, 2013, 05:45:34 am »
@Klarth's (clearly a thousand times more readable) rewrite: Just nit-picking here, but I think it would be better to use the initializer list and write

Code: [Select]
card(string cardName, int top, int left, int right, int bottom, bool side)
  : CardName(cardName), Top(top), Left(left), Right(right), Bottom(bottom), Side(side) {}

instead of manually assigning the values within the constructor. This might not make a big difference here, but it's best to adopt good practices early on.

@IK: Also, if the complexity further grows, I'd divide main() into smaller functions that are reuseable and can be maintained better, for example "clearing the board", "initialize players' cards" and "game loop".

FAST6191

  • Hero Member
  • *****
  • Posts: 3345
    • View Profile
Re: Trouble with card game I'm making..
« Reply #3 on: February 27, 2013, 06:39:47 am »
I will spare you my lousy C++ skills but I do wish to point out there is a nice clone game for the DS with source you might like to have a look at
http://gamebrew.org/wiki/Triple_Triad_DS

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Trouble with card game I'm making..
« Reply #4 on: February 27, 2013, 11:16:33 am »
What's up with this line:

Code: [Select]
cin >> input;
PlayerDeck[i] = PlayerCards[input];

Does that like inherit everything from one struct to the other? I didn't put that in there.

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: Trouble with card game I'm making..
« Reply #5 on: February 27, 2013, 11:21:44 am »
It calls the assignment operator method that's defined for that struct/class. The default implementation provided by the compiler just copies all data from one instance to the other.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Trouble with card game I\'m making..
« Reply #6 on: February 27, 2013, 12:59:50 pm »
That is so cool! I didn't know about that.. I'm thinking about using that in my battlesystem! But I want to finish this card game first.

Thanks for shortening my code!

February 27, 2013, 04:53:45 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
One more thing, why isn't my map appearing?
http://pastebin.com/iecLWM2x

It all starts on line 106. It doesn't output anything.
« Last Edit: February 27, 2013, 04:53:45 pm by InfamousKnight »

Klarth

  • Sr. Member
  • ****
  • Posts: 498
    • View Profile
Re: Trouble with card game I'm making..
« Reply #7 on: February 27, 2013, 08:02:09 pm »
Just nit-picking here, but I think it would be better to use the initializer list
Fair enough, good suggestion!  Also, I didn't break it up into functions because I didn't know exactly where he was going with the code yet.  It can still be substantially cleaner.

One more thing, why isn't my map appearing?
for(int x = 3; x < 3; x++)

Take a bit to think about that!  Same deal with the inner y loop.  Hint: The loop is never executed.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Trouble with card game I'm making..
« Reply #8 on: February 27, 2013, 08:50:50 pm »
I can't believe I didn't notice that.. Thanks!

syntax error

  • Full Member
  • ***
  • Posts: 227
    • View Profile
Re: Trouble with card game I'm making..
« Reply #9 on: February 28, 2013, 05:03:29 pm »
in FF8 PC the cards are in the executable.