Baby steps- catching dreams

Image

We should be working

I’ve been trying to get more sleep lately. This means that a significant portion of my ‘coding time’ has now been exchanged for ‘sleeping time.’ That, in turn, means much less progress with my latest coding project, the Pokemon Card Game.

The major goal of this project is to familiarize myself with vectors and how to manipulate them easily, moving items from one vector to another, deleting them, changing aspects of single vector objects, etc. So fa, this has been somewhat achieved. I have definitely become more familiar with the idea of the vector (it’s an array with more reasonable manipulations). The problem is, I still run into problems with these manipulations (unable to delete items from a vector, etc).

Image

I’m not sure this thing will work

Secondary goals involve:

1. Presenting a more civilized (although still ASCII) interface. I would love to leave ASCII and the terminal behind, but that has been a very elusive goal that I have no idea how to tackle.

2. Building in more realistic randomness into the play while also shepherding this randomness into better gameplay (attacks are randomized, but contain modifiers to make them more challenging)

3. Trying to keep my code simple and organized

 

Let’s be honest, #3 has been right out the window.

#2 is coming, and I think it should be more straight-forward than my other issues, but it’s still not implemented.

#1 is the only thing I worked on at all last night. Although I have good ideas about how I could make this much better, I’m not letting ‘the perfect’ get in the way of ‘the good’ just yet. Right now, this is about what the interface looks like:

 

Screen Shot 2014-06-24 at 8.31.49 AM 

Advertisements

Advancing the Pokemon

I’m not unstuck yet, but I am advancing a bit.

I just finished playing with the code a bit trying to tackle one small problem at a time rather than trying to solve the whole thing all at once. This strategy has proven more and more successful as the program has grown.

Please note that there are several superfluous statements here in order to follow the process more closely. At this point I have been trying to get the points taken care of properly and recognize when someone has less that 1 pt left (making them dead). 

The next steps are to pop dead pokemon out of the player / computer’s hand and then advance the remaining pokemon to the fore.

Here’s a copy of the text from the latest run:

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

**********

Player’s hand is empty.

**********

Computer’s hand is empty.

**********

**********

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, please choose a Pokemon from the draw pile (enter ID number)

4

You chose number 4, Meowth

player’s hand:

IDNumber = 4, name = Meowth

IDNumber = 0, name = 

**********

IDNumber = 1, name = Pikachu

IDNumber = 2, name = Froky

IDNumber = 3, name = FurFrou

IDNumber = 5, name = BunnleBy

IDNumber = 6, name = BeeDrill

IDNumber = 7, name = Gloom

IDNumber = 8, name = Diglett

**********

**********

computer’s hand:

IDNumber = 5, name = BunnleBy

IDNumber = 0, name = 

**********

IDNumber = 1, name = Pikachu

IDNumber = 2, name = Froky

IDNumber = 3, name = FurFrou

IDNumber = 6, name = BeeDrill

IDNumber = 7, name = Gloom

IDNumber = 8, name = Diglett

**********

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

7

You chose number 7, Gloom

player’s hand:

IDNumber = 4, name = Meowth

IDNumber = 7, name = Gloom

**********

IDNumber = 1, name = Pikachu

IDNumber = 2, name = Froky

IDNumber = 3, name = FurFrou

IDNumber = 6, name = BeeDrill

IDNumber = 8, name = Diglett

**********

**********

computer’s hand:

IDNumber = 5, name = BunnleBy

IDNumber = 2, name = Froky

**********

Finished drawing cards.

 

 

 

 

 

 

**********

IDNumber = 4, name = Meowth

IDNumber = 7, name = Gloom

**********

IDNumber = 5, name = BunnleBy

IDNumber = 2, name = Froky

**********

**********

Which Pokemon will you send into battle? (select ID number)

IDNumber = 4, name = Meowth

IDNumber = 7, name = Gloom

7

Gloom is the player’s current Pokemon.

Froky is the computer’s current Pokemon.

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 100 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 100 Status: alive

Select an attack (by number):

Attack 1 = Acid

Attack 2 = Swwet Scent

Attack 3 = Poison Powder

3

Gloom attacks Froky using Poison Powder

Begin Battle

Yes! Hit.

Gloom scores 45 using Poison Powder.

End Battle

player turn = false

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 100 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 55 Status: alive

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 100 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 55 Status: alive

