Hi,
I have been working on a Reversi/Othello game using QT and have got stuck when trying to implement a new game function which will return the game state back to its original state.
reversigame.cpp
/**
@file reversigame.cpp
@author Rob Charrett
@brief ReversiGame implementation.
*/
#include "reversigame.h"
ReversiGame::ReversiGame(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags), gameBoard(GameGrid(10,10,this))
{
// initialise UI based on reversigame.ui form file
ui.setupUi(this);
// display the board in the central widget location, has been created with default
// size of 10x10
setCentralWidget(&gameBoard);
// default to new game
state = GAME_RUNNING;
// set up status bar
setupStatusBar();
// set up menu bar
setupMenu();
}
ReversiGame::~ReversiGame()
{
}
void ReversiGame::setupStatusBar()
{
// set starting text of each label
if(playerTurn == PLAYER_ONE)
{
feedback.setText(tr("PLAYER ONE"));
}
else if(playerTurn == PLAYER_TWO)
{
feedback.setText(tr("PLAYER TWO"));
}
player1Score.setText(tr("Player 1: "));
player2Score.setText(tr("Player 2: "));
// add widgets to status bar
statusBar()->addWidget(&feedback,1);
statusBar()->addWidget(&player1Score);
statusBar()->addWidget(&player2Score);
}
void ReversiGame::setupMenu()
{
// add a new menu ("File")
QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
createNewAction = fileMenu->addAction(tr("&Create New Game"), this, SLOT(newg()));
createNewAction->setShortcut(tr("Ctrl+N"));
loadSavedAction = fileMenu->addAction(tr("&Load A Saved Game"), this, SLOT(load()));
loadSavedAction->setShortcut(tr("Ctrl+L"));
quitAction = fileMenu->addAction(tr("&Quit"), this, SLOT(quit()));
quitAction->setShortcut(tr("Ctrl+Q"));
/*saveCurrentAction = fileMenu->addAction(tr("&Save Current Game"), this, SLOT(Save Current()));
saveCurrentAction->setShortcut(tr("Ctrl+S"));
ReplayAction = fileMenu->addAction(tr("&Play Again?"), this, SLOT(Again?()));
ReplayAction->setShortcut(tr("Ctrl+P"));*/
}
void ReversiGame::boardClicked()
{
// Get the GridNode on the board that received the click (the origin of the signal
// that kicked off this function)
GridNode* slot = (GridNode*) sender();
// Get the position of the slot in the grid.
NodePosition pos = slot->getPosition();
GridNode* gridNode = gameBoard.getNode(pos);
if(playerTurn == PLAYER_ONE)
{
if(slot -> getOwner() == OWNER_NONE)
{
slot -> setOwner (OWNER_PLAYER1);
playerTurn = PLAYER_TWO;
}
}
else if(playerTurn == PLAYER_TWO)
{
if(slot -> getOwner() == OWNER_NONE)
{
slot -> setOwner (OWNER_PLAYER2);
playerTurn = PLAYER_ONE;
}
}
else
{
playerTurn = PLAYER_ONE;
}
setupStatusBar();
}
//
//void ReversiGame::quit
//
//void ReversiGame::load()
//{
//}
//
//void ReversiGame::save()
//{
//}
void ReversiGame::newg()
{
NodePosition pos(0,0);
GridNode* gridNode = gameBoard.getNode(pos);
for(pos.col = 0; pos.col <10; pos.col++)
{
for(pos.row = 0; pos.row <10; pos.row++)
{
if(gridNode->getOwner() == OWNER_NONE)
{
if (pos.col == 5 && pos.row == 5)
{
getOwner = OWNER_PLAYER1;
}
if (pos.col == 4 && pos.row == 4)
{
getOwner = OWNER_PLAYER1;
}
if (pos.col == 4 && pos.row == 5)
{
getOwner = OWNER_PLAYER2;
}
if (pos.col == 5 && pos.row == 4)
{
getOwner = OWNER_PLAYER2;
}
}
}
}
}
void ReversiGame::quit()
{
// currently, simply exit the application
qApp->quit();
}
reversigame.h
/**
@file reversigame.h
@author Rob Charrett
@brief ReversiGame and GameState definitions.
@description This file contains the definition of the core ReversiGame class and the
related GameState enum.
*/
#ifndef REVERSIGAME_H
#define REVERSIGAME_H
#include <QtGui/QMainWindow>
#include <QtGui/QLabel>
#include <QtGui/QAction>
#include "ui_reversigame.h"
#include "gameboard.h"
/** Enumeration used for handling the current game states in ReversiGame */
enum GameState {GAME_NONE, GAME_RUNNING, GAME_FINISHED};
enum Turn {PLAYER_ONE, PLAYER_TWO};
/**
@brief The ReversiGame class forms the core of the ReversiGame application.
@description This class forms the core of the ReversiGame application, handling the
GUI, user interaction and game logic. The GUI is initialised through
*/
class ReversiGame : public QMainWindow
{
Q_OBJECT
public:
/** ReversiGame constructor */
ReversiGame(QWidget *parent = 0, Qt::WFlags flags = 0);
~ReversiGame();
protected:
/**
Menu setup function. Change this to change the items appearing in the menu at
start up, as well as any actions that should be associated with said items.
*/
void setupMenu();
/**
Status bar setup function. Change this to change the items and text appearing
in the status bar at start up.
*/
void setupStatusBar();
private:
/** Class generated by reversigame.ui form file */
Ui::ReversiGameClass ui;
/** Game board, fwds mouse clicks to boardClicked() (see ReversiGame constructor) */
GameGrid gameBoard;
/** Current game state */
GameState state;
Turn playerTurn;
/** Label (text field) used for displaying player1's score in the status bar */
QLabel player1Score;
/** Label (text field) used for displaying player2's score in the status bar */
QLabel player2Score;
/** Label (text field) used for displaying feedback in the status bar */
QLabel feedback;
/** Action used in menu bar, connected to the quit() slot */
QAction* quitAction;
QAction* createNewAction;
QAction* loadSavedAction;
/*QAction* ReplayAction;
QAction* saveCurrentAction;*/
public slots:
/**
Public slot, receiving signals from the GameGrid (see ReversiGame constructor).
This function is responsible for catching user interaction, and handling the game
logic that follows said interaction.
*/
void boardClicked();
protected slots:
private slots:
/** Private slot, quits the application upon receiving a signal */
void quit();
void newg();
};
#endif // REVERSIGAME_H
I am getting the error C2065: undeclared identifier for 'getOwner'.
I know this is probably quite obvious but have spent far too long staring at a pc screen! so any help would be greatly appreciated.