Stuck programing A Chess Game! HELP

I am trying to program a chess game but i am stuck on moving the pieces and for them to move by the rules.
my .CPP and .H file below
#pragma once

#include “ofMain.h”

class ofApp : public ofBaseApp{

public:
void setup();
void update();
void draw();
int i,j;
int isVisible;

ofImage startGame;
ofImage instruct;
ofSoundPlayer backGroundMusic;
ofRectangle chessGrid[8][8];
ofColor myColors[8][8];
ofImage myBackground;
ofTrueTypeFont largeFont;
ofTrueTypeFont smallFont;
ofTrueTypeFont mediumFont;
int myboardsetup[8][8];


ofImage bpawnPic;
ofPoint bpawnPos[8];

ofImage bbishopPic;
ofPoint bbishopPos[2];

ofImage bknightPic;
ofPoint bknightPos[2];

ofImage brookPic;
ofImage bqueenPic;
ofImage bkingPic;
ofImage whpawnPic;
ofImage whbishopPic;
ofImage whknightPic;
ofImage whrookPic;
ofImage whqueenPic;
ofImage whkingPic;
int pawn=100;
int bishop=305;
int knight =300;
int rook=500;
int queen= 900;
int king= 2000;
int isPlaying;
int startup[8][8]={rook, knight, bishop, queen, king, bishop, knight, rook, pawn, pawn,pawn,pawn,pawn,pawn,pawn, pawn, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -rook, -knight, -bishop, -queen, -king, -bishop, -knight, -rook};



void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

};

#include “ofApp.h”

//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(50);
myBackground.load(“HomeScreen.jpg”);
backGroundMusic.load(“ChessMusic.mp3”);
backGroundMusic.play();
backGroundMusic.setLoop(10);

isVisible=1;
startGame.load("ChessHome.jpg");
instruct.load("directions.jpg");

smallFont.load("font.ttf", 23);
mediumFont.load("font.ttf", 60);
largeFont.load("font.ttf", 200);

isPlaying=0;

for(i=0;i<8;i++)
{
    chessGrid[0][i].set(50+80*i, 50, 75, 75);
    chessGrid[1][i].set(50+80*i, 127, 75, 75);
    chessGrid[2][i].set(50+80*i, 205, 75, 75);
    chessGrid[3][i].set(50+80*i, 282, 75, 75);
    chessGrid[4][i].set(50+80*i, 360, 75, 75);
    chessGrid[5][i].set(50+80*i, 438, 75, 75);
    chessGrid[6][i].set(50+80*i, 516 , 75, 75);
    chessGrid[7][i].set(50+80*i, 594, 75, 75);
    
}
int white[3]={200,200,200};
int teal[3]={150,120,120};
for(i=0;i<8;i++)
{
        if (i%2==0) {
            myColors[0][i].set(teal[0], teal[1], teal[2]);
            myColors[1][i].set(white[0], white[1], white[2]);
            myColors[2][i].set(teal[0], teal[1], teal[2]);
            myColors[3][i].set(white[0], white[1], white[2]);
            myColors[4][i].set(teal[0], teal[1], teal[2]);
            myColors[5][i].set(white[0], white[1], white[2]);
            myColors[6][i].set(teal[0], teal[1], teal[2]);
            myColors[7][i].set(white[0], white[1], white[2]);
        }
        else if(i%2==1)
        {
            myColors[0][i].set(white[0], white[1], white[2]);
            myColors[1][i].set(teal[0], teal[1], teal[2]);
            myColors[2][i].set(white[0], white[1], white[2]);
            myColors[3][i].set(teal[0], teal[1], teal[2]);
            myColors[4][i].set(white[0], white[1], white[2]);
            myColors[5][i].set(teal[0], teal[1], teal[2]);
            myColors[6][i].set(white[0], white[1], white[2]);
            myColors[7][i].set(teal[0], teal[1], teal[2]);

        }
}

bpawnPic.load("blackPawn.png");
whpawnPic.load("whitePawn.png");
brookPic.load("blackRook.png");
whrookPic.load("whiteRook.png");
bbishopPic.load("blackBishop.png");
whbishopPic.load("whiteBishop.png");
bqueenPic.load("blackQueen.png");
whqueenPic.load("whiteQueen.png");
bkingPic.load("blackKing.png");
whkingPic.load("whiteKing.png");
bknightPic.load("blackHorse.png");
whknightPic.load("whiteHorse.png");

}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
//Main Menu------------------------------------------------------------------
if (isPlaying==0) {
ofSetColor(255, 255, 255);
startGame.draw(0, 0, ofGetWidth(), ofGetHeight());

    ofSetColor(100, 100, 100,180);
    ofDrawRectangle(240, 480, 510, 80);
    
    ofSetColor(100, 100, 100,180);
    ofDrawRectangle(390, 330, 220, 80);
    
    ofSetColor(150, 0, 0);
    largeFont.drawString("CHESS", ofGetWidth()/2-430,250);
    mediumFont.drawString("PLAY", ofGetWidth()/2-100, 400);
    mediumFont.drawString("Instructions", ofGetWidth()/2-250, 550);
    
}
///------------------------------------------------------------------
//Instructions------------------------------------------------------------------
if (isPlaying==2) {
    instruct.draw(0,0,ofGetWidth(),ofGetHeight());
    ofSetColor(255,0,0,180);
    ofDrawRectangle(440, 575, 100, 35);
    ofSetColor(255, 150, 255);
    largeFont.drawString("CHESS", ofGetWidth()/2-430, 250);
    mediumFont.drawString("Instructions", 250, 380);
    smallFont.drawString("-Click on any of the following peices you would like to move", ofGetWidth()/4-220, 420);
    smallFont.drawString("-With your mouse click on the box you would like to move to", ofGetWidth()/4-220, 490);
    smallFont.drawString("Back", 450, ofGetHeight()-100);
}
//------------------------------------------------------------------
//---------------------------------------------------------------------

