Planet Chili
http://forum.planetchili.net/

Noob learns to code in 3 months
http://forum.planetchili.net/viewtopic.php?f=3&t=3868
Page 57 of 63

Author:  Yumtard [ September 13th, 2017, 5:46 pm ]
Post subject:  Re: Noob learns to code in 3 months

^ 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.

Author:  Yumtard [ September 13th, 2017, 6:10 pm ]
Post subject:  Re: Noob learns to code in 3 months

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

Author:  Yumtard [ September 13th, 2017, 8:52 pm ]
Post subject:  Re: Noob learns to code in 3 months

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

Author:  chili [ September 14th, 2017, 10:55 am ]
Post subject:  Re: Noob learns to code in 3 months

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 ;)

Author:  Yumtard [ September 14th, 2017, 12:51 pm ]
Post subject:  Re: Noob learns to code in 3 months

^ 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:
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

Author:  Yumtard [ September 14th, 2017, 1:20 pm ]
Post subject:  Re: Noob learns to code in 3 months

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

Author:  Yumtard [ September 14th, 2017, 4:22 pm ]
Post subject:  Re: Noob learns to code in 3 months

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 :)

Author:  albinopapa [ September 14th, 2017, 8:19 pm ]
Post subject:  Re: Noob learns to code in 3 months

Hehem, state machine using enums?

Author:  Yumtard [ September 14th, 2017, 8:37 pm ]
Post subject:  Re: Noob learns to code in 3 months

albinopapa wrote:
Hehem, state machine using enums?


wat?

Author:  Yumtard [ September 14th, 2017, 10:03 pm ]
Post subject:  Re: Noob learns to code in 3 months

trying to delete all dynamically allocated objects.

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

Code:
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"

Page 57 of 63 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/