Ahha, got rid of those errors, heres an update for anyone that might be interested. In case you haven't guessed i'm making a Towers of Hanoi clone. If you have any comments or suggestions on my progress so far then that would be greatly appreciated.
Header File:
Code:
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#define OK 1
#define FAILED 0
#include <string>
#include <vector>
#include <iostream>
using namespace std;
struct ring{
int size;
};
class CPeg{
public:
CPeg(vector<int> pStack,const string& itsName):
pegStack(pStack),name(itsName)
{}
int addRing(int rSize){
if(pegStack.size() > 0){
if(rSize < pegStack.back()){
pegStack.push_back(rSize);
return OK;
}else
return FAILED;
}else{
pegStack.push_back(rSize);
return OK;
}
}
void removeRing(){ pegStack.pop_back(); }
void showStack(){
for(int i = pegStack.size() - 1; i >= 0; i--)
cout << pegStack[i] << endl;
}
private:
vector<int> pegStack;
string name;
};
class CDifficulty{
public:
CDifficulty(const char* itsSetting = "",const int nRings = 3):
setting(itsSetting),numRings(nRings)
{}
CDifficulty(const string& itsSetting,int nRings):
setting(itsSetting),numRings(nRings)
{}
int setDifficulty(const string itsSetting){
setting = itsSetting;
if(setting == "easy"){
numRings = 3;
return OK;
}else if(setting == "medium"){
numRings = 5;
return OK;
}else if(setting == "hard"){
numRings = 7;
return OK;
}else
return FAILED;
}
private:
string setting;
int numRings;
};
Main source file:
Code:
#include "definitions.h"
/*Prototypes*/
COption* mainMenu();
COption* diffMenu();
COption* playMenu();
int main(){
vector<int> pStack;
/*Create the pegs*/
CPeg* A = new CPeg(pStack,"A");
CPeg* B = new CPeg(pStack,"B");
CPeg* C = new CPeg(pStack,"C");
/*Create menu options*/
COption* mainOpts = mainMenu();
COption* diffOpts = diffMenu();
COption* playOpts = playMenu();
/*Create Menus*/
CMenu* mainMenu = new CMenu("MAIN MENU",mainOpts);
CMenu* diffMenu = new CMenu("DIFFICULTY MENU",diffOpts);
CMenu* playMenu = new CMenu("PLAY MENU",playOpts);
delete A,B,C,mainMenu;
delete diffMenu,playMenu;
delete[] mainOpts;
delete[] diffOpts;
delete[] playOpts;
return 0;
}
COption* mainMenu(){
COption* o_array = new COption[4];
COption num1("Choose Difficulty",1);
COption num2("Read rules",2);
COption num3("Play game",3);
COption num4("Leader board",4);
COption num5("Exit",5);
o_array[0] = num1;
o_array[1] = num2;
o_array[2] = num3;
o_array[3] = num4;
o_array[4] = num5;
return o_array;
}
COption* diffMenu(){
COption* o_array = new COption[3];
COption num1("Easy",1);
COption num2("Medium",2);
COption num3("Hard",3);
COption num4("Main menu",4);
o_array[0] = num1;
o_array[1] = num2;
o_array[2] = num3;
o_array[3] = num4;
return o_array;
}
COption* playMenu(){
COption* o_array = new COption[6];
COption num1("Move From A to B",1);
COption num2("Move From A to C",2);
COption num3("Move From B to A",3);
COption num4("Move From B to C",4);
COption num5("Move From C to A",5);
COption num6("Move From C to B",6);
COption num7("Main Menu",7);
o_array[0] = num1;
o_array[1] = num2;
o_array[2] = num3;
o_array[3] = num4;
o_array[4] = num5;
o_array[5] = num6;
o_array[6] = num7;
return o_array;
}