Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ============================================================================
- ==========================Adventure Game Skeleton!==========================
- ============================================================================
- - This has all of the basic features of a text based adventure game.
- - The AI isn't very good(all randomized), but it's a start. If you want a really smart enemy, have them go directly for the
- player.
- - Nothing can go through walls. It will stop you if you try.
- - The map can be adjusted and changed, ' ' will always be walkable ground, '#' will always be walls
- - No matter what, you can have the walls anywhere and it will work (As long as there is spawn space, and spawns are in the right place)
- - You could add several maps by making "doors" on specific coordinates that when you walk through them, it causes the new map to load.
- This could possibly lead to a very large map system.
- - The sword was added and now you can attack enemies. It goes in four directions, and only goes one unit in distance.
- - A loot system is now possible. Do a check if the enemy is dead, then if you step on them and they are in fact dead,
- add to the player's loot. This could possibly lead to a buying system where you can increase the range of your weapon,
- amongst other things such as lives, armor, etc., etc..
- - You can make an inventory system with a vector by adding loot, or bought items to it. Then you could add them to a vector
- and iterate through that vector, as well as access the items.
- - I added classes (Hooray!). Now you can call the member functions of the spawned enemies without having to write the code several times.
- - You can now enter a number into NUM_OF_ENEMIES and it will spawn that many enemies.
- */
- #include "Functions.h"
- #include "Entities.h"
- using namespace std;
- const int NUM_OF_ENEMIES = 30; //You can set this to any number and it will
- //spawn that many enemies
- //These are for holding the enemies that are made and iterating through them
- vector<Enemy> EnemyVector;
- vector<Enemy>::iterator iter;
- Player player('@', 1, 1);
- int main()
- {
- srand(static_cast<unsigned int>(time(0)));
- int Rounds = 0;
- int HealCounter = 0;
- bool GameBool = true;
- bool Choosing = true;
- Enemy * Pointer[NUM_OF_ENEMIES];//Pointer array to create new enemies. Refer to the
- //for loop below.
- for (int i = 0; i < NUM_OF_ENEMIES; i++)
- {
- Pointer[i] = new Enemy(EnemyVector);
- }
- for (iter = EnemyVector.begin(); iter != EnemyVector.end(); iter++)
- {
- iter->AddToGame();//Adding the enemies to the screen
- }
- player.AddToGame();//Adding the player to the screen
- ShowBoard();//Show the board
- while (GameBool)
- {
- if (HealCounter == 5)
- {
- player.Health += 1;
- if (player.Health > 100)
- player.Health = 100;
- HealCounter = 0;
- }
- ClearScreen();//Clear the screen
- ShowBoard();//Show the board after the enemies have moved
- cout << "\nCurrent health: " << player.Health << endl;
- cout << "Current gold: " << player.Gold << endl;
- cout << "\nWhat would you like to do?"
- "\nB - Go To The Store"
- "\nW - Move Up"
- "\nS - Move Down"
- "\nA - Move Left"
- "\nD - Move Right"
- "\nU - Attack Up"
- "\nJ - Attack Down"
- "\nH - Attack Left"
- "\nK - Attack Right\n";
- Choosing = true;
- Sleep(50);
- while (Choosing)
- {
- //Go To The Shop
- if (GetAsyncKeyState(B))
- {
- player.Choice = 'b';
- Choosing = false;
- }
- //Move Up
- if (GetAsyncKeyState(W))
- {
- player.Choice = 'w';
- Choosing = false;
- }
- //Move Left
- if (GetAsyncKeyState(A))
- {
- player.Choice = 'a';
- Choosing = false;
- }
- //Move Down
- if (GetAsyncKeyState(S))
- {
- player.Choice = 's';
- Choosing = false;
- }
- //Move Right
- if (GetAsyncKeyState(D))
- {
- player.Choice = 'd';
- Choosing = false;
- }
- //Attack Up
- if (GetAsyncKeyState(U))
- {
- player.Choice = 'u';
- Choosing = false;
- }
- //Attack Left
- if (GetAsyncKeyState(H))
- {
- player.Choice = 'h';
- Choosing = false;
- }
- //Attack Down
- if (GetAsyncKeyState(J))
- {
- player.Choice = 'j';
- Choosing = false;
- }
- //Attack Right
- if (GetAsyncKeyState(K))
- {
- player.Choice = 'k';
- Choosing = false;
- }
- }
- CheckChoice(player.Choice, player.Damage, player.Gold, player.Health, player.Range);
- for (iter = EnemyVector.begin(); iter != EnemyVector.end(); iter++)
- {
- iter->Move(player.PlayerX, player.PlayerY, player.Health);//Move all of the enemies
- }
- //Check if all enemies are dead
- for (iter = EnemyVector.begin(); iter != EnemyVector.end(); iter++)
- {
- if (iter->IsDead == false)
- break;//If not, exit the loop
- else if (iter == (EnemyVector.end() -1) && iter->IsDead == true)
- {
- GameBool = false; //If so, set the GameBool to false and exit the
- } //main while loop
- }
- if (player.Health <= 0)
- GameBool = false;
- if (Win == true)
- GameBool = false;
- ++Rounds;
- ++HealCounter;
- }
- for (int i = 0; i < NUM_OF_ENEMIES; i++)
- {
- delete Pointer[i];//delete the enemies that were made
- Pointer[i] = NULL;
- }
- if (player.Health <= 0)
- cout << "\nYou died!\n"; //You Lost!!
- else if (Win == true)
- {
- cout << "\nYou reached the golden question mark! You win!\n";
- cout << "\nYour score is " << ((((player.Gold / Rounds) * player.Health) * player.Damage) * player.Range) + 500;
- }
- else
- {
- cout << "\nYou Defeated All Of The Enemies!\n";//You won!!
- cout << "Your score is " << (((player.Gold / Rounds) * player.Health) * player.Damage) * player.Range;
- }
- _getch();//Because system("PAUSE") is a bad thing to use
- return 0;
- }
- void CheckChoice(char& choice, int& Damage, int& Gold, int& Health, int& Range)
- {
- switch (choice) //You can pick any valid move or attack without
- { //having to deal with a cout asking if you want
- case 'b':
- BuyScreen(Damage, Gold, Health, Range);
- break;
- case 'w': //to attack or move.
- player.Move();
- break;
- case 's':
- player.Move();
- break;
- case 'a':
- player.Move();
- break;
- case 'd':
- player.Move();
- break;
- case 'u':
- player.Attack(EnemyVector, iter);
- break;
- case 'j':
- player.Attack(EnemyVector, iter);
- break;
- case 'h':
- player.Attack(EnemyVector, iter);
- break;
- case 'k':
- player.Attack(EnemyVector, iter);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement