By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Forums - General Discussion - Need some help on 2D game programming...

^ Yeah but I said 57 was alot for a number guessing game....



 

Around the Network

OMG, I just looked at your code in the other thread, and if you code like that you'll have one heck of a time trying to write any type of graphical game. Don't even attempt Tetris, go simpler with something like graphical tic-tac-toe, or even better yet, try solitaire or blackjack on a command line interface. Graphics in C++ are a royal pain and until you can write a good engine you'll be wasting your time.

First off, format your code, or debugging will be near impossible.

Get rid of i before every int (or any abbreviation for a type), its the worst way to code ever and makes reading your code a pain. A good compiler won't let you assign the wrong value type to it anyways without having to cast which you can read anyways.

Put your open brace on a new line also, It'll make everything so much easier when your trying to figure out what the heck your doing.

Use for loops, they are your friend.


your code in your other thread should have looked like this which is only 37 lines of code. Even then, magic numbers are bad, and should be replaced by constants.

#include
#include
#include

using namespace std;

void main()
{
   system("TITLE COOKIE JAR GUESSING GAME");
    system("COLOR 2");
    int cookies;
    int guess;
   bool won = false;

    srand((unsigned int)time(0));
    cookies = rand()%10+1;
    cout<<"guess how many cookies are in the jar"<

    for(int i = 0; i < 3 && !won; ++i)
   {
      cin>>guess;
      if(guess < cookies)
      {
         cout<<"too low"<
      }
      else if (guess > cookies)
      {
          cout<<"too high" << endl;
      }
      else // guess == cookies
      {
         cout<<"you win!"<
         won = true;
      }
   }
   system("PAUSE");
}




If you drop a PS3 right on top of a Wii, it would definitely defeat it. Not so sure about the Xbox360. - mancandy
In the past we played games. In the future we watch games. - Forest-Spirit
11/03/09 Desposit: Mod Bribery (RolStoppable)  vg$ 500.00
06/03/09 Purchase: Moderator Privilege  vg$ -50,000.00

Nordlead Jr. Photo/Video Gallery!!! (Video Added 4/19/10)

^

uh..... gibberish to me



And that's the only thing I need is *this*. I don't need this or this. Just this PS4... And this gaming PC. - The PS4 and the Gaming PC and that's all I need... And this Xbox 360. - The PS4, the Gaming PC, and the Xbox 360, and that's all I need... And these PS3's. - The PS4, and these PS3's, and the Gaming PC, and the Xbox 360... And this Nintendo DS. - The PS4, this Xbox 360, and the Gaming PC, and the PS3's, and that's all *I* need. And that's *all* I need too. I don't need one other thing, not one... I need this. - The Gaming PC and PS4, and Xbox 360, and thePS3's . Well what are you looking at? What do you think I'm some kind of a jerk or something! - And this. That's all I need.

Obligatory dick measuring Gaming Laptop Specs: Sager NP8270-GTX: 17.3" FULL HD (1920X1080) LED Matte LC, nVIDIA GeForce GTX 780M, Intel Core i7-4700MQ, 16GB (2x8GB) DDR3, 750GB SATA II 3GB/s 7,200 RPM Hard Drive

try gamemaker. it rocks at making simple 2d games and you dont need to know how to code and its free.



Reading this thread makes me miss the fun programming assignments we got back in high school. :(