Register
Email: Password:
Forum » Learning C++
  • « previous
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • » next
  • Learning C++

    void 19 years ago
    That's no surpise. In DOS it's alot harder to instruct the computer on how to draw graphics. Directx, openGL, an win32 do all the grunt work for you now.
    #
    Amarth 19 years ago
    My comment:

    Were there ever .bat-games? that's pretty impressive... I mean I started my coding in QBasic, and that's just YA Easy Language (for DOS at least... it can't do a thing object-oriented). But a batch-game... wow . I wrote a couple of easy batch-files myself, but they were mostly just to streamline certain operations... Anyway that's beside the C++ point .

    So, back to C:


    bool exit = false;

    do
    {

    case 5:
    exit = true
    break;

    }while (exit == false);


    can be simplified to (btw "exit == false" != "exit = false")


    bool continue = true;

    do
    {

    case 5:
    continue = false
    break;

    }while (continue);


    It's not that much of a change... But don't over-complexify things by checking for negations. Also, don't use an equal-test for booleans. Just check the name or !name...
    Once again, don't mind me if you don't like me. I just give you advise to make you see what things can be chenged, as most can be done in 2 ways. I thought about this calculator too... I have a challenge:
    Make it so that FIRST the two numbers are being read, and that then the selection between the operators is done. Then answer the question: why do I ask you to do this?

    Next thing: arrays and structures:
    don't worry about struct's... skip to classes. They are much more powerful, but almost the same, and they are the standard now.
    array's are important, but not that hard. I'm waiting till you see pointers

    a debugger let's you stop the progress of your program to check various conditions and variables... Very helpful, but it can be avoided by writing debug messages to the screen or to a file. This does mean, of course, altering and re-compiling your program. A debugger is a powerful tool when you now how to use it, but is not absolutely necessary for something to work.

    -Amarth
    #
    void 19 years ago
    can be simplified to (btw "exit == false" != "exit = false")

    Ummmm..... I did it on purpose..... as a .... ummmm..... test! yeah a test. ops: No big deal I would have picked it up if I ran the program.

    Didn't realize I could do it like that but I don't think I've ever used bool anyway.

    Once again, don't mind me if you don't like me. I just give you advise to make you see what things can be chenged, as most can be done in 2 ways.

    bah?
    #
    NeoGangster 19 years ago
    I did once upon a time a game in dos lol just text and german...
    I could post the code if you want it but i don't want to translate it XD
    #
    Marevix 19 years ago
    There weren't even any graphics in the battleship game, I found around 300 or so (probably more) switch statement cases making up the bulk of it.
    #
    Anonymous1157 19 years ago
    Where can I get BOTH those DOS thingymajiggers? By the way, DOS command line is useful as an installer. I once started bundling some stuff just to practice DOS! BTW How would you get DOS to render a moving pixel on the deafult black background all in a batch file? Makes a nice challenge; then again im only 11...
    #
    Marevix 19 years ago
    Battleship game: <!-- m --><a class="postlink" href="http://www.cprogramming.com/cgi-bin/source/source.cgi?action=Category&CID=2">http://www.cprogramming.com/cgi-bin/sou ... gory&CID=2</a><!-- m -->

    On another point, it's astounding how young people like Anoynymous 1157 can learn so much better than many irresponsible adults in the world can.
    You really should learn C++ at your current age, you could be better than Ville when you're 20 or so.
    #
    Amarth 19 years ago
    I don't think you can make a graphics game with only a .bat file... Perhaps when you'd write directly into the video memory, but I don't know how to do that (perhaps with some help of debug.exe?), and even then, it's very dangerous . Don't you mind DOS, please. Start C++ .

    -Amarth
    #
    Zombie 19 years ago
    Please excuse the intrusion... But I don't know what the bloody barnacles any of ye be talking about... yarr...

    But anywho, I'm going to the bookstore this weekend... Book suggestions for C++ anyone? I plan to get a few electronics and computer books too...

    In fact, any and every book suggestion... Just let me know... I need new books... I can read the ones I have until they decay... but I only want to read the ones I have until I get bored...
    #
    void 19 years ago
    c++ the complete reference 4th editon is a MUST. This book is the bible for c++, even Ville should buy it. It covers sooo much and has source code examples to back everything up. Even if your not sure just take my word for it and buy this book. At first it may be a bit hard to pick up but give it time and know what your looking for inside it and it will become your favorite book.

    Also find yourself a c++ introduction book. Cheak amazon to see which one has the best rating and would suit you needs.

    One other book you might like is "The Elegant Universe" It's a science book that talks about reletivity, quantum mechanics, string theory, and much more. If you want to know about alll these subject this would be a very good book to get. (don't worry, you don't need a degree in physics to understand it although you may have to read so bits a few times to get what it's saying.)
    #
    Marevix 19 years ago
    Anyone know of a way to convert a decimal into a percent using C++? I wanna make a self-grading DOS test.
    #
    void 19 years ago
    Don't you just multiply it by 100? i.e.

    0.75*100 = 75%

    Just look in a school text book or something to make sure this is right.

    In a function something like this...


    int d_to_f (int x)
    {

    int y;

    x*100 = y;

    return (y);
    }
    #
    Marevix 19 years ago
    Yes, I thought of that soon after posting, but I got too lazy to edit. I know I could do this myself, but does anyone have an idea on how to convert fractions into decimals or percents like this? Not only would it work for my self-grading program, but it could also be included in a more advanced version of my calculator along with reducing fractions. 6th graders rejoice!
    #
    Amarth 19 years ago
    About fractions. It would be a good time to learn about classes now, and represent a fraction as a class. But anyway... btw, i have no idea whether my english names are right, just try to get the idea
    Basically, you represent the fraction with two integers. The decimal value is simply the division, but make sure to have a floating-point division (use a cast if needed). Remember that a percent is nothing more than a hundred times the decimal value, with the '%' added if necessary.
    To simplify a fraction, search the greatest common divider between the numerator and the denominator and integer-divide both with it. To search this gcd, there are a lot of existing algorithms out there, and i suggest you use one of those.

    Then, some more stuff:
    To add two fractions, multiply the numerator of the one with the denominator of the other and vice versa, then make a fraction with the sum of the two new values as numerator, and the multiplication of the denominators as denominator. Then simplify that fraction.
    Multiplication is even simpler, just multiply numerators and denominators.
    Division is equally simple, but multiply numerator with denominator.

    If you tackle this class-based, you'll want a constructor that automatically simplifies the fraction, and that checks that the denumerator is not zero.

    I can be pretty broad about this because we saw a class 'fraction' in our lessons programming at school . It's in Java, however, but the idea remains the same.

    -Amarth
    #
    Marevix 19 years ago
    Well, I have what I need for a self-grading test already (how to turn fraction into decimal, decimal into percent). I've found Euclid's algorithm on the internet for reducing fractions, but I don't quite get how it works yet.

    7/9: 7 / 9 = 1 + 2
    9 / 2 = 4 + 1
    4 / 1 = 4 exactly.

    The website says that 4 should be the gcd, but 4 does not divide into 7 or 9. What did I do wrong?
    #
    Amarth 19 years ago
    It should be:
    gcd(7,9) = gcd(9,7) (i think the second number has to be the smaller one, not sure though).
    9 = 7*1+2, thus gcd(9,7) = gcd(7,2)
    7 = 2*3 + 1, thus gcd(7,2) = gcd(2,1) = 1
    if i got that right . And that is indeed the right answer, since 9/7 cannot be simplyfied.

    Now, based from you post, perhaps you need something else:
    9/2 = 4+1/2
    9/7 = 1+2/7
    etc
    that's pretty easy to implement: the first part is the integer division of numerator and denominator, the second part is the 'modulo', wich can be calculated in C with the % operator, example:

    9%7 = 2 and 9/7 = 1
    9%2 = 1 and 9/2 = 4

    -Amarth
    #
    Marevix 19 years ago
    It doesn't seem to work on 48/100 though..

    48/100: 100 / 48 = 2 * 1 + 4 (GCD 2,4)
    4 / 2 = 2 with no remainder, so 2 is the GCD.

    Euclid's pissing me off.
    #
    NeoGangster 19 years ago
    For those of you who want to make games here is a good game programming libary for C/C++

    <!-- m --><a class="postlink" href="http://www.allegro.cc/go.php?_url=http%3A%2F%2Falleg.sourceforge.net&">http://www.allegro.cc/go.php?_url=http% ... forge.net&</a><!-- m -->

    Allegro is a game programming library for C/C++ developers distributed freely, supporting the following platforms: DOS, Unix (Linux, FreeBSD, Irix, Solaris, Darwin), Windows, QNX, BeOS and MacOS X. It provides many functions for graphics, sounds, player input (keyboard, mouse and joystick) and timers. It also provides fixed and floating point mathematical functions, 3d functions, file management functions, compressed datafile and a GUI.
    #
    Marevix 19 years ago
    Thanks for the link, NeoGangster. I still can't get Euclid's GCD algorithm yet though.
    #
    Amarth 19 years ago
    What's the Euclid trouble? And do you actually need it? because i seem to have the impression you are actually searching for an integer/remaining fraction kind of thing, but perhaps I'm wrong. I'll try to explain Eclid once more

    Take two positive integers, a and b, a>b
    Search how many times b goes into a, thus integer-divide a by b. You'll get
    a = b*t + r
    with a and b the given numbers, and t and r 2 other numbers to make it being right, so that r<b. Now, the gcd(a,b) = gcd(b,r). Thus you'll take that for the next step.
    So it does work for 48/100:

    (step 1)100 = 48*2 + 4
    thus gcd(100,48 ) = gcd(48,4)
    (step 2)48 = 4*12
    thus gcd(48,4) = 4 (because there is no remaining term)

    indeed, the greatest common divisor of 100 and 48 is 4:
    48/100 = (48/4)/(100/4) = 12/25

    It's not that hard for me :d. Note that Eculid has nothing to see with fractions, just with positive integers. The RESULT you get from that algorithm, however, is interesting to use in fractions. Keep the things apart .

    -Amarth
    #
    Marevix 19 years ago
    Now I get it. Thanks, don't know why I didn't understand it sooner.
    #
    Zombie 19 years ago
    Zombie has no idea what you are talking about...

    But anyways, I've been tricked out on various games... X2: The Threat is one good space trading sim-type thing...

    Okey, anyways... I just got this book, "Sam's Teach Yourself Game Programming in 24 Hours" right? I love it already. It's a C++ based book that so far into my reading has delved into the basic idea of game programming and I'm now on Object Oriented Programming...

    I was going nuts in Barnes & Nobles because I couldn't find a damnedable book that taught game programming in C++... I mean, I have game ideas, but I have no idea where to start yet... :/ Anywho, I'll probably be ignoring classes to read now... I mean, when will I need trigonometry in real life situations? How about British Literature? And why do they even bother teaching 'proper' english, when little to no people SPEAK english properly?! Well, needless to say... I'll be glad with electronics classes and stuff next year!

    Anyways...

    ... ... ...

    I dunno...
    #
    void 19 years ago
    I mean, when will I need trigonometry in real life situations?

    If you ever make 3d games you'll need to know trig as well as matrices and a bunch of other stuff.

    How about British Literature? And why do they even bother teaching 'proper' english, when little to no people SPEAK english properly?!

    I don't think it's such a bad idea. The English language is at risk of being destroyed with all the rapper slang and what not.

    yo, u, da, wat, snizzel fizzel u wizzel...

    Which is another reason to learn math because it is a universal language to describe nature.
    #
    Toko 19 years ago
    wanna, will,can learn.............ug......zzzz....zzzz.....zzz.....
    #
    ville 19 years ago
    "void" said:
    I mean, when will I need trigonometry in real life situations?

    If you ever make 3d games you'll need to know trig as well as matrices and a bunch of other stuff.

    He's lying. I don't know squat about trigonometry, yet I've made full 3D engines and physics engines. The thing is, you can use other people's knowledge, no need for your own.
    #
    Neoecs 19 years ago
    Allegro is a very good easy to use C++ engine =/

    <!-- m --><a class="postlink" href="http://www.allegro.cc/go.php?_url=http%3A%2F%2Falleg.sourceforge.net&">http://www.allegro.cc/go.php?_url=http% ... forge.net&</a><!-- m --> - Best tutorial ever
    <!-- m --><a class="postlink" href="http://www.allegro.cc/">http://www.allegro.cc/</a><!-- m --> - a very good site
    <!-- m --><a class="postlink" href="http://heanet.dl.sourceforge.net/sourceforge/alleg/all403.zip">http://heanet.dl.sourceforge.net/source ... all403.zip</a><!-- m --> - Engine
    <!-- m --><a class="postlink" href="http://www.angelfire.com/games4/exemplar/">http://www.angelfire.com/games4/exemplar/</a><!-- m --> - a few good tut's
    #
    Zombie 19 years ago
    "void" said:
    I mean, when will I need trigonometry in real life situations?

    If you ever make 3d games you'll need to know trig as well as matrices and a bunch of other stuff.

    How about British Literature? And why do they even bother teaching 'proper' english, when little to no people SPEAK english properly?!

    I don't think it's such a bad idea. The English language is at risk of being destroyed with all the rapper slang and what not.

    yo, u, da, wat, snizzel fizzel u wizzel...

    Which is another reason to learn math because it is a universal language to describe nature.

    Phht... I'm taking physics so when I get into building a game engine I can build one based on the actual laws of physics. Trigonometry is mostly useless. Matricies are easy, but I can't see where I'd use them...

    And the English language should be left to the English. Americans should focus on creating their own language, one that is simple but can be used to express complex ideas. We should write our language how we speak it, not the other way around. The first method of informational exchange was verbal. Written languages came in afterwards, when people encountered others who didn't know what the heck they were saying.

    Americans teach that if it sounds right when you say it, then it is probably grammatically incorrect. I ask why, and earn the loathing of many english teachers. Only 2 (my current Brit Lit teacher, and my summerschool Survey Lit teacher) actually understood what I was saying in this sense, and I think actually agreed with me.

    We should write things the way we say them. Things should be simpler. If we have rules, but five-thousand-and-one exeptions to them, then what is the point of the rules? Why not just make new rules that don't apply to the exceptions? Why do we not just have nouns, verbs, adjectives, adverbs, and conjunctions? Why do we need anything else? "I am going home"... Noun, verb, adverb... am is a form of 'to be' and going is a form of 'to go'. That's all we need. A noun is a subject or a target. Either it is the actor or the acted upon. "I pushed you"... Noun, verb, noun... It's that simple...

    Anyways, my cable is being frozen (seriously! it's cold enough here to freeze TV in Chicago... ;P) and glitchy so I have no background noise and am kinda irritated about that... Grrr...

    Heh...

    In regards to C++, I kinda wish there was some way where I could just pour out my ideas, and the game I envisioned would just be easily and quickly made... Alas, 'tis not so... So I guess I'll have to learn to do decent graphics in paint... over time I might actually get pretty good at graphics...
    #
    Amarth 19 years ago
    "Zombie" said:
    In regards to C++, I kinda wish there was some way where I could just pour out my ideas, and the game I envisioned would just be easily and quickly made... Alas, 'tis not so...

    Luckily for us, I'd like to say . Imagine every idea appearing in Zombies head to be released upon the unsuspecting world... It's bad enough on this forum .

    -Amarth
    #
    Marevix 19 years ago
    Agreed. Imagine what a 4 year old would make.
    #
    void 19 years ago
    "ville" said:

    He's lying. I don't know squat about trigonometry, yet I've made full 3D engines and physics engines. The thing is, you can use other people's knowledge, no need for your own.

    Okay, so you're able to make a 3d game by using other peoples math, but it's still a good idea to learn the math yourself.


    Phht... I'm taking physics so when I get into building a game engine I can build one based on the actual laws of physics. Trigonometry is mostly useless. Matricies are easy, but I can't see where I'd use them...

    Physics you say? Well you'll soon see that trigonometry is a very impprtant part of physics. Matricies are used to manipulate objects in 3d space. Also why build a game engine based on the actual laws of physics when you can make one with your own aggghh-the-pain-kill-me-now! laws of physics.
    #
    ville 19 years ago
    "void" said:
    "ville" said:

    He's lying. I don't know squat about trigonometry, yet I've made full 3D engines and physics engines. The thing is, you can use other people's knowledge, no need for your own.

    Okay, so you're able to make a 3d game by using other peoples math, but it's still a good idea to learn the math yourself.

    Oh yes, of course. Can't argue with that. Just noting that it's not requisite.
    #
    Zombie 19 years ago
    "Amarth" said:
    "Zombie" said:
    In regards to C++, I kinda wish there was some way where I could just pour out my ideas, and the game I envisioned would just be easily and quickly made... Alas, 'tis not so...

    Luckily for us, I'd like to say . Imagine every idea appearing in Zombies head to be released upon the unsuspecting world... It's bad enough on this forum .

    -Amarth

    Bwahahahaha! And I havn't even released the tip of my idea iceberg! The Ideaberg I calls it... ;P

    Anyways... You'd need a device to pour your ideas into so the device can make your idea for you. If your four-year-old was making too many purple-spot-striped donkey elephacamogigerats then you'd take it away... By the way... That's a donkey/elephant/camel/dog/tiger/cat mix with stripes of purple spots.

    And who says real-world physics arn't aggghh-the-pain-kill-me-now! physics? Ever try to fly? Lemme tell you the trick... well it's more of a knack... Well the tric-err, knack to flying is to throw yourself at the ground and miss... That's right! You must completely ignore gravity and simply miss the ground! Of course, you musn't be AWARE that you've missed the ground until you've already missed it, because if you are actively TRYING to miss the ground, then you won't miss it because you know it's there! How can you miss it if you see it right in front of you?! On a similar topic, ever break your arm from throwing yourself at the ground, sliding across a linoleum floor, and impacting a cement wall? You'll get yer aggghh-the-pain-kill-me-now! physics lesson right there... ;P

    And why would I not want to build a game engine based on real-world physics? And how exactly would I make my own laws of physics? Does anyone actually know HOW to make one?! Suuure, you can decrease or increase the gravity, change some numbers about... But you need to replicate real-world physics first in order to make your own, because you need something to edit!

    It's like saying something in your own words... I usually say, "Englifaalibiniklie triyuxiornolomoboto aaffbaffcaffdaffeafffaffgaff, mortonlaibonotogiyufgen." and then the teacher looks at me all funny... sometimes it takes them a bit, but they eventually get it and either laugh (with the whole class, and quite loudly too) or discipline me (usually accompanied by class laughing too)... ;P[/b]
    #
    Click 19 years ago
    I don't really understand how you can use C++ to make a game. How would you put the graphics in and the sounds in?
    #
    HarmlessHermit 19 years ago
    From my limited knowledge of C++ I think that's where using files, animations, and music already made comes into play. Simple things like circles or dots can be drawn just by typing in something but other things are made outside of the C++ language. Am I right? *prepares to be corrected*
    #
    void 19 years ago

    I don't really understand how you can use C++ to make a game. How would you put the graphics in and the sounds in?

    You use C++ to talk to the computer and tell it to load an image or a mesh or sounds.... it's pretty simple in theory.
    #
    Forum » Learning C++
  • « previous
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • » next
  • Post Reply


    Your email:
    Your name: