Noob learns to code in 3 months
Re: Noob learns to code in 3 months
superconfused...
just as a test. I did this:
void BattleManager::freeMemory()
{
m_Players[0]->freeMemory();
m_Players[1]->freeMemory();
delete m_Players[0];
delete m_Players[1];
delete m_Moves["Tackle"];
}
and then I call it from main and get no crash.
then I paste this code in the destructor and call the destructor from main and get crash
just as a test. I did this:
void BattleManager::freeMemory()
{
m_Players[0]->freeMemory();
m_Players[1]->freeMemory();
delete m_Players[0];
delete m_Players[1];
delete m_Moves["Tackle"];
}
and then I call it from main and get no crash.
then I paste this code in the destructor and call the destructor from main and get crash
Re: Noob learns to code in 3 months
maybe this was the issue. idk seems to be working when not calling itYumtard wrote: and call the destructor from main and get crash
Re: Noob learns to code in 3 months
You should (almost) never ever call DTOR directly bro. I remember telling you that somewhere earlier in this thread as well (when you tackled the homework for I6)
Chili
Re: Noob learns to code in 3 months
need to see full code there bro. also, you may have other issues, but first gotta deal with your iterator issue.Yumtard wrote:trying to delete all dynamically allocated objects.
Why does this not work for deleting the objects in my map?
"map/set iterator not dereferencable"Code: Select all
for (; it != m_Moves.end(); it++) { if (it != m_Moves.end()) { delete it->second; it->second = nullptr; std::cout << "Destroying a move..." << std::endl; } }
Chili
Re: Noob learns to code in 3 months
Alright, this has been the biggest mess of my programming life
I just couldn't get it to work...
I had major issues with dumb logic, like states getting switched from everywhere.
I also couldn't get the program working the way I wanted it to.
After much time coding and many headaches I decided to rewrite/restructure almost everything.
When I did that the logic became a bit less confusing and I got the program working the way I wanted it to.
also I'm now reading in from files instead of doing it all in code.
I'm pretty sure this could've been done in a better way but at least it's better than it was before.
I'm also pretty sure the code still sucks ass. There's some stuff I wanted to do different and I think there's a bunch of stuff I'm unaware of, like hardcoding, bad logic, bad practices, bad structure etc
but I've been coding for probably 20 hours and atm just can't think of any ways to improve it further (and I'm supposed to hand it in, in 2 hours fml).
Would be very happy if anyone would be kind enough to let me know how one would structure this better.
https://github.com/Yumtard/pokemonBattle/tree/different
I just couldn't get it to work...
I had major issues with dumb logic, like states getting switched from everywhere.
I also couldn't get the program working the way I wanted it to.
After much time coding and many headaches I decided to rewrite/restructure almost everything.
When I did that the logic became a bit less confusing and I got the program working the way I wanted it to.
also I'm now reading in from files instead of doing it all in code.
Code: Select all
BattleManager::BattleManager()
{
{
std::ifstream in("damaging.txt");
int dmg;
std::string name;
while (in.good())
{
in >> name >> dmg;
m_Moves[name] = new DamagingMove(name, dmg);
}
}
{
std::ifstream in("absorbing.txt");
int dmg;
std::string name;
while (in.good())
{
in >> name >> dmg;
m_Moves[name] = new AbsorbingMove(name, dmg);
}
}
{
m_Player = new Player("Ash");
std::ifstream in("player1pokemons.txt");
int hp;
std::string name, att1, att2, att3, att4;
while (in.good())
{
in >> name >> att1 >> att2 >> att3 >> att4 >> hp;
m_Pokemons[name] = new Pokemon(name, hp);
m_Pokemons[name]->AddMove(att1);
m_Pokemons[name]->AddMove(att2);
m_Pokemons[name]->AddMove(att3);
m_Pokemons[name]->AddMove(att4);
m_Player->AddPokemon(m_Pokemons[name]);
}
}
{
m_AI = new Player("Gary");
std::ifstream in("player2pokemons.txt");
int hp;
std::string name, att1, att2, att3, att4;
while (in.good())
{
in >> name >> att1 >> att2 >> att3 >> att4 >> hp;
m_Pokemons[name] = new Pokemon(name, hp);
m_Pokemons[name]->AddMove(att1);
m_Pokemons[name]->AddMove(att2);
m_Pokemons[name]->AddMove(att3);
m_Pokemons[name]->AddMove(att4);
m_AI->AddPokemon(m_Pokemons[name]);
}
}
}
I'm also pretty sure the code still sucks ass. There's some stuff I wanted to do different and I think there's a bunch of stuff I'm unaware of, like hardcoding, bad logic, bad practices, bad structure etc
but I've been coding for probably 20 hours and atm just can't think of any ways to improve it further (and I'm supposed to hand it in, in 2 hours fml).
Would be very happy if anyone would be kind enough to let me know how one would structure this better.
https://github.com/Yumtard/pokemonBattle/tree/different
Re: Noob learns to code in 3 months
well, apparently this would've passed
meanwhile I spammed 800-900 lines of codes yesterday
Code: Select all
#include <string>
struct Pokemon
{
int hp;
std::string name;
};
struct Player
{
Pokemon* pkmn;
};
int main()
{
Player* ash = new Player;
Player* gary = new Player;
ash->pkmn = new Pokemon;
gary->pkmn = new Pokemon;
ash->pkmn->name = "Pikachu";
gary->pkmn->name = "charizard";
ash->pkmn->hp = 30;
gary->pkmn->hp = 100;
while (ash->pkmn->hp > 0 && gary->pkmn->hp > 0)
{
gary->pkmn->hp -= 4;
ash->pkmn->hp -= 7;
}
delete ash->pkmn;
delete gary->pkmn;
delete ash;
delete gary;
return 0;
}
Re: Noob learns to code in 3 months
Hahaha, well it's good to know what level they're expecting
No need to overthink things I guess, but it's good to mess around with stuff and come up with a lot of failed designs. That's how you really start building a feel for what works and what doesn't.
No need to overthink things I guess, but it's good to mess around with stuff and come up with a lot of failed designs. That's how you really start building a feel for what works and what doesn't.
Chili
Re: Noob learns to code in 3 months
Well they're hoping for more than this ofc .chili wrote:Hahaha, well it's good to know what level they're expecting
No need to overthink things I guess, but it's good to mess around with stuff and come up with a lot of failed designs. That's how you really start building a feel for what works and what doesn't.
But he showed this as like the bare minimum for what would qualify as a simulation and mentioned that he would've passed it.
He expected all of us to have overthinked the assignment and probably to have attempted doing something we weren't really able to. He seemed to be correct
He also mentioned that it might've been a good idea to start out like this and then build upon it.
More students seemed to have had the same issues as me with trying to do eeverything at once
It felt nice to know they're not expecting us to be masters at programming. because during this assignment I started feeling like they're probably expecting more of me than I'm capable of.
Re: Noob learns to code in 3 months
Solid advice IMO.Yumtard wrote:He also mentioned that it might've been a good idea to start out like this and then build upon it.
Chili
Re: Noob learns to code in 3 months
Being a github tartd
https://github.com/planetchili/3D_Funda ... e/t3-rot3d
I'm watching t3 of 3d fundamentals. Cloned this repo but I only get te master branch, not the t3 rot3d branch
https://github.com/planetchili/3D_Funda ... e/t3-rot3d
I'm watching t3 of 3d fundamentals. Cloned this repo but I only get te master branch, not the t3 rot3d branch