//Header file to create linked list.
#ifndef RANDOMSHAPELISTGEN_H
#define RANDOMSHAPELISTGEN_H
#include <iostream>
#include <list>
#include <stdlib.h>
#include <ctime>
//Where should I put the code "std::"?
class shape
{
public:
shape(){}
virtual ~shape(){;}//destructor
virtual char *getType() = 0;//does any of this actually need to be virtual?
//need code to designate what the score value of each shape is. All shapes are worth 2 points each
private://don't think I need any private
};
class circle : public shape
{
public:
char *getType() {return "circle";}
};
class square : public shape
{
public:
char *getType() {return "square";}
};
class triangle : public shape
{
public:
char *getType() {return "triangle";}
};
typedef list<shape*> shapeList_t;//this sometimes raises an error sometimes doesn't. Its like my computer can't make up it mind.
typedef shapeList_t::iterator shapeListIter_t;//what am I doing wrong here?
shapeList_t myList;//declared this outside functions so multiple functions could use it.
shapeListIter_t myIter;//same as above
shape *curShape;//same as above
shapeList_t makeList()//should I have defined this function perhaps in the cpp file?
{//also am I defining this function correctly? I think eventually I will need to pass something to it, such as what level the game is on, to be passed to shapes(later though for timer.)
int i, numItems=20;//i is a counter, and numItems is simply the number of shapes in the list.
int seed;
seed = time(0);
srand(seed);//makes time the seed for randomization function
// Insert
for (i=0; i<numItems; i++)//for loop to fill list.
{
switch (rand() % 3)//random function here, seeded by srand.
{
case 0: myList.push_back(new circle); break;
case 1: myList.push_back(new square); break;
case 2: myList.push_back(new triangle); break;
}
}
// Display. Will need to be changed to keep console screen from being a mess.
//Also will need to be changed so that only one object at a time is listed, and clears each time object is moved from list or deleted.
for (myIter=myList.begin(); myIter!=myList.end(); myIter++)
{
curShape = *myIter;
std::cout << "Shape type: " << curShape->getType() << endl;
}
return myList;//Not sure if this right.
}
void deleteList()//function to delete list. Again should I put this in the cpp file?
//Also, will this work for when the list is empty or not filled with a number different than 20?
{
// Cleanup
for (myIter=myList.begin(); myIter!=myList.end(); myIter++)
{
curShape = *myIter;
delete curShape; // free the memory that this list item consumes - calls curShape's destructor
}
myList.clear(); // free the memory that the list uses to point to each list item - empties the list
}
#endif
// char input
//for gameover=false
//run game(will call all functions at some point, probably multiple times.
//if input = s execute save
//if input = j execute join
//if input = d execute drop
//if input = e execute redeem
//gameover conditions met: go to main menu.
//cout totalScore
//
#include <iostream>
//May need to include another header file.
#include "RandomShapeListGen.h"
using namespace std;
int main()
{
bool stackFull = false; //initial value, changes based on return of a function. Controls level loop.
bool listEmpty = false; //initial value, changes based on return of a function. Controls level loop.
bool gameOver = false;//initial value, controls main loop.
bool levelEndCondition= false; //controls level loop.
int userScore, totalScore=0; //initial values, totalScore is found at the end of every level. userScore is determined by user functions.
int commonShapeScore;
int level;
while (gameOver==false)
{
for (level=1; level<=3; level++)//I haven't been able to quite test this, but will it start at level 1 or automatically move to level 2?
//Do I need to change the initialization to level=0?
{
//Code to create new list using resources from header file.
//code to create stack using resources from a header file(not done yet, not sure how my code for this will look.)
//commonShapeScore=//Code to find number of most abundant shape and multiply by 2. A function.
while (levelEndCondition==false)
{
userScore=0;
/*[Display contents of the top of the stack and contents at the beginning of list.];
[perform user functions on stack and list:
parameters of functions:
Shape score: 2
redeemableScore X = 5*level (if score is greater than this, it is redeemable);
user controlled function to move shape at beginning of list to top of stack and next shape in list becomes shape at beginning;
automated function that scores points whenever enough shapes of the same type are placed consecutively on top eachother in stack];
[Change displayed representation of stack and list based on what user functions were called (without multiple displays appearing for each time a change is made if possible)];
stackFull=[function to test if stack is full, returns bool];
listEmpty=[function to test if list is empty, returns bool];*/
if (stackFull==true)
{
levelEndCondition=true;
}
else if (listEmpty==true)
{
levelEndCondition=true;
}
else
{
cout<<""<<endl;
}
}
totalScore+=userScore;
//Code to delete list.
//Code to delete stack.
if (userScore < (3/4 * commonShapeScore))
{
gameOver=true;
cout<<3/4*commonShapeScore<<" was the minimum score to proceed. You did not reach it."<<endl;
cout<<"Game Over"<<endl;
break;
}
else
{
if (level==3)
{
cout<<"You beat all the levels!"<<endl;
gameOver=true;
}
else
{
cout<<"Going to next level... Press enter to continue:"<<endl;
//code to make program wait for enter to be pressed before continuing.
}
}
}
}
cout<<totalScore<<" is your final score."<<endl;
return 0;
}
Oh and ignore the text above the include statement in the cpp file, the bottom file, that was some pseudocode I was using earlier. Sorry about that.

New Topic/Question
Reply



MultiQuote






|