Permalink
Browse files

I AM THE KING DEBUGGER.

  • Loading branch information...
1 parent 73e403b commit bf73040c89b3488955abfdcf7ba561e845886822 @masra91 masra91 committed Apr 29, 2012
Showing with 50 additions and 39 deletions.
  1. +23 −14 Checkers.cpp
  2. +1 −2 abstractGame.cpp
  3. +21 −13 gamePiece.cpp
  4. +3 −2 gamePiece.h
  5. +2 −8 reversiGame.cpp
View
@@ -29,8 +29,8 @@ Checkers :: Checkers(string playerB, string playerR)
playerB_ = playerB;
playerR_ = playerR;
- checkerPiece black = checkerPiece(BLACK);
- checkerPiece red = checkerPiece(RED);
+ checkerPiece black = checkerByColor(BLACK);
+ checkerPiece red = checkerByColor(RED);
bool offsetLine = false;
@@ -184,28 +184,37 @@ void Checkers :: turn()
if(moveCheck(start_, dest_))
{
- state_ = EXTENDEDTURN;
+
//superfluous for it's boolean check function, but used to ensure that the member variable
//is accurate for the current move and current jummped piece.
- if(jumpedPiece(start_, dest_))
+ if(jumpedPiece(start_, dest_) || currentMoveType_ == UP || currentMoveType_ == DOWN)
{
movePiece();
- removePiece(jumped_);
+ if( currentMoveType_ == JUMPUP || currentMoveType_ == JUMPDOWN)
+ {
+ removePiece(jumped_);
+ state_ = EXTENDEDTURN;
+ }
}
while(state_ == EXTENDEDTURN)
{
+ print();
prompt();
listen();
+ if(moveCheck(start_, dest_))
+ {
+ if(currentMoveType_ == JUMPUP || currentMoveType_ == JUMPDOWN)
+ {
+ movePiece();
+ removePiece(jumped_);
+ }
+ }
}
}
- else
- {
- return;
- }
-
-
+
+ isBlacksTurn_ = (!isBlacksTurn_);
}
void Checkers :: prompt()
@@ -234,17 +243,17 @@ void Checkers :: prompt()
break;
case NEEDLOC:
cout << name << "'S TURN: " << endl;
- cout << "Moving piece at " << start_ << ". Where would you like to move it?" ;
cout << "Type 'listmoves' to see the available moves for this piece." << endl;
+ cout << "Moving piece at " << start_ << ". Where would you like to move it? " ;
break;
case EXTENDEDTURN:
cout << "Continuing turn. Moving piece originally located at " << original_ << "." << endl;
- cout << "Piece currently located at " << start_ << ". Where would you like to move it? ";
cout << "Type 'listmoves' to see the available moves for this pieces. Type 'finished' or 'done' to end your turn. " << endl;
+ cout << "Piece currently located at " << start_ << ". Where would you like to move it? ";
break;
default:
abstractGame :: prompt();
-
+ break;
}
}
View
@@ -167,8 +167,7 @@ void abstractGame::newGame(int argc, abstractGame*& pointer)
}
else if (type_ == REVERSI)
{
- reversiGame game = *new reversiGame(firstvar, secondvar);
- pointer = &game;
+ pointer = new reversiGame(firstvar, secondvar);
pointer->nameChecker();
type_ = REVERSI;
return;
View
@@ -126,31 +126,39 @@ bool const numberSquare :: operator<(const numberSquare &other)
checkerPiece :: checkerPiece()
{
- checkerPiece(BLACK);
+ name_ = "black checker";
+ color_ = BLACK;
+ isKing_ = false;
+ symbol_ = "X";
+ value_ = 0;
}
-checkerPiece :: checkerPiece(pieceColor color)
+checkerPiece checkerByColor(pieceColor color)
{
- value_ = color;
- color_ = color;
- isKing_ = false;
+ checkerPiece piece = checkerPiece();
+
+ piece.value_ = color;
+ piece.color_ = color;
+ piece.isKing_ = false;
switch(color)
{
case BLACK:
- name_ = "black checker";
- symbol_="X";
+ piece.name_ = "black checker";
+ piece.symbol_="X";
break;
case RED:
- name_ = "red checker";
- symbol_="O";
+ piece.name_ = "red checker";
+ piece.symbol_="O";
break;
default:
- value_=0;
- color_=INVALID_COLOR;
- name_="badpiece";
- symbol_="ERROR:BADPIECE";
+ piece.value_=0;
+ piece.color_=INVALID_COLOR;
+ piece.name_="badpiece";
+ piece.symbol_="ERROR:BADPIECE";
break;
}
+
+ return piece;
}
void checkerPiece :: flip()
View
@@ -72,13 +72,14 @@ struct reversiPiece : gamePiece
struct checkerPiece : gamePiece
{
checkerPiece();
- checkerPiece(pieceColor color);
bool isKing_;
virtual void flip();
void king();
- void set(gamePiece piece);
+ void set(gamePiece p);
};
+checkerPiece checkerByColor(pieceColor color);
+
#endif
View
@@ -55,7 +55,7 @@ ostream& operator<<(ostream &stream, const reversiGame &game)
{
// formatting set-up to account for variable length symbols and readability
char space = ' ';
- string spacing(game.maxSymbol_, space); // adds space the width of the max length symbol
+ string spacing(1, space); // adds space the width of the max length symbol
char verticalBar = '|';
int dashCount = (game.boardx_ * 3) + (game.boardx_ - 1);
string dashes(dashCount,'-');
@@ -70,12 +70,6 @@ ostream& operator<<(ostream &stream, const reversiGame &game)
{
if(x==0 && y!=0)
{
- if (getLength(y-1) < game.maxSymbol_)
- {
- //determine number spaces to add before y-axis symbol (only need if we are using nxn boards)
- string spaces(game.maxSymbol_ - getLength(y-1), space);
- stream << spaces;
- }
stream << y-1; //prints vertical axis
}
else if(game.board_.count(Point(x-1, y-1)) == 1) //check if there is a piece at that position
@@ -104,7 +98,7 @@ ostream& operator<<(ostream &stream, const reversiGame &game)
void reversiGame :: print()
{
- cout << self_ << endl;
+ cout << *this << endl;
}
bool reversiGame :: done()

0 comments on commit bf73040

Please sign in to comment.