Skip to content
25 changes: 25 additions & 0 deletions sem2/Boiko MA/minihomework1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <string>

int main()
{
std::vector<std::string> vecForCheck;

for (int a = 0; a <= 200; a++)
{
vecForCheck.push_back(std::to_string(rand()%1000 + 50 - 20));
}

char lookFor;
std::cout << "What are you looking for today?" << std::endl << "Type in a digit, as we are looking through a vector of numbers" << std::endl << "(if you don't want to get a zero :3)" << std::endl;
std::cin >> lookFor;

int howMany = count_if(vecForCheck.begin(), vecForCheck.end(), [lookFor] (std::string _n) {
return _n[0] == lookFor;
});

std::cout << howMany << " strings in our vector start with " << lookFor << std::endl;
}
167 changes: 167 additions & 0 deletions sem2/Practics - DinoWars 1.5/classes/Dino.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include "Dino.h"

std::map<species, std::string> speciesMap = {
{Tiranosaurus, "Tiranosaurus"},
{Brachiozaurus, "Brachiozaurus"},
{Diplodocus, "Diplodocus"},
{Triceratops, "Triceratops"},
{Stegozaurus, "Stegozaurus"}
};

std::map<species, std::string> texture_map
{
{Tiranosaurus, "res/dino_textures/Tirano.png"},
{Brachiozaurus, "res/dino_textures/Brachio.png"},
{Diplodocus, "res/dino_textures/Diplo.png"},
{Triceratops, "res/dino_textures/Tricer.png"},
{Stegozaurus, "res/dino_textures/Stegoz.png"}
};


species get_random_species()
{
int a = rand() % 5;
switch (a)
{
case 0: return Tiranosaurus;
case 1: return Brachiozaurus;
case 2: return Diplodocus;
case 3: return Triceratops;
case 4: return Stegozaurus;
}
}

terrain get_random_terrain()
{
int a = rand() % 3;
switch (a)
{
case 0: return River;
case 1: return Plains;
case 2: return Mountain;
}
}

int Dino::damage(terrain cur_ter)
{
int raw_dmg = cur_ter == Mountain ? MIND : cur_ter == Plains ? STR : AGIL;
if (cur_ter == pref_terrain)
{
raw_dmg = raw_dmg * 2;
}
return raw_dmg;
}

Dino::Dino(int input_hp, int input_str, int input_mind, int input_agil)
{
HP = input_hp;
INITHP = HP;
STR = input_str;
MIND = input_mind;
AGIL = input_agil;
is_alive = true;
is_chosen = false;
cost = 50;


}

Dino::Dino()
{
TYPE = get_random_species();
pref_terrain = get_random_terrain();

HP = rand() % 70 + 30;
INITHP = HP;
STR = rand() % 10 + 20;
MIND = rand() % 10 + 20;
AGIL = rand() % 10 + 20;
is_alive = true;
is_chosen = false;
cost = rand() % 30 + 10;

texture.loadFromFile(texture_map[TYPE]);
sprite.setTexture(texture);
}

int Dino::get_hp()
{
return this->HP;
}

int Dino::getCost()
{
return cost;
}

terrain Dino::getPrefter()
{
return pref_terrain;
}

std::string Dino::dino_info()
{
return speciesMap[TYPE] + " " + std::to_string(HP) + "H " + std::to_string(STR) + "S " + std::to_string(MIND) + "M " + std::to_string(AGIL) + "A";
}

void Dino::set_params(sf::Vector2f pos, sf::Vector2f scale)
{
sprite.setPosition(pos);
sprite.setScale(scale);
}

void Dino::set_hp(int i_hp)
{
HP-=i_hp;
if (HP <= 0)
{
is_alive = false;
}
}
void Dino::draw(sf::RenderWindow& window)
{
window.draw(sprite);
}

void Dino::set_typeandter(species s, terrain t)
{
TYPE = s;
pref_terrain = t;

texture.loadFromFile(texture_map[TYPE]);
sprite.setTexture(texture);
}

