I am working on a console game and I am wondering if this is correct usage and setup of class objects, mainly in main, I think it's ok but idk, it just doesnt feel right, it feels like a kludge to me. It's not complete but this is what I have so far. These are not all of the classes either but this is the one i'm working on.
main.cpp
Code:
#include "pch.h"
#include <iostream>
#include <string>
#include <vector>
#include "Item.h"
#include "Player.h"
#include "Arena.h"
#include "Shop.h"
#include "Dinosaur.h"
int main()
{
Shop shop;
Arena arena;
shop.AddItems("Golden Necklace of Speak Good", 450);
shop.AddItems("Helmet of Protect Head", 800);
shop.AddItems("Staff of Magic Stuff", 8000);
shop.AddItems("Mask of Suffocation", 420);
shop.AddItems("Dagger of Major Stabness", 230);
Player player("Chay", 60000);
std::vector<std::pair<std::string, int>> trexAttacks, velociraptorAttacks;
//Create T-Rex
trexAttacks.push_back(std::make_pair("Stomp", 80));
trexAttacks.push_back(std::make_pair("Crunch", 30));
Dinosaur Trex("T-Rex", 800, trexAttacks);
std::cout << Trex.GetDinosaurName() << '\n';
Trex.ShowAllDinosaurAttacks();
std::cout << "\n";
//Create Velociraptor
velociraptorAttacks.push_back(std::make_pair("JumpAttack", 20));
velociraptorAttacks.push_back(std::make_pair("Bite", 15));
Dinosaur Velociraptor("Velociraptor", 400, velociraptorAttacks);
std::cout << Velociraptor.GetDinosaurName() << '\n';
Velociraptor.ShowAllDinosaurAttacks();
std::cout << "\n";
//Show list of Arena opponents (All possible enemies the player could face)
arena.CreateListOfOpponents(Trex, trexAttacks);
arena.CreateListOfOpponents(Velociraptor, velociraptorAttacks);
//Choose and enemy randomly
std::cout << "\n";
arena.RandomlyChooseEnemy();
//shop.Buy(player);
return 0;
}
Dinosaur.h
Code:
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <time.h>
#include <stdlib.h>
class Dinosaur
{
public:
Dinosaur(std::string dinosaurName, int dinosaurHealth, std::vector<std::pair<std::string, int>> dinosaurAttacks)
: mDinosaurName(dinosaurName), mDinosaurHealth(dinosaurHealth), mDinosaurAttacks(dinosaurAttacks){}
void ChooseRandomAttack()
{
srand(time(NULL));
unsigned int chooseRandomAttack = rand() % mDinosaurAttacks.size();
//TO DO
//If number is within certain range, perform attack.
}
void ShowAllDinosaurAttacks()
{
for(unsigned int i = 0; i < mDinosaurAttacks.size(); i++)
{
std::cout << mDinosaurAttacks[i].first << " " << mDinosaurAttacks[i].second << "\n";
}
}
std::string GetDinosaurName() const { return mDinosaurName; }
std::string GetDinosaurAttackName() const { return mDinosaurAttackName; }
int GetDinosaurAttackPower() const { return mDinosaurAttackPower; }
int GetDinosaurHealth() const { return mDinosaurHealth; }
private:
int mDinosaurHealth;
int mDinosaurAttackPower;
std::string mDinosaurAttackName;
std::string mDinosaurName;
std::vector<std::pair<std::string, int>> mDinosaurAttacks;
};