Texture maping problem

Hello,
I want to create a little game to experiment with 3D in openframworks.
But I have a problem with textures mapping:


I want that brick texture goes to the walls and top and that cobblestone texture goes to the floor
Here is the texture:

And my code:

    m.setMode(OF_PRIMITIVE_TRIANGLES);

    m.addVertex(ofVec3f(x,y,0));
    m.addTexCoord(ofVec2f(0,0));
    m.addVertex(ofVec3f(x+this->caseSize,y,0));
    m.addTexCoord(ofVec2f(0.5,0));
    m.addVertex(ofVec3f(x+this->caseSize,y+this->caseSize,0));
    m.addTexCoord(ofVec2f(0.5,1));
    m.addVertex(ofVec3f(x,y+this->caseSize,0));
    m.addTexCoord(ofVec2f(0,1));

    if (mode == 0){
        //add indexes
        m.addIndex(this->drawIndex);
        m.addIndex(this->drawIndex+2);
        m.addIndex(this->drawIndex+1);

        m.addIndex(this->drawIndex);
        m.addIndex(this->drawIndex+2);
        m.addIndex(this->drawIndex+3);
    } else {
        m.addVertex(ofVec3f(x,y,this->caseSize));
        m.addTexCoord(ofVec2f(0.5,0));
        m.addVertex(ofVec3f(x+this->caseSize,y,this->caseSize));
        m.addTexCoord(ofVec2f(1,0));
        m.addVertex(ofVec3f(x+this->caseSize,y+this->caseSize,this->caseSize));
        m.addTexCoord(ofVec2f(1,1));
        m.addVertex(ofVec3f(x,y+this->caseSize,this->caseSize));
        m.addTexCoord(ofVec2f(0.5,1));


        m.addIndex(this->drawIndex+4);
        m.addIndex(this->drawIndex+6);
        m.addIndex(this->drawIndex+5);
        m.addIndex(this->drawIndex+4);
        m.addIndex(this->drawIndex+6);
        m.addIndex(this->drawIndex+7);

        x /= this->caseSize;
        y /= this->caseSize;

        if(x > 0)  if(this->layout.at(y).at(x-1).z != 1){
            m.addIndex(this->drawIndex);
            m.addIndex(this->drawIndex+7);
            m.addIndex(this->drawIndex+3);
            m.addIndex(this->drawIndex);
            m.addIndex(this->drawIndex+7);
            m.addIndex(this->drawIndex+4);
        }
        if(y > 0) if(this->layout.at(y-1).at(x).z != 1){
            m.addIndex(this->drawIndex);
            m.addIndex(this->drawIndex+5);
            m.addIndex(this->drawIndex+1);
            m.addIndex(this->drawIndex);
            m.addIndex(this->drawIndex+5);
            m.addIndex(this->drawIndex+4);
        }

        if (x < (int)this->layout.at(y).size()-1)  if(this->layout.at(y).at(x+1).z != 1){
            m.addIndex(this->drawIndex+1);
            m.addIndex(this->drawIndex+6);
            m.addIndex(this->drawIndex+2);
            m.addIndex(this->drawIndex+1);
            m.addIndex(this->drawIndex+6);
            m.addIndex(this->drawIndex+5);
        }

        if(y < (int)this->layout.size()-1) if(this->layout.at(y+1).at(x).z != 1){
            m.addIndex(this->drawIndex+2);
            m.addIndex(this->drawIndex+7);
            m.addIndex(this->drawIndex+6);
            m.addIndex(this->drawIndex+2);
            m.addIndex(this->drawIndex+7);
            m.addIndex(this->drawIndex+3);
        }
    }

    this->drawIndex += ((mode > 0) ? 8 : 4);

This is a method of a class where
m is a ofMesh
x and y are the coordinates of the “block”
this->drawIndex is the last index of last “block”
mode is a int that for the moment is 0 if the block is a ground or 1 if this is a wall
this->caseSize is the size of a block

This code is for testing purposes i will add arrays and for loop to create a cleanest code.
Thanks for your help.