Stuck in the mud

ImageIt’s not that I haven’t been trying to move forward with this program (the Pokemon thing), the problem is that I’ve gotten stuck in the mud. I don’t think the problem is really so huge, but that I’m having trouble figuring out what the problem actually is. There’s just not sufficient direction in my debugger to point me to the problem.

Advertisements

The Next Step: Turning a Clown Car into a Pokemon Battle

It’s my son who asked me to do this. He’s recently taken up Pokemon and has insisted that my wife and I both learn to play so that we can have Pokemon battles with him.

Image

Pika!

I thought: Ok, I have this Clown Car thing all worked out already. Maybe I can just transform it into  what he wants. The basic idea is to transform the clown car into a deck of Pokemon cards. The I also need to have two other decks – one for the player’s hand and one for the computer’s.  At the start of the game, we should have all the Pokemon in the main deck. I thought I would make this main deck viewable and then allow the player and then computer to draw cards, one at a time until they fill up their hands (in my first example, I top out the player and computer decks at two cards each.

What I need to do is be able to move the cards from one deck to another. Apparently, there is a move function for vectors, but I haven’t been able to make this work. However, it shouldn’t be too difficult to just copy a card object from one deck to another and then erase the first instance.

Nevertheless, I have not been able to make this work yet. Here’s the code that controls the player picking and the computer randomly taking cards:

 

 

void drawCards(vector<Pokemon> &draw, vector<Pokemon> &player, vector<Pokemon> &computer){

bool playerChoice = true;

int playerPick= NULL;

int compPick;

int number = 0;

   //start with outline

    printVectorContents2(draw);

    cout<<“**********”<<endl;

    cout<<“Player’s hand”<<endl;

    printVectorContents2(player);

    cout<<“**********”<<endl;

    cout<<“Computer’s hand”<<endl;

    printVectorContents2(computer);

    cout<<“**********”<<endl;

    cout<<“**********”<<endl;

 

while (number < 2) {             //this is copying the pokemon into the new vectors properly, but not erasing them

if (playerChoice == true) {

            cout<<“Player, please choose a Pokemon from the draw pile (enter ID number)”<<endl;

cin>>playerPick;

cout<<“You chose number “<<playerPick<<“, “<<draw[playerPick1].getName()<<endl;

            player[number] = draw[playerPick1];

            //draw.push_back(playerPick-1);

            draw.erase(draw.begin()-playerPick-1);

            //draw.pop_back();

            //move(draw.begin()+playerPick-1, draw.begin()+playerPick-1, player.begin()+number);

            playerChoice = false;

            }

else{

            compPick = rand()%draw.size()+1;

cout<<“Computer chose number “<<compPick<<“, “<<draw[compPick1].getName()<<endl;

           // move(draw.begin()+compPick-1, draw.begin()+compPick-1, computer.begin()+number);

            computer[number] = draw[compPick1];

            //draw.push_back(compPick-1);

            //draw.pop_back();

            draw.erase(draw.begin()-compPick-1);

            number++;

            playerChoice = true;

        }

    }

    //exits when number =3

    cout<<“Finished drawing cards.”<<endl;

    printVectorContents2(draw);

    cout<<“**********”<<endl;

    printVectorContents2(player);

    cout<<“**********”<<endl;

    printVectorContents2(computer);

    cout<<“**********”<<endl;

    cout<<“**********”<<endl;

The problem I’m seeing is that nothing is actually moving. output:

**************

IDNumber = 1, name = Pikachu

IDNumber = 2, name = Froky

IDNumber = 3, name = FurFrou

IDNumber = 4, name = Meowth

IDNumber = 5, name = BunnleBy

IDNumber = 6, name = BeeDrill

IDNumber = 7, name = Gloom

IDNumber = 8, name = Diglett

**********

Player’s hand

IDNumber = 0, name = 

IDNumber = 0, name = 

**********

Computer’s hand

IDNumber = 0, name = 

IDNumber = 0, name = 

**********

**********

Player, please choose a Pokemon from the draw pile (enter ID number)

1

You chose number 1, Pikachu

Computer chose number 6, Gloom

(lldb)

This means that we are getting through the first round of picks, but crashing before second round. Previously, I did have a second round operational, but the player and computer hands remained empty and the Pokemon who had been picked remaining in the drawPile. Perhaps it’s a problem with using pointers?