Select an attack (by number):

Attack 1 = Acid

Attack 2 = Swwet Scent

Attack 3 = Poison Powder

3

Gloom attacks Froky using Poison Powder

Begin Battle

missed – Drat!!

End Battle

player turn = false

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 100 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 55 Status: alive

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 100 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 55 Status: alive

Select an attack (by number):

Attack 1 = Acid

Attack 2 = Swwet Scent

Attack 3 = Poison Powder

3

Gloom attacks Froky using Poison Powder

Begin Battle

Yes! Hit.

Gloom scores 45 using Poison Powder.

End Battle

player turn = false

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 100 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 10 Status: alive

Froky attacks Gloom using water drip

Begin Battle

Yes! Hit.

Froky scores 20 using water drip.

End Battle

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 80 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 10 Status: alive

Select an attack (by number):

Attack 1 = Acid

Attack 2 = Swwet Scent

Attack 3 = Poison Powder

3

Gloom attacks Froky using Poison Powder

Begin Battle

missed – Drat!!

End Battle

player turn = false

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 80 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 10 Status: alive

Froky attacks Gloom using quick attack

Begin Battle

missed – Drat!!

End Battle

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 80 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = 10 Status: alive

Select an attack (by number):

Attack 1 = Acid

Attack 2 = Swwet Scent

Attack 3 = Poison Powder

2

Gloom attacks Froky using Swwet Scent

Begin Battle

Yes! Hit.

Gloom scores 15 using Swwet Scent.

Froky is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

End Battle

player turn = false

 

 

 

 

 

 

 

 

 

 

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 80 Status: alive

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = -5 Status: dead

Froky attacks Gloom using water drip

Begin Battle

missed – Drat!!

End Battle

Popping 1 Pokemon, named Froky

Computer has advanced BunnleBy into attack position.

Player’s Deck

—————

IDNumber = 4 Name = Meowth, hp = 100 Status: alive

IDNumber = 7 Name = Gloom, hp = 80 Status: alive

 

 

 

 

Computer’s Deck

—————

IDNumber = 5 Name = BunnleBy, hp = 100 Status: alive

IDNumber = 2 Name = Froky, hp = -5 Status: dead

Select an attack (by number):

Attack 1 = Acid

Attack 2 = Swwet Scent

Attack 3 = Poison Powder

(I quit the program here)

Wow, Finally smoothed out that clown problem

ImageThis version of the clown application uses a vector (clown car) to handle the objects (clowns).

