I just dont really understand yet how it can be implemented in a game concept.
You say you understand how OO works and all the concepts and such, right? If that's really how it is then not seeing a good fit right away means that OO might not be a good idea. For you, I think you're trying to apply organizational patterns with OO to a project that doesn't need it.
When you write object-based stuff, it means that you're using objects for the data hiding and encapsulation benefits, but you don't really need inheritance and polymorphism for the organization benefits that only large projects really need.
I'm gonna play the part of a naysayer if ya don't mind.You say you understand how OO works and all the concepts and such, right? If that's really how it is then not seeing a good fit right away means that OO might not be a good idea. For you, I think you're trying to apply organizational patterns with OO to a project that doesn't need it.
There's more to objects than just the full blown OO that you've prolly been learning. An object-based method is more common than an object-oriented method, if that makes any sense at all.When you write object-based stuff, it means that you're using objects for the data hiding and encapsulation benefits, but you don't really need inheritance and polymorphism for the organization benefits that only large projects really need.
When you write object-oriented stuff, the main win comes from being able to use inheritance hierarchies to organize the concepts in a big project. That's a full OO approach, and you don't really need it unless your project is too big to get a big picture view without getting a headache.
My (psychotic as my colleagues like to say) guess is that you're trying to go object-oriented and it's confusing you because you don't need that level of abstraction. If you drop down a level to object-based design, you'll prolly have more luck breaking your game concepts up into objects.![]()
What (or who) I need is a guide though.
If anyone has an example of their own game it would be very helpful for me if you could send it over so I can check out the source code and get into the game programmers mind.
Please help, thanks in advance :cheesy:


