![]() |
|
board, pawn and classes |
HardTranceFan
Member #7,317
June 2006
![]() |
Quote: I hope it's not a Sams Teach Yourself C++ in 24hr books either.
Why, what's wrong with them? It's what got me started. And no-one's died yet Ok, so my games never work, the PC resets with every recompile, and every time I get to the point where I can execute my program I need to re-install the windows. But otherwise it's fine. -- |
kosmitek
Member #8,151
December 2006
|
Durnus - my programm shouldn't use classes, constructor and destructor ?? Why ?? And why I shouldn't use "goto" ?? I change my code
everything okay PS. thanks TeamTerradactyl for your advices |
imaxcs
Member #4,036
November 2003
|
This is a joke right? This is not even closely valid C++- - code! Did you ever try to compile it? Even if it would, by skimming through it, I can say it would crash like hell... Listen to people's advises or at least post the freaking compiler-errors!!
|
raccoon
Member #7,478
July 2006
|
you shouldn't use classes, constructors and destructors because it seems you have no idea how to use them. if you really read a c++-book (which i doubt), you should have come across a thing called while-loop. you could replace your goto with this statement. |
kosmitek
Member #8,151
December 2006
|
But what is wrong in this code:
This programm guns very good so what is wrong |
X-G
Member #856
December 2000
![]() |
All right, guys, let's just stop taking this thread seriously. Either it's a troll, or so blithely ignorant as to be beyond our help. We've already given the only correct response: Get a C++ book and follow it from the beginning to the end. -- |
kosmitek
Member #8,151
December 2006
|
X-G I am not troll X-G if you don't want help me you didn't write. X-G my programm is almost good and you can only criticize me - you do not want even to say what is bad despite that my programme great run. And "goto" must be because if somebody will press other button than: "->; <-" then program go to "direction" - and player will have press "->; <-" - the number of eyes will not change, if I use "continue" then player also will have press "->; <-; Esc" but the number of eyes will change - and I don't want that the number of eyes change until player press "->" or "<-". |
TeamTerradactyl
Member #7,733
September 2006
![]() |
kosmitek: Attached is a cleaned-up version of your code. Since you really don't need to use a class/struct for this program, I have removed them. I also added a bunch of comments so you could read the changes I've made, or else what's going on in the program. Thank you for posting your source code so I could see what your game was supposed to do. You may want to convert your .BMP images into .PCX or another format: The filesize will be a LOT smaller (the BMP images are uncompressed, while PCX are). I also changed this to WINDOWED mode instead of full-screen (my computer crashes a lot whenever it's in full-screen, for some reason), so if you need to change it back, you can do so. I hope this helps. I think that if you WANTED to use a class/struct, the best thing to do would be to have something that has a lot of different data: your "pawn" could be an animated tile, and so the pawn could be a class, or if you have several different "boards", you could make each of those with a separate class (like, one could have a wood background with the "tiles" a few inches apart, and another could have a stone background with the "tiles" in more of a circular pattern and different coordinates, etc.). What you're doing right now doesn't really need a class, since that looks like you're trying to use your class as a substitute for the main body of your game. Anyway, hope this helps (and others can take a look at the code and make sure I didn't leak a bunch of memory
|
Paul whoknows
Member #5,081
September 2004
![]() |
This site should be enough. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
kosmitek
Member #8,151
December 2006
|
TeamTerradactyl thank you very much for your help and comments in the code. I wanted use class, constructor and destructor because I want develop my game and for example: "destroy_bitmap" - it was ideal to use destructor etc. |
TeamTerradactyl
Member #7,733
September 2006
![]() |
kosmitek, Let's say that that little "pink pawn" that you had in your code was going to become a nice little animated sprite (like a swirling "rock" or a "chess piece" that occasionally moves or whatever). +---+---+---+---+---+---+ | X | | X | | | | +---+---+---+---+---+---+ | | | | X | | | +---+---+---+---+---+---+ Say you had three pawns on the screen at once. Declaring the pawn as a class would allow each of the three pawns to have a different look, have different x/y coordinates, be facing different directions, etc. For those, it would be fine to use a class, since each pawn would need to keep track of similar data (direction facing, coordinates, etc) but all the data itself would be different (the top two are facing down, the bottom is facing up, so each would have a different "direction"). As an example of a usage of classes, my games have several bad guys/monsters. Each bad guy/monster keeps track of its current location, the direction is is trying to go, and its health. If I attack one of those monsters, its HP goes down slightly. When the monster dies, I don't need to keep track of that monster anymore and "delete" it. When it gets "deleted", the class destructor frees up all the data it was storing (like the BITMAP it was using, its location, etc.). In that case, it would be useful to have a class. So kosmitek, if you could describe for us, what do you want to use a "class" for in your game? If you have only 1 pawn and 1 "game board", I don't think you would need to use a class.
|
X-G
Member #856
December 2000
![]() |
I especially love how you all seem to think that "classes" is some kind of feature you "add to your code". THAT'S NOT HOW IT WORKS! Object-oriented programming is a design paradigm that you base your entire architecture on. This is why I'm sure you don't understand OOP. -- |
kosmitek
Member #8,151
December 2006
|
TeamTerradactyl you are very very very helpful - thank you a lot. So I want do this game: So it is my plan of game - where I can apply here OOP ? |
Steve Terry
Member #1,989
March 2002
![]() |
Kosmetek: Just out of curiosity how old are you? ___________________________________ |
TeamTerradactyl
Member #7,733
September 2006
![]() |
kosmitek: This sounds slightly similar to Monopoly, where each "field" has a different attribute (like "collect 200 dollars" or "You owe [some person] $50", etc.). If this is the case, then I would suggest making the "field" a class:
Then, each "field" you land on can have its own attributes and pictures. This would make sense, since you would use several "field" objects where you would really only use a handful of "pawn" objects. You would need to define several different "Attributes" that this class would be able to use: one would be a "shop" where you buy stuff, another would be a "thief" where you lose 50% of your weapons, etc. How you implement your "Attributes" would be up to you. But I hope this helps answer your question.
|
Steve Terry
Member #1,989
March 2002
![]() |
What a strange game, throwing bones and eyes... ___________________________________ |
TeamTerradactyl
Member #7,733
September 2006
![]() |
Steve:
|
kosmitek
Member #8,151
December 2006
|
ups - sorry - bones = dice TeamTerradactyl thank you a lot - you must be very good programmer. Your idea is too complicated for me. I would like to use in my game some simple class, constructor, destruktor and heirdom but I have no idea - maybe I should do two monsters and when player kill one monster then he heirdom his strength and then he fight with second monster but where can I use here simply class, constructor and destructor..... - class "monster" ?? |
TeamTerradactyl
Member #7,733
September 2006
![]() |
kosmitek: Yes, the "monster" would be an excellent place to use a class. Another would be the "player" because you need to keep track of the player's position, health, strength, etc.
|
Albin Engström
Member #8,110
December 2006
![]() |
TeamTerradactyl has a heart of.. gold, i really want to see you change, kosmitek. |
Audric
Member #907
January 2001
|
(note: It's Christmas) In the case of your game, one possible use of inheritance could be if monsters stay on the board: This is only an example, certainly not THE solution for what you want to do. People here have much experience coding 2D objects moving on a background (I've just described 40% of the games on a.cc), but board games are much, much more difficult to design and code, and frankly there's no evident OO design there. If you've never DESIGNED something in object-oriented design, a board game is the worst choice to start...You will never complete the game, and you will not even learn why your design does not make your game go in the right direction. If you want to progress in your game, structured programming is the way to go...until at least you completely understand how to use Allegro for a game, with some code for all initializations, a game loop, some code for logic, some other code for display, etc... and no memory messup. |
Steve Terry
Member #1,989
March 2002
![]() |
I guess even 23yrold3yrold started out like Kosmitek... there may be hope ___________________________________ |
X-G
Member #856
December 2000
![]() |
Only if he starts taking the only good advice in this thread and reads a damn book and starts from the beginning, and drops the notions he has ingrained in his head right now. He needs to start over, not be further confused and fed misinformation. -- |
[iCe]CorTez
Member #1,856
January 2002
![]() |
:> Only The Strong survive |
kosmitek
Member #8,151
December 2006
|
Thank you for you advices, especially thank TeamTerradactyl. I do not thank "X-G", he only discouraged me and he write nothing helpful. I have fast change my code as you say. Now I have simply class, late I will add here that if player stand on some field then something will done, I will also add class monster etc. But can you say me that my fragments of code touch OOP are okey ? And why my destructor isn't okey ?
|
|
|