From 400396586675b5a50f8988b11e04389da2cba25d Mon Sep 17 00:00:00 2001 From: "Jasleen Mann (mannj15)" Date: Fri, 6 Mar 2020 08:59:38 +0000 Subject: [PATCH] Some random enemy placement code the goblins sometimes render outside of the map but i cant figure out how to stop it --- Character.h | 102 +++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/Character.h b/Character.h index be2e3bd..747624b 100644 --- a/Character.h +++ b/Character.h @@ -3,9 +3,13 @@ #include /* srand, rand */ #include /* time */ #pragma once + extern std::string lastTurnsMessages; extern char map[100][100]; extern int willWalkIntoSomebody; + +int rand(); + class Character { public: @@ -15,52 +19,52 @@ public: //void Movement(int Vertical, int Horizontal); void Movement(int Vertical, int Horizontal) -{ - int x2 = x + Horizontal; // movement on x-axis - int y2 = y + Vertical; // movement on y-axis - - if (map[x2][y] == ' ') // if player moves horizontally the space before becomes an empty space and the space moved to becomes '@' - { - map[x][y] = ' '; - x += Horizontal; - map[x][y] = '@'; - } - if (map[x2][y] == '.') // if player moves horizontally the space before becomes an empty space and the space moved to becomes '@' - { - map[x][y] = ' '; - x += Horizontal; - map[x][y] = '@'; - } - if (map[x2][y] == 'M') { - map[x][y] = ' '; - x+=Horizontal; - map[x][y] = '@'; - gold+=rand()%100; - srand (time(NULL)); - } + int x2 = x + Horizontal; // movement on x-axis + int y2 = y + Vertical; // movement on y-axis - if (map[x][y2] == ' ') // if player moves vertically the space before becomes an empty space and the space moved to becomes '@' - { - map[x][y] = ' '; - y += Vertical; - map[x][y] = '@'; - } - if (map[x][y2] == '.') // if player moves vertically the space before becomes an empty space and the space moved to becomes '@' - { - map[x][y] = ' '; - y += Vertical; - map[x][y] = '@'; - } - if (map[x][y2] == 'M') - { - map[x][y] = ' '; - y+=Vertical; - map[x][y] = '@'; - gold+=rand()%100; - srand (time(NULL)); + if (map[x2][y] == ' ') // if player moves horizontally the space before becomes an empty space and the space moved to becomes '@' + { + map[x][y] = ' '; + x += Horizontal; + map[x][y] = '@'; + } + if (map[x2][y] == '.') // if player moves horizontally the space before becomes an empty space and the space moved to becomes '@' + { + map[x][y] = ' '; + x += Horizontal; + map[x][y] = '@'; + } + if (map[x2][y] == 'M') + { + map[x][y] = ' '; + x+=Horizontal; + map[x][y] = '@'; + gold+=rand()%100; + srand (time(NULL)); + } + + if (map[x][y2] == ' ') // if player moves vertically the space before becomes an empty space and the space moved to becomes '@' + { + map[x][y] = ' '; + y += Vertical; + map[x][y] = '@'; + } + if (map[x][y2] == '.') // if player moves vertically the space before becomes an empty space and the space moved to becomes '@' + { + map[x][y] = ' '; + y += Vertical; + map[x][y] = '@'; + } + if (map[x][y2] == 'M') + { + map[x][y] = ' '; + y+=Vertical; + map[x][y] = '@'; + gold+=rand()%100; + srand (time(NULL)); + } } -} void LevelUp() @@ -108,10 +112,18 @@ class monster void getInfo() { - std::cout<<"x="; + for (int j = 0; j < 2; ++j) + { + x = rand() % 36; + + y = rand() % 36; + + j += 1; + } + /*std::cout<<"x="; std::cin>>x; std::cout<<"y="; - std::cin>>y; + std::cin>>y;*/ } void wasAttacked(int *playerattack, int *playerxp, int *playertotalxp)