[ADD] convert number to digits

This commit is contained in:
Sem van der Hoeven
2021-06-11 12:30:47 +02:00
parent 504b97b320
commit 692bb76164
4 changed files with 29 additions and 0 deletions

View File

@@ -270,6 +270,15 @@ namespace scene
collision::CheckCollisions(collision_entities);
update_hand_detection();
std::vector<int> res;
toolbox::GetDigitsFromNumber(1234567890, res);
std::cout << "number 1234567890 in digits: " << std::endl;
for (int i : res)
{
std::cout << i << " , ";
}
std::cout << std::endl;
}
//manages the key input in the game scene

View File

@@ -54,6 +54,8 @@ namespace scene
//pause_guis is a list of components that will be rendered when the game is paused.
std::vector<gui::GuiTexture*> pause_guis;
std::vector<gui::GuiTexture*> score_guis;
/**
* @brief renders the objects/gui models
* @param

View File

@@ -56,4 +56,12 @@ namespace toolbox
}
return min + rand() % ((max + 1) - min);
}
void GetDigitsFromNumber(int number, std::vector<int>& result_vector)
{
if (number >= 10)
GetDigitsFromNumber(number / 10, result_vector);
result_vector.push_back(number % 10);
}
}

View File

@@ -2,6 +2,7 @@
#include "../entities/camera.h"
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
namespace toolbox
{
@@ -78,4 +79,13 @@ namespace toolbox
* @return: The random number
*/
int Random(const int min, const int max);
/**
* @brief gets the separate digits from the number.
*
* @param number the number to get the digits from
* @param result_vector the vector to hold the individual digits.
*/
void GetDigitsFromNumber(int number, std::vector<int>& result_vector);
}