void Dino::set_chosen(bool a)
{
is_chosen = a;
}

bool Dino::is_dino_chosen()
{
return is_chosen;
}

float Dino::get_hp_float()
{
return float(HP) / float(INITHP);
}
std::string Dino::getDinoData()
{
return std::to_string(TYPE) + " " + std::to_string(pref_terrain) + " " + std::to_string(STR) + " " + std::to_string(AGIL) + " " + std::to_string(MIND) + " " + std::to_string(HP);
}
void Dino::set_flip()
{
sprite.scale(-1.f, 1.f);
sprite.move(sprite.getGlobalBounds().width, 0.f);
}
void Dino::reset()
{
is_alive = true;
is_chosen = false;
HP = INITHP;
}
bool Dino::is_available(int a)
{
return a >= cost;
}
48 changes: 48 additions & 0 deletions sem2/Practics - DinoWars 1.5/classes/Dino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once
#include "sfml_stuff.h"
#include <random>

enum species { Tiranosaurus, Brachiozaurus, Diplodocus, Triceratops, Stegozaurus };
enum terrain { Mountain, River, Plains };

class Dino
{
private:
sf::Texture texture;
sf::Sprite sprite;
species TYPE;
terrain pref_terrain;
int INITHP;
int HP;
int STR;
int MIND;
int AGIL;
int cost;

bool is_chosen;
public:
Dino(int input_hp, int input_str, int input_mind, int input_agil);
Dino();
int damage(terrain cur_ter);

int getCost();
terrain getPrefter();
bool is_dino_chosen();
float get_hp_float();
int get_hp();
bool is_alive;

bool is_available(int a);
std::string dino_info();

void set_params(sf::Vector2f pos, sf::Vector2f scale);
void set_typeandter(species s, terrain t);
void set_chosen(bool a);
void set_hp(int i_hp);

void draw(sf::RenderWindow& window);
void set_flip();

void reset();
std::string getDinoData();
};
64 changes: 64 additions & 0 deletions sem2/Practics - DinoWars 1.5/classes/Player.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "Player.h"

Player::Player(int i_coins)
{
coins = i_coins;

chosen_dinos.push_back(nullptr);
chosen_dinos.push_back(nullptr);
chosen_dinos.push_back(nullptr);
}
bool Player::any_dino_alive()
{
for (auto a : chosen_dinos)
{
if (a!= nullptr && a->is_alive)
{
return true;
}
}
return false;
}
int Player::getCoins()
{
return coins;
}
void Player::buy_dino(Dino* newDino)
{
if (coins >= newDino->getCost())
{
coins -= newDino->getCost();
dinos_owned.push_back(newDino);
// std::cout << "DINO BOUGHT. COINS: " << coins << std::endl;
}
else
{
// std::cout << "TOO POOR" << std::endl;
}
}
void Player::generate_dinos()
{
for (int k = 0; k < 3; k++)
{
this->chosen_dinos[k] = new Dino();
}
}
void Player::giveCoins(int a)
{
coins += a;
}
void Player::setCoins(int a)
{
coins = a;
}
void Player::reset_dinos()
{
for (auto d : dinos_owned)
{
d->reset();
}
}
bool Player::has_dinos()
{
return (!dinos_owned.empty());
}
26 changes: 26 additions & 0 deletions sem2/Practics - DinoWars 1.5/classes/Player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "sfml_stuff.h"
#include <iostream>
#include <vector>
#include "Dino.h"

class Player
{
private:
int coins;
public:
std::vector<Dino*> dinos_owned;
std::vector<Dino*> chosen_dinos;

Player(int i_coins);
int getCoins();
bool any_dino_alive();
void giveCoins(int a);
void setCoins(int a);
void buy_dino(Dino* newDino);
void reset_dinos();
bool has_dinos();
// ��� �����
void generate_dinos();
};

Loading