if(isPlaying==1)
{
    myBackground.draw(0, 0, ofGetWidth(), ofGetHeight());
    ofImage(mybackground);
for(i=0;i<8;i++)
{
    for(j=0;j<8;j++){
    ofSetColor(myColors[i][j]);
    ofFill();
    ofDrawRectangle(chessGrid[i][j]);
    }

}
for(i=0;i<8;i++)
{
    for(j=0;j<8;j++)
    {
       if(startup[i][j]==100)
       {
           bpawnPos[j].x=chessGrid[i][j].x;
           bpawnPos[j].y=chessGrid[i][j].y;
           ofSetColor(0, 0, 0);
           bpawnPic.draw(bpawnPos[j].x, bpawnPos[j].y, 75,75);
           ofImage(bpawnPic);
       }
        if(startup[i][j]==-100)
        {
            ofSetColor(255, 255, 255);
            whpawnPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(whpawnPic);
        }
        if(startup[i][j]==305)
        {
            ofSetColor(0, 0, 0);
            bbishopPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(bbishopPic);
        }
        if(startup[i][j]==-305)
        {
            ofSetColor(255, 255, 255);
            whbishopPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(whbishopPic);
        }
        if(startup[i][j]==300)
        {
            ofSetColor(0, 0, 0);
            bknightPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(bknightPic);
        }
        if(startup[i][j]==-300)
        {
            ofSetColor(255, 255, 255);
            whknightPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            printf("%f %f",chessGrid[i][j].x, chessGrid[i][j].y);
            ofImage(whknightPic);
        }
        if(startup[i][j]==500)
        {
            ofSetColor(0, 0, 0);
            brookPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(brookPic);
        }
        if(startup[i][j]==-500)
        {
            ofSetColor(255, 255, 255);
            whrookPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(whrookPic);
        }
        if(startup[i][j]==900)
        {
            ofSetColor(0, 0, 0);
            bqueenPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(bqueenPic);
        }
        if(startup[i][j]==-900)
        {
            ofSetColor(255, 255, 255);
            whqueenPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(whqueenPic);
        }
        if(startup[i][j]==2000)
        {
            ofSetColor(0, 0, 0);
            bkingPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(bknightPic);
        }
        if(startup[i][j]==-2000)
        {
            ofSetColor(255, 255, 255);
            whkingPic.draw(chessGrid[i][j].x, chessGrid[i][j].y, 75,75);
            ofImage(whknightPic);
        }
    }}
    smallFont.drawString("A", 75, 700);
    smallFont.drawString("B", 160, 700);
    smallFont.drawString("C", 240, 700);
    smallFont.drawString("D", 320, 700);
    smallFont.drawString("E", 400, 700);
    smallFont.drawString("F", 480, 700);
    smallFont.drawString("G", 560, 700);
    smallFont.drawString("H", 640, 700);
    
    smallFont.drawString("1", 25, 100);
    smallFont.drawString("2", 25, 180);
    smallFont.drawString("3", 25, 260);
    smallFont.drawString("4", 25, 330);
    smallFont.drawString("5", 25, 410);
    smallFont.drawString("6", 25, 480);
    smallFont.drawString("7", 25, 560);
    smallFont.drawString("8", 25, 640);
    
    
    smallFont.drawString("QUIT", 900, 700);

}

//------------------------------------------------------------------
//---------------------------------------------------------------------

}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key==’ ') {
for (i=0; i<8; i++) {
bpawnPos[1].x=ofGetMouseX();
bpawnPos[1].y=ofGetMouseY();
}
}
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
if (ofGetMousePressed()==1 && isPlaying==2) {
if (ofGetMouseX()<=540 && ofGetMouseX()>=440 && ofGetMouseY()<=610&& ofGetMouseY()>=575) {
isPlaying=0;
}
}
if (ofGetMousePressed()==1 && isPlaying==0) {
if (ofGetMouseX()<=610 && ofGetMouseX()>=390 && ofGetMouseY()<=410 && ofGetMouseY()>=330) {
isPlaying=1;
}
}
if (ofGetMousePressed()==1 && isPlaying==0) {
if (ofGetMouseX()<=750 && ofGetMouseX()>=240 && ofGetMouseY()<=560 && ofGetMouseY()>=480) {
isPlaying=2;
}
}
if (ofGetMousePressed()==1 && isPlaying==1) {
if (ofGetMouseX()<=990 && ofGetMouseX()>=860 && ofGetMouseY()<=735 && ofGetMouseY()>=660) {
isPlaying=0;
}
}

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}

I think if you want an answer you have to explain your problem and how you tried to solve it and what isn’t working a little bit more detailed.

So break it down in small steps…

1 Like