1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
using namespace std;
//Produce classes
class FOOD
{
public:
int x;
int y;
int stunErbij;
FOOD *ptr;
FOOD(int x, int y, int stunErbij);
};
vector<FOOD*> ptrvector;
FOOD::FOOD(int x_input, int y_input, int stunErbij_input)
{
x = x_input;
y = y_input;
stunErbij =stunErbij_input;
ptr = this;
ptrvector.push_back(ptr);
}
bool Compare(int x_input, int y_input, vector<FOOD*>)
{
bool toggle = false;
for(int fooditer = 0; fooditer < ptrvector.size(); fooditer++)
{
if(ptrvector[fooditer]->x == x_input && ptrvector[fooditer]->y ==y_input){toggle = true;}
}
return toggle;
}
class APPENDIX
{
public:
int x;
int y;
int stun;
APPENDIX(int x,int y, int stun) // Init-constuctor
{
this->x = y;
this->y = x;
this->stun = stun;
}
};
class PLAYER
{
public:
int x;
int y;
int punten;
PLAYER(int x,int y, int punten) // Init-constructor.
{
this->x = y;
this->y = x;
this->punten = punten;
}
};
int main() // HEAD PROGRAM.
{
int temporaryAppendixCoordinate[2]= {0,0};
//Random number for spawning objects
// const int aantalfood = 8;
const int fieldsize = 15;
// int randomSpawn[4];
srand((unsigned)time(NULL));
//String produced for controls
string wasd1234;
//Iterator for producing random numbers
/* for (int i=0; i<10; i++)
{
srand((unsigned)time(NULL));
int number = rand();
randomSpawn[i] = (number % (fieldsize-1));
}
*/
//Instances
PLAYER player1(7,7,0); //player 1 position
APPENDIX appendix1(temporaryAppendixCoordinate[0],temporaryAppendixCoordinate[1],0);
FOOD food0(9,9,3);
FOOD food1(5,3,3);
FOOD food2(9,7,3);
FOOD food3(4,8,3);
FOOD food4(2,3,3);
FOOD food5(1,5,3);
FOOD food6(8,5,3);
FOOD food7(4,5,3);
// Infinite loop
for(bool i=true;i==true;)
{
system("CLS");
//Produce the field
for (int x=0; x<fieldsize; x++)
{
for (int y=0; y<fieldsize; y++)
{
if ((appendix1.x == x) && (appendix1.y == y))
if (appendix1.stun > 0)
{
cout << ">" << appendix1.stun << "<";
}
else
{
cout << ">!<";
}
// Here the code needs to check ALL the food instances instead of just food0!!!
else if (Compare(x,y,ptrvector))
cout << "+" << food0.stunErbij << " ";
else if ((player1.x == x) && (player1.y == y))
cout << "€ ";
else
cout << ". ";
}
cout << endl;
}
}
return 0;
}
|