Each clown has a Name, and ID number, hit points(hps), and three attacks. The way this program works is that it seeds the vector with the clown objects at the beginning (this was part of the vector handling problem), then allows them to fight it out in the clown car – every time a clown’s hps falls to zero, the clown is dead and if thrown from the car (i.e., they no longer populate the vector. This proceeds until only one clown remains. The last clown standing is declared the winner.

As the battle occurs, cout statements indicate who attacks whom and what damage is inflicted. (note: every attack is a ‘hit’). If a clown is killed, this is also announced and then the vector is printed out to show what clowns remain in the car.

I believe there are no bugs remaining in this program. When I was working on it, I included a large number of debugging statements. These have been removed for clarity in the final product. I also removed the dialog asking what clown to eject – and removed the function that handled that query.

Code:

//

//  main.cpp

//  clowncar

//

//  Created by Jack on 5/4/14.

//

#include <iostream>

#include <vector>

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

#include <cstdlib>

#include <ctime>

usingnamespacestd;

using std::vector;

class IdNumbers{     // a place to store a counter for creating idNumbers

public:

    IdNumbers(){

    }

static int getANewNumber(){

counter++;

return counter;

    }

protected:

static int counter;

}; //end IdNumbers

class Clown{   // the clown objects

public:

    Clown(){};

    ~Clown(){};

    Clown(int clownId){

idNum = clownId;

    };

    Clown(string nameOfClown, IdNumbers theNumber, string attackIn1, int attackIn1Damage, string attackIn2, int attackIn2Damage, string attackIn3, int attackIn3Damage ){

clownName = nameOfClown;

idNum = theNumber.getANewNumber();

attack1 = attackIn1;

attack2 = attackIn2;

attack3 = attackIn3;

attack1Damage = attackIn1Damage;

attack2Damage = attackIn2Damage;

attack3Damage = attackIn3Damage;

hitPoints = 100;

dead = false;

    };

int getClownId(void){

return idNum;

    }

string getName(void){

return clownName;

    }

void printClown(void){

cout<<“idNumber = “<<idNum<<endl;

cout<<“name = “<<clownName<<endl;

    };

void printClown2(void){

        cout<<“Clown idNumber = “<<idNum<<“, name = “<<clownName<<endl;

    };

void printClown3(void){

        cout<<“Clown Name = “<<clownName<<“, hp = “<<hitPoints<<endl;

    };

int getNumAttacks(void){

return numAttacks;

    };

string getAttack1(){

return attack1;

    };

string getAttack2(){

return attack2;

    };

string getAttack3(){

return attack3;

    };

int getDamage1(){

        returnattack1Damage;

    };

int getDamage2(){

        returnattack2Damage;

    };

int getDamage3(){

        returnattack3Damage;

    };

int getHP(){

return hitPoints;

    };

void setHP(int damage){

this->hitPoints = this->hitPoints – damage;

if (hitPoints <= 0){

dead = true;

        }

    }

bool getDead(){

return dead;

    }

private:

string clownName;

int idNum;

int numAttacks = 3;

string attack1;

int attack1Damage;

string attack2;

int attack2Damage;

string attack3;

int attack3Damage;

int hitPoints;

bool dead;

};    //end clown

//functions

void printVectorContents(vector<Clown> &);

void printVectorContents2(vector<Clown> &);

void askWhoToPop(vector<Clown> &);

void popClown(vector<Clown> &, int);

void popThisClown(vector<Clown> &car, int popWho);

void directFight(vector<Clown> &car);

int IdNumbers ::counter = 0;

//*********************************************************************************************

int main(int argc, const char * argv[])

{

IdNumbers theCounter;

    srand (time(NULL));                     //<—–should seed random numbers appropriately…

    vector<Clown> clowncar;     //sets up a vector for fish

int vectorSize = 0;

    vectorSize = clowncar.size(); //get array size

Clown pennywise(“Pennywise”, theCounter, “bite”, 30, “claw”, 20, “defenestrate”, 1000);

    clowncar.push_back(pennywise);

    Clown jwgacy(“John Wayne Gacy”, theCounter, “creep out”, 30, “molest”, 50, “defenestrate”, 1000);

    clowncar.push_back(jwgacy);

    vectorSize = clowncar.size(); //get array size

    Clown bozo(“Bozo”, theCounter, “nose honk”, 5, “flower squirt”, 10, “defenestrate”, 1000);

    clowncar.push_back(bozo);

    Clown krusty(“Krusty”, theCounter, “tease”, 15, “step on foot”, 20, “defenestrate”, 1000);

    clowncar.push_back(krusty);

    vectorSize = clowncar.size(); //get array size

    Clown ronald(“Ronald McDonald”, theCounter, “smile”, 30, “arterie clog”, 30, “defenestrate”, 1000);

    clowncar.push_back(ronald);

    vectorSize = clowncar.size(); //get array size

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

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

    clowncar.shrink_to_fit();

    printVectorContents2(clowncar);

directFight(clowncar);

return 0;

}

//****************************************************************************

//Non-Member functions

void printVectorContents(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown();

    }

}

void printVectorContents2(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown2();

    }

}

void printVectorContents3(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown3();

    }

}

void popThisClown(vector<Clown> &car, int popWho){   //how to selectively delete from a vector????

for (int j = 0; j < car.size(); j++)

    {

if(car[j].getClownId() == popWho)

        {

            car.erase (car.begin()+j);

        }

    }// end for

};

