Dinosaur battle text game help please

Hi, im making a text game where you battle a dinosaur in an arena, but i'm a bit stumped as to how to make the dinosaur randomly choose attactk and use them against the player. here is my code:

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
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <ctime>
#include <random>

using namespace std;

void Player();
void Enemy();
void TRex();
void arena();

string choice;
bool turn = false;

struct values
{
    string name;
    double health;
    int level;
};

struct Attacks
{
    //T-Rex Attacks
    int chomp;
    int bite;
    int charge;
    string MonsterMiss;

    //Player Attacks
    int shotgun;
    int club;
    int sword;
    string PlayerMiss;
};

int main()
{
    cout << "Welcome to the arena?" << endl;
    cout << "Would you like to begin?" << endl;
    cout << "\n";
    cout << "Yes" <<endl;
    cout << "no" <<endl;
    cin >> choice;

    if(choice == "Yes" || choice == "yes")
    {
        arena();
    }


}

void Player()
{
    values PlayerVal;

    PlayerVal.name;
    PlayerVal.health = 100;
    PlayerVal.level = 1;

}

void Enemy()
{
    values Enemy1;

    Enemy1.health = 100;
    Enemy1.level = 1;
    Enemy1.name = "T-Rex";
}

void TRex()
{
    Attacks Trex;

    srand(time(NULL));
}

void arena()
{
    cout << "The battle begins!!" << endl;
    cout << "\n";


}
Last edited on
look into pseudo random number generators for c++, I think this site has a tutorial about it.
you could use the rand() function to randomize a number between 1 and 4, and use an attack based on the number using a case statement.
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/
I tried the random numbers thing, i followed a tutorial on them and it isnt working. I tried using srand(); also and it wond even print out the random numbers on the screen. I want it to generate 1 number between 0 and 4, then choose an attack based on that number. I cant seem to get it. I'm trying to work on it right now, but please help still.
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
#include <iostream>
#include <string>
#include <ctime>
#include <stdlib.h>

template <class A>
void randomize(A &random, A max = 99, A min = 1)
{
    // don't forget to seed once in main.
    max++;
    max -= min;
    random = (A)(rand() % max + min);
}

void Player();
void Enemy();
void TRex();
void arena();

std::string choice;
bool turn = false;
int container;

struct values
{
    std::string name;
    double health;
    int level;
};

struct Attacks
{
    //T-Rex Attacks
    int chomp;
    int bite;
    int charge;
    std::string MonsterMiss;

    //Player Attacks
    int shotgun;
    int club;
    int sword;
    std::string PlayerMiss;
};

int main()
{
    srand(time(NULL));
    std::cout << "Welcome to the arena?" << std::endl;
    std::cout << "Would you like to begin?" << std::endl;
    std::cout << "\n";
    std::cout << "Yes" << std::endl;
    std::cout << "no" << std::endl;
    std::cin >> choice;

    if(choice == "Yes" || choice == "yes")
    {
        arena();
    }
}

void Player()
{
    values PlayerVal;

    PlayerVal.name = "Newbie";
    PlayerVal.health = 100;
    PlayerVal.level = 1;
}

void Enemy()
{
    values Enemy1;

    Enemy1.health = 100;
    Enemy1.level = 1;
    Enemy1.name = "T-Rex";
}

void TRex()
{
    Attacks Trex;

    randomize(container, 4, 1);

    switch (container)
    {
    case 1:
        std::cout << container << std::endl;
        break;
    case 2:
        std::cout << container << std::endl;
        break;
    case 3:
        std::cout << container << std::endl;
        break;
    case 4:
        std::cout << container << std::endl;
        break;
    default:
        std::cout << "Error" << std::endl;
        break;
    }
}

void arena()
{
    std::cout << "The battle begins!!" << std::endl;
    std::cout << "\n";
    for (int i = 0; i < 20; i++) // get rid of the for loop, it is simply for showing you that the numbers are random
    {
        TRex();
    }
}
Topic archived. No new replies allowed.