3. Board (the 4x4 playing board that will consist of a 2-dimensional array of type int - int playingBoard[4][4])
4. Location (I'm not sure of this one, but this is the location or block that the pawn will move to on the board?...)
#include <iostream>
using namespace std;
enum PieceType { NoPiece, Queen, Bishop, Horse, Castle };
enum PlayerNum { NoPlayer, Player1, Player2 };
// Square is each individual block the playing board will consist of. Each block
// is considered to have 3 member data: type of piece that occupies that block,
// the player whose piece that is, and the position it holds.
class Square
{
public:
Square(){}
~Square(){}
PieceType GetItsPieceType() const { return itsPieceType; }
void SetItsPieceType(PieceType type) { itsPieceType = type; }
PlayerNum GetItsPlayerNum() const { return itsPlayerNum; }
void SetItsPlayerNum(PlayerNum num) { itsPlayerNum = num; }
int GetItsX() const { return itsX; }
void SetItsX(int x) { itsX = x; }
int GetItsY() const { return itsY; }
void SetItsY(int y) { itsX = y; }
private:
PieceType itsPieceType;
PlayerNum itsPlayerNum;
int itsX;
int itsY;
};
// PlayingBoard is the board of the game which consists of a 16 block, 4x4 square
// playing field of class Square
class PlayingBoard
{
public:
PlayingBoard(); // initialize the blcok values in the board constructor
~PlayingBoard(){}
void Draw(); // draws the playing board
private:
Square itsBoard[4][4];
};
PlayingBoard::PlayingBoard()
{
// initialize square's x and y positions
for (int i=0; i<4; i++)
{
for (int j=0; j<4; j++)
{
itsBoard[i][j].SetItsX(i);
itsBoard[i][j].SetItsY(j);
}
}
// initialize pawn positions for player 1
itsBoard[0][0].SetItsPieceType(Queen);
itsBoard[0][0].SetItsPlayerNum(Player1);
itsBoard[2][0].SetItsPieceType(Bishop);
itsBoard[2][0].SetItsPlayerNum(Player1);
itsBoard[1][3].SetItsPieceType(Horse);
itsBoard[1][3].SetItsPlayerNum(Player1);
itsBoard[3][3].SetItsPieceType(Castle);
itsBoard[3][3].SetItsPlayerNum(Player1);
// initialize pawn positions for player 2
itsBoard[0][3].SetItsPieceType(Queen);
itsBoard[0][3].SetItsPlayerNum(Player2);
itsBoard[2][3].SetItsPieceType(Bishop);
itsBoard[2][3].SetItsPlayerNum(Player2);
itsBoard[1][0].SetItsPieceType(Horse);
itsBoard[1][0].SetItsPlayerNum(Player2);
itsBoard[3][0].SetItsPieceType(Castle);
itsBoard[3][0].SetItsPlayerNum(Player2);
// initialize other pawn positions to NoPlayer (empty)
itsBoard[0][1].SetItsPieceType(NoPiece);
itsBoard[0][1].SetItsPlayerNum(NoPlayer);
itsBoard[1][1].SetItsPieceType(NoPiece);
itsBoard[1][1].SetItsPlayerNum(NoPlayer);
itsBoard[2][1].SetItsPieceType(NoPiece);
itsBoard[2][1].SetItsPlayerNum(NoPlayer);
itsBoard[3][1].SetItsPieceType(NoPiece);
itsBoard[3][1].SetItsPlayerNum(NoPlayer);
itsBoard[0][2].SetItsPieceType(NoPiece);
itsBoard[0][2].SetItsPlayerNum(NoPlayer);
itsBoard[1][2].SetItsPieceType(NoPiece);
itsBoard[1][2].SetItsPlayerNum(NoPlayer);
itsBoard[2][2].SetItsPieceType(NoPiece);
itsBoard[2][2].SetItsPlayerNum(NoPlayer);
itsBoard[3][2].SetItsPieceType(NoPiece);
itsBoard[3][2].SetItsPlayerNum(NoPlayer);
}
void PlayingBoard::Draw()
{
cout << endl;
cout << " 0 1 2 3 \n";
cout << " ----------------\n";
for (int i=0; i<4; i++)
{
cout << i << "| ";
for (int j=0; j<4; j++)
{
switch (itsBoard[i][j].GetItsPlayerNum())
{
case Player1 : cout << "p1"; break;
case Player2 : cout << "p2"; break;
case NoPlayer : cout << "__"; break; // no player in square
}
switch (itsBoard[i][j].GetItsPieceType())
{
case Queen: cout << "Q "; break;
case Bishop: cout << "B "; break;
case Horse: cout << "H "; break;
case Castle: cout << "C "; break;
case NoPiece : cout << "_ "; break; // no piece in square
}
}
cout << endl;
}
cout << endl;
}
// Pawn is an abstract class that will be used to create specific pawns such as
// Queen, Bishop, Horse and Castle.
class Pawn
{
public:
Pawn(){}
~Pawn(){}
int GetItsCurrentX() const { return itsCurrentX; }
void SetItsCurrentX(int x) { itsCurrentX = x; }
int GetItsCurrentY() const { return itsCurrentY; }
void SetItsCurrentY(int y) { itsCurrentY = y; }
// Move() is a function that will enable the user to move a certain pawn
// to a specific location on the board. All tests to whether it is a valid
// move will be held in the driver program. Therefore, it can be taken for
// granted that Move() will always be valid and will be used without any
// further checks.
/*
what will move() have as parameters? a square location? the whole board?
a new X location, a new Y location, player who is moving? pawn type that
is to be moved?
*/
private:
int itsCurrentX;
int itsCurrentY;
};
// Queen is a class derived from the Pawn class. It inherits all its data and
// functions and also includes its own if needed.
class QueenPawn : public Pawn
{
public:
QueenPawn(){}
~QueenPawn(){}
};
// Bishop is a class derived from the Pawn class. It inherits all its data and
// functions and also includes its own if needed.
class BishopPawn : public Pawn
{
public:
BishopPawn(){}
~BishopPawn(){}
};
// Horse is a class derived from the Pawn class. It inherits all its data and
// functions and also includes its own if needed.
class HorsePawn : public Pawn
{
public:
HorsePawn(){}
~HorsePawn(){}
};
// Castle is a class derived from the Pawn class. It inherits all its data and
// functions and also includes its own if needed.
class CastlePawn : public Pawn
{
public:
CastlePawn(){}
~CastlePawn(){}
};
// Player is a class which represents the 2 players in the game. Each player has
// one of each available pawn. This is represented by a has-a relationship,
// including an object instantiation for each pawn in the player class.
class Player
{
public:
Player(){}
~Player(){}
// the user must be able to move a pawn. This is, basically, all he/she
// can do in the game. This Move() function should trigger the pawn Move()
// in the Pawn class. The player will have a seperate move function for
// all pawns (MoveQueen, MoveBishop, etc) so that the specific value for
// each pawn can be sent up to the Move() function in Pawn class as a
// parameter.
// ie MoveQueen() { Pawn::Move(..., PawnType Queen, int newX, int newY); }
private:
QueenPawn Queen;
BishopPawn Bishop;
HorsePawn Horse;
CastlePawn Castle;
};
// main program
int main()
{
PlayingBoard GameBoard; // initialize the playing board
Player Player1; // initialize player 1
Player Player2; // initialize player 2
GameBoard.Draw(); // draw the current playing board, expected result:
/////////////////////////
// 0 1 2 3 //
// ---------------- //
// 0| p1Q ___ ___ p2Q //
// 1| p2H ___ ___ p1H //
// 2| p1B ___ ___ p2B //
// 3| p2C ___ ___ p1C //
// //
/////////////////////////
return 0;
}| DaniWeb Message | |
| Cancel Changes | |