Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 13th, 2017, 5:46 pm

^ thanks, now that you mentioned it I've seen chili do this before, seems more clear that way.

I'm trying to make a pokemon battle simulator.
Usually when I make a program I just start coding and whatever happens, happens :D
Trying to actually plan it this time with UML, it's a bit hard becuase I don't know UML and it's kinda confusing.
Also running into some design problems.
The player should have 6 pokemons to choose from. Each pokemon should have 4 different moves.
I was planning on making a Move class and its function Use() would take 2 references to pokemon, target and attacker... but pokemons should have 4 moves so would need to store moves in pokemon which would mean circular dependancy.

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 13th, 2017, 6:10 pm

this is not done, but does this already look really dumb? Feels like spaghetti code?
batlleM has players,
players has a team
team has pokemons,
pokemons have moves...

Image

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 13th, 2017, 8:52 pm

Image

uugh, UML and this project already feels like aids.
I now have one day to write all the code so gonna get a good nights rest and start coding tomorrow. Just try and make it simple and dumb and then try and make it better

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Noob learns to code in 3 months

Post by chili » September 14th, 2017, 10:55 am

Yeah man, starting simple is the way to go for sure.

I rather like UML. Kinda pointless when working by myself, but it's a good tool for communicating your architecture quickly to others. Well, quickly for them ;)
Chili

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 14th, 2017, 12:51 pm

^ Yeah I think I'll like it once I get more used to it.

Written some code. What I'm still unsure about is how to set up the simulation with players, pokemons and moves... What I have so far is something like this:

Code: Select all

moves["Tackle"] = new DamagingMove("Tackle", 10);
	moves["Leech Life"] = new AbsorbingMove("Leech Life", 8);
	moves["Thunder Shock"] = new DamagingMove("Thunder Shock", 12);
	moves["Fire Blast"] = new DamagingMove("Fire Blast", 15);
	moves["Ember"] = new DamagingMove("Ember", 10);
	moves["Water Gun"] = new DamagingMove("Water Gun", 10);
	moves["Slam"] = new DamagingMove("Slam", 12);
	moves["Quick Attack"] = new DamagingMove("Quick Attack", 10);
	moves["Scratch"] = new DamagingMove("Scratch", 12);

	Pokemon* pikachu = new Pokemon("Pikachu", 20);
	Pokemon* charmander = new Pokemon("Charmander", 20);
	Pokemon* bulbasaur = new Pokemon("Bulbasaur", 20);
	Pokemon* squirtle = new Pokemon("Squirtle", 20);

	pikachu->AddMove("Tackle");
	pikachu->AddMove("Thunder Shock");
	pikachu->AddMove("Slam");
	pikachu->AddMove("Quick Attack");

	charmander->AddMove("Tackle");
	charmander->AddMove("Scratch");
	charmander->AddMove("Ember");
	charmander->AddMove("Fire Blast");

	bulbasaur->AddMove("Tackle");
	bulbasaur->AddMove("Leech Life");
	bulbasaur->AddMove("Slam");
	bulbasaur->AddMove("Scratch");

	squirtle->AddMove("Tackle");
	squirtle->AddMove("Scratch");
	squirtle->AddMove("Water Gun");
	squirtle->AddMove("Scratch");

	players[0] = new Player("Ash");
	players[0]->AddPokemon(pikachu);
	players[0]->AddPokemon(charmander);

	players[1] = new Player("Gary");
	players[1]->AddPokemon(bulbasaur);
	players[1]->AddPokemon(squirtle);
Don't really like it. Once both players have 6 different pokemons and all pokemons have 4 moves this becomes many lines of code and it feels dumb. Should be some more efficient way of doing this but currently can't think of anything

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 14th, 2017, 1:20 pm

Also, I think I started off doing it too complicated like always. Have been coding for a couple hours and not ran a singe test :D so no idea if what I'm doing will even work

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 14th, 2017, 4:22 pm

Well the program works, but lots of stuff still needs to be done.

Realized that atm my game works like this
player 1 decides what to do and then his pokemon attacks
player 2 decides what to do and then his pokemon attacks

in the actual game it's supposed to be like this:
player 1 decides what to do
player 2 decides what to do
player 1s pokemon attcks
player 2s pokemon attacks.

Not sure how to make that happen but will try and figure something out or leave it like it is if I run out of time.

Also consider making it so one of the player is the computer and the other one is an actual player.

But first I have more important things to work on :)

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » September 14th, 2017, 8:19 pm

Hehem, state machine using enums?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 14th, 2017, 8:37 pm

albinopapa wrote:Hehem, state machine using enums?
wat?

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » September 14th, 2017, 10:03 pm

trying to delete all dynamically allocated objects.

Why does this not work for deleting the objects in my map?

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;
		}
	}
"map/set iterator not dereferencable"

Post Reply