void directFight(vector<Clown> &car){      //handles the fighting

bool victor = false;

bool targetIdentified = false;

string winner;

int attackerArrayPosition;

int targetArrayPosition;

int targetID;

int attackerID;

string attackerName;

string targetName;

int attackNum;

string attackType;

int attackDamage;

while (victor == false){

for (int attackerArrayPosition=0;attackerArrayPosition<car.size();attackerArrayPosition++){                             //scrolls through attackers

if(car.size() == 1){

                victor = true;

                winner = car[0].getName();

cout<<“Winner is “<<winner<<endl;

exit(0);

            }

            attackerName = car[attackerArrayPosition].getName();

            attackerID = car[attackerArrayPosition].getClownId();

            targetArrayPosition = rand()%car.size();               // gets an array position

            targetID = car[targetArrayPosition].getClownId();      //translates array position into clown ID number

            targetName = car[targetArrayPosition].getName();

while (targetIdentified == false){

if (targetID == attackerID){

                    targetIdentified = false;

                    targetArrayPosition = rand()%car.size();

                    targetID = car[targetArrayPosition].getClownId();

                }

else if (targetID != attackerID){

                    targetIdentified = true;

for(int i=0;i<car.size();i++){

if (targetID == car[i].getClownId()){

                            targetName = car[i].getName();

                        }

                    }

break;

                }

else{

                    cout<<“this isn’t supposed to happen. AttackerID is “<<attackerArrayPosition<<” target ID is “<<targetID<<endl;

                }

            }

        attackNum = rand()%3 + 1;    //choose attack (gets a random number)

switch ( attackNum ) {

case 1 :

                    attackType = car[attackerArrayPosition].getAttack1();

break;

case 2 :

                    attackType = car[attackerArrayPosition].getAttack2();

break;

case 3 :

                    attackType = car[attackerArrayPosition].getAttack3();

break;

default :

                    cout<<“error in attackNum switch statement”<<endl;

            } //end attackNum Switch

switch ( attackNum ) {

case 1 :

                    attackDamage = car[attackerArrayPosition].getDamage1();

break;

case 2 :

                    attackDamage = car[attackerArrayPosition].getDamage2();

break;

case 3 :

                    attackDamage =  car[attackerArrayPosition].getDamage3();

break;

default :

                    cout<<“error in attackNum switch statement”<<endl;

            }

cout<<attackerName<<” attacks “<<targetName<<” with “<<attackType<<” attack for “<<attackDamage<<” damage.”<<endl;

            //report attacker, attack, target AND score damage

                        car[targetArrayPosition].setHP(attackDamage);       //call to adjust hps according to damage

if (car[targetArrayPosition].getDead() == true){    //thrown dead from the car

cout<<car[targetArrayPosition].getName()<<” is dead.”<<endl;

                            cout<<“<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>”<<endl;

popThisClown(car, targetID);

                            car.shrink_to_fit();

                            targetIdentified = false;   //reset for next round

break;

                        }

else{

                            cout<<“<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>”<<endl;

                            targetIdentified = false;   //reset for next round

printVectorContents3(car);

                        }

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

if(car.size() == 1){

                victor = true;

                winner = car[0].getName();

            }

    }

         printVectorContents3(car);

    }

cout<<“Winner is “<<winner<<endl;

};

output:

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

**********

Clown idNumber = 1, name = Pennywise

Clown idNumber = 2, name = John Wayne Gacy

Clown idNumber = 3, name = Bozo

Clown idNumber = 4, name = Krusty

Clown idNumber = 5, name = Ronald McDonald

Pennywise attacks Bozo with bite attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 100

Clown Name = John Wayne Gacy, hp = 100

Clown Name = Bozo, hp = 70

Clown Name = Krusty, hp = 100

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

John Wayne Gacy attacks Krusty with defenestrate attack for 1000 damage.

Krusty is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 100

Clown Name = John Wayne Gacy, hp = 100

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

Pennywise attacks John Wayne Gacy with bite attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 100

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

John Wayne Gacy attacks Pennywise with molest attack for 50 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 50

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

Bozo attacks Pennywise with nose honk attack for 5 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

Ronald McDonald attacks Bozo with defenestrate attack for 1000 damage.

Bozo is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Ronald McDonald, hp = 100

Pennywise attacks John Wayne Gacy with defenestrate attack for 1000 damage.

John Wayne Gacy is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = Ronald McDonald, hp = 100

Pennywise attacks Ronald McDonald with bite attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = Ronald McDonald, hp = 70

<<<<<<<<<*************>>>>>>>>>>>>>

Ronald McDonald attacks Pennywise with smile attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 15

Clown Name = Ronald McDonald, hp = 70

<<<<<<<<<*************>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 15

Clown Name = Ronald McDonald, hp = 70

Pennywise attacks Ronald McDonald with defenestrate attack for 1000 damage.

Ronald McDonald is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 15

Winner is Pennywise

Program ended with exit code: 0