Header of my Game class:
class Game
{
public:
Game();
void StartGame();
void DrawBoard();
bool IsCheckMate();
Piece* Board[8][8];
};




Posted 09 March 2009 - 03:45 PM
class Game
{
public:
Game();
void StartGame();
void DrawBoard();
bool IsCheckMate();
Piece* Board[8][8];
};
Posted 09 March 2009 - 03:51 PM
//Queen.cpp for example
#include "Queen.h" //Queen.h will probably include Game.h
void Queen::MovePiece(Piece* theBoard)
{
theBoard->update(); //or whatever
}
//OR
void Queen::MovePiece(Game* theGame)
{
theGame->theBoard->update(); //or whatever
}
This post has been edited by KYA: 09 March 2009 - 03:52 PM
Posted 09 March 2009 - 03:54 PM
Posted 09 March 2009 - 04:59 PM
Posted 09 March 2009 - 05:25 PM
void Queen::Move(int desx, int desy)
{
Board[desy][desx] = *this;
Board[LocY][LocX] = NULL;
}
Posted 09 March 2009 - 07:55 PM
Posted 09 March 2009 - 09:54 PM
int main()
{
Game* theGame = new Game(); //initialize, etc..
theGame->startGame();
//what controls your Piece class?
}
Posted 09 March 2009 - 10:15 PM
// Queen.h
#pragma once
#include "Piece.h"
#include "Game.h"
class Queen: public Piece
{
public:
Queen(int locx, int locy, int side);// Constructor
void Draw(); // Draws the Queen
void Move(int desx, int desy); // Moves the Queen
myGame.Board;
};
// Queen.cpp
#include "Queen.h"
#include "Game.h"
Queen::Queen(int locx, int locy, int side)
{
LocX = locx;
LocY = locy;
Side = side;
}
void Queen::Draw()
{
cout << " Q ";
}
void Queen::Move(int desx, int desy)
{
myGame.Board[desy][desx] = *this; // These two lines are where my problem is arising
myGame.Board[LocY][LocX] = NULL; // I'm lost on how to make these calls to myGame.Board valid statements
}
// Piece.h
#pragma once
class Piece
{
public:
Piece();
virtual void Draw() = 0;
virtual void Move(int desx, int desy) = 0;
int LocX;
int LocY;
int Side;
};
// Game.h
#pragma once
#include "Piece.h"
#include "Rook.h"
#include "Knight.h"
#include "Bishop.h"
#include "Queen.h"
#include "King.H"
#include "Pawn.h"
using namespace std;
class Game
{
public:
Game();
void StartGame();
void DrawBoard();
bool IsCheckMate();
Piece* Board[8][8];
};
// Game.cpp (some of it)
#include "Game.h"
#include "Piece.h"
#include <iostream>
using namespace std;
#define NULL 0
Game::Game()
{
// A sample of how I'm initializing the pieces
Rook* bRook1 = new Rook(0, 0, 2);
Board[0][0] = bRook1;
Knight* bKnight1 = new Knight(0, 1, 2);
Board[0][1] = bKnight1;
Bishop* bBishop1 = new Bishop(0, 2, 2);
Board[0][2] = bBishop1;
for (int i = 2; i < 6; i++)
for (int j = 0; j < 8; j++)
Board[i][j] = NULL;
}
void Game::StartGame()
{
int movex, movey, finalx, finaly;
while(!IsCheckMate())
{
DrawBoard();
cout << "Player 1 to move:" << endl;
cout << "Move from: ";
cin >> movex >> movey;
cout << "Move to: ";
cin >> finalx >> finaly;
Board[movey][movex]->Move(finalx, finaly);
}
}
This post has been edited by Restrikted: 09 March 2009 - 10:17 PM
Posted 10 March 2009 - 01:20 PM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
