Jump to content
  • Advertisement
Sign in to follow this  
kingofswing94

What is wrong with this code?

This topic is 2603 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is the code:

#include<iostream>
#include<SDL/SDL.h>
#include<SDL/SDL_ttf.h>
#include<string>

using namespace std;

int frame=0;
bool cap=true;
Timer fps;
const int SCREEN_WIDTH=640;
Const int SCREEN_HEIGHT=480;
Const int SCREEN_BPP=32;
Const int FRAMES_PER_SECOND=20;
int Player_One_Points,Cpu_Points,Player_Two_Points=0;
bool quit=false;
int game_state=o;
intrandomNumber=rand();
intrandomVelocity(randomNumber%6)+1;

class Ball
{
public:

int x,y;
int xVel,yVel;
void Ball();
void Ball_Track();
void Show_Ball();
void Ball_Track_2_Player();
void Ball_Wall_Collision();
};
Ball::Ball() : randomNumber(rand()), randomVelocity((randomNumber%6)+1)
{
x=310;
y=230;
xVel=3;
yVel=0;
};
Ball::Ball_Track()
{
if(x+20 > SCREEN_WIDTH)
{
Player_One_Points+=1;
x=310;
y=230;
SDL_Delay(2000);

if(Player_One_Points==1)
{
SDL_FreeSurface(Message0);
apply_surface(30,10,Message1,screen);
}
else if(Player_One_Points==2)
{
SDL_FreeSurface(Message1);
apply_surface(30,10,Message2,screen);
}
else if(Player_One_Points==3)
{
SDL_FreeSurface(Message2);
apply_surface(30,10,Message3,screen);
}
else if(Player_One_Points==4)
{
SDL_FreeSurface(Message3);
apply_surface(30,10,Message4,screen);
}
else if(Player_One_Points==5)
{
SDL_FreeSurface(Message4);
apply_surface(30,10,Message5,screen);
}
else if(Player_One_Points==6)
{
SDL_FreeSurface(Message5);
apply_surface(30,10,Message6,screen);
}
else if(Player_One_Points==7)
{
SDL_FreeSurface(Message6);
apply_surface(30,10,Message7,screen);
}
else if(Player_One_Points==8)
{
SDL_FreeSurface(Message7);
apply_surface(30,10,Message8,screen);
}
else if(Player_One_Points==9)
{
SDL_FreeSurface(Message8);
apply_surface(30,10,Message9,screen);
}
else if(Player_One_Points==10)
{
SDL_FreeSurface(Message9);
apply_surface(30,10,Message10,screen);
apply_surface(310,205,MessageCongratsP1,screen);
SDL_Delay(4000);
SDL_FreeSurface(Message10);
SDL_FreeSurface(MessageCongratsP1);
SDL_FreeSurface(Ball);
SDL_Freesurface(Player_One_Bat);
SDL_FreeSurface(Cpu_Bat);
game_state==0;
}
}
else(x<0)
{
Cpu_Points+=1;
x=310;
y=230;
SDL_Delay(2000);

if(Cpu_Points==1)
{
SDL_FreeSurface(Message0);
apply_surface(30,10,Message1,screen);
}
else if(Cpu_Points==2)
{
SDL_FreeSurface(Message1);
apply_surface(30,10,Message2,screen);
}
else if(Cpu_Points==3)
{
SDL_FreeSurface(Message2);
apply_surface(30,10,Message3,screen);
}
else if(Cpu_Points==4)
{
SDL_FreeSurface(Message3);
apply_surface(30,10,Message4,screen);
}
else if(Cpu_Points==5)
{
SDL_FreeSurface(Message4);
apply_surface(30,10,Message5,screen);
}
else if(Cpu_Points==6)
{
SDL_FreeSurface(Message5);
apply_surface(30,10,Message6,screen);
}
else if(Cpu_Points==7)
{
SDL_FreeSurface(Message6);
apply_surface(30,10,Message7,screen);
}
else if(Cpu_Points==8)
{
SDL_FreeSurface(Message7);
apply_surface(30,10,Message8,screen);
}
else if(Cpu_Points==9)
{
SDL_FreeSurface(Message8);
apply_surface(30,10,Message9,screen);
}
else if(Cpu_Points==10)
{
SDL_FreeSurface(Message9);
apply_surface(30,10,Message10,screen);
apply_surface(310,205,MessageCongratsCpu,screen);
SDL_Delay(4000);
SDL_FreeSurface(Message10);
SDL_FreeSurface(MessageCongratsCpu);
SDL_FreeSurface(Ball);
SDL_Freesurface(Player_One_Bat);
SDL_FreeSurface(Cpu_Bat);
game_state==0;
}
}
};

Ball::Show_Ball()
{
apply_surface(x,y,Ball,screen);
};

Ball::Ball_Track_2_Player()
{
if(x+20 > SCREEN_WIDTH)
{
Player_One_Points+=1;
x=310;
y=230;
SDL_Delay(2000);

if(Player_One_Points==1)
{
SDL_FreeSurface(Message0);
apply_surface(30,10,Message1,screen);
}
else if(Player_One_Points==2)
{
SDL_FreeSurface(Message1);
apply_surface(30,10,Message2,screen);
}
else if(Player_One_Points==3)
{
SDL_FreeSurface(Message2);
apply_surface(30,10,Message3,screen);
}
else if(Player_One_Points==4)
{
SDL_FreeSurface(Message3);
apply_surface(30,10,Message4,screen);
}
else if(Player_One_Points==5)
{
SDL_FreeSurface(Message4);
apply_surface(30,10,Message5,screen);
}
else if(Player_One_Points==6)
{
SDL_FreeSurface(Message5);
apply_surface(30,10,Message6,screen);
}
else if(Player_One_Points==7)
{
SDL_FreeSurface(Message6);
apply_surface(30,10,Message7,screen);
}
else if(Player_One_Points==8)
{
SDL_FreeSurface(Message7);
apply_surface(30,10,Message8,screen);
}
else if(Player_One_Points==9)
{
SDL_FreeSurface(Message8);
apply_surface(30,10,Message9,screen);
}
else if(Player_One_Points==10)
{
SDL_FreeSurface(Message9);
apply_surface(30,10,Message10,screen);
apply_surface(310,205,MessageCongratsP1,screen);
SDL_Delay(4000);
SDL_FreeSurface(Message10);
SDL_FreeSurface(MessageCongratsP1);
SDL_FreeSurface(Ball);
SDL_Freesurface(Player_One_Bat);
SDL_FreeSurface(Player_Two_Bat);
game_state==0;
}
}
else(x<0)
{
Player_Two_Points+=1;
x=310;
y=230;
SDL_Delay(2000);

if(Player_Two_Points==1)
{
SDL_FreeSurface(Message0);
apply_surface(30,10,Message1,screen);
}
else if(Player_Two_Points==2)
{
SDL_FreeSurface(Message1);
apply_surface(30,10,Message2,screen);
}
else if(Player_Two_Points==3)
{
SDL_FreeSurface(Message2);
apply_surface(30,10,Message3,screen);
}
else if(Player_Two_Points==4)
{
SDL_FreeSurface(Message3);
apply_surface(30,10,Message4,screen);
}
else if(Player_Two_Points==5)
{
SDL_FreeSurface(Message4);
apply_surface(30,10,Message5,screen);
}
else if(Player_Two_Points==6)
{
SDL_FreeSurface(Message5);
apply_surface(30,10,Message6,screen);
}
else if(Player_Two_Points==7)
{
SDL_FreeSurface(Message6);
apply_surface(30,10,Message7,screen);
}
else if(Player_Two_Points==8)
{
SDL_FreeSurface(Message7);
apply_surface(30,10,Message8,screen);
}
else if(Player_Two_Points==9)
{
SDL_FreeSurface(Message8);
apply_surface(30,10,Message9,screen);
}
else if(Player_Two_Points==10)
{
SDL_FreeSurface(Message9);
apply_surface(30,10,Message10,screen);
apply_surface(310,205,MessageCongratsP2,screen);
SDL_Delay(4000);
SDL_FreeSurface(Message10);
SDL_FreeSurface(MessageCongratsP2);
SDL_FreeSurface(Ball);
SDL_Freesurface(Player_One_Bat);
SDL_FreeSurface(Player_Two_Bat);
game_state==0;
}
}
};
Ball::Ball_Wall_Collision()
{
if(y==0)&&(xVel==3)
{
yVel+=randomVelocity;
}
else if(y==0)&&(xVel<0)
{
yVel+=randomVelocity;
}
else if(y+=20==SCREEN_HEIGHT)&&(xVel==3)
{
yVel-=randomVelocity;
}
else(y+=20==SCREEN_HEIGHT)&&(xVel<0)
{
yVel-=randomVelocity;
}
};

class One_Player_Button
{
public:

SDL_Rect box;
One_Player_Button(intx,int,y,intw,inth);
void handle_events();
void show();
};
One_Player_Button::One_Player_Button(intx,inty,intw,inth)
{
box.x=x;
box.y=y;
box.w=w;
box.h=h;
};

One_Player_Button::handle_events()
{
intx=320,y=240;

if(event.type==SDL_MOUSEMOTION)
{
x=event.motion.x;
y=event.motion.y;

if(event.type==SDL_MOUSEBUTTONDOWN)
{
if(event.button.button==SDL_BUTTON_LEFT)
{
x=event.button.x;
y=event.button.y;

if((x>box.x)&&(x<box.x+box.w)&&(y>box.y)&&(y<box.y+box.h))
{
SDL_FreeSurface(MessagePong);
SDL_FreeSurface(MessageOnePlayer);
SDL_FreeSurface(MessageTwoPlayer);
game_state==1;
}
}
}
}
};
One_Player_Button::Show()
{
apply_surface(box.x,box.y,MessageOnePlayer,screen);
};

class Two_Player_Button
{
public:

SDL_Rect box;
Two_Player_Button(intx,int,y,intw,inth);
void handle_events();
void show();
};
Two_Player_Button::Two_Player_Button(intx,inty,intw,inth)
{
box.x=x;
box.y=y;
box.w=w;
box.h=h;
};
Two_Player_Button::handle_events()
{
intx=320,y=240;

if(event.type==SDL_MOUSEMOTION)
{
x=event.motion.x;
y=event.motion.y;

if(event.type==SDL_MOUSEBUTTONDOWN)
{
if(event.button.button==SDL_BUTTON_LEFT)
{
x=event.button.x;
y=event.button.y;

if((x>box.x)&&(x<box.x+box.w)&&(y>box.y)&&(y<box.y+box.h))
{
SDL_FreeSurface(MessagePong);
SDL_FreeSurface(MessageOnePlayer);
SDL_FreeSurface(MessageTwoPlayer);
game_state==2;
}
}
}
}
};
Two_Player_Button::Show()
{
apply_surface(box.x,box.y,MessageTwoPlayer,screen);
};

class Player_One_Bat
{
public:

int x,y;
const float yVel;
int xVel;
void Player_One_Bat();
void Show();
void Player_One_Bat_Collision();
void Player_One_Bat_Handle_Input();
};

Player_One_Bat::Player_One_Bat() : randomNumber(rand()), randomVelocity((randomNumber%6)+1)
{
x=10;
y=215;
xVel=0;
yVel=2.5;
};

Player_One_Bat::Show()
{
apply_surface(x,y,Player_One_Bat,screen);
};

Player_One_Bat::Player_One_Bat_Collision()
{
if(Ball.x==x+=10)
{
Ball.yVel+=||-= randomVelocity;

if(Ball.xVel<0)
{
Bal.xVel=3;
}
}
else if(Ball.x==x+=10)&&(SDLK_W)
{
Ball.yVel-= randomVelocity;

if(Ball.xVel<0)
{
Ball.xVel=3;
}
}
else(Ball.x==x+=10)&&(SDLK_S)
{
Ball.yVel+=randomVelocity;

if(Ball.xVel<0)
{
Ball.xVel=3;
}
}
};

Player_One_Bat::Player_One_Bat_Handle_Input()
{
if(event.type==SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_W:y-=yVel;break;
case SDLK_S:y+=yVel;break;
}
}
};

class Cpu_Bat
{
public:

int x,y;
const float yVel;
int xVel;

void Cpu_Bat();
void Show();
void Cpu_Bat_Collision();
void Cpu_Ai();
};

Cpu_Bat::Cpu_Bat() : randomNumber(rand()), randomVelocity((randomNumber%6)+1)
{
x=620;
y=215;
xVel=0;
yVel=2.5;
};

Cpu_Bat::Show()
{
apply_surface(x,y,Cpu_Bat,screen);
};

Cpu_Bat::Cpu_Bat_Collision()
{
if(Ball.x==x+=10)
{
Ball.yVel+=||-= randomVelocity;

if(Ball.xVel==3)
{
Bal.xVel-=6;
}
}
};

Cpu_Bat::Cpu_Bat_Ai()
{
if(y<Ball.y)
{
y+=Ball_Speed;
}
else(y>Ball.y)
{
y-=Ball_Speed;
}
};

class Player_Two_Bat
{
public:

int x,y;
const float yVel;
int xVel;

void Player_Two_Bat();
void Show();
void Player_Two_Bat_Collision();
void Player_Two_Bat_Handle_Input();
};

Player_Two_Bat::Player_Two_Bat() : randomNumber(rand()), randomVelocity((randomNumber%6)+1)
{
x=620;
y=215;
xVel=0;
yVel=2.5;
};

Player_Two_Bat::Show()
{
apply_surface(x,y,Player_Two_Bat,screen);
};

Player_Two_Bat::Player_Two_Bat_Collision()
{
if(Ball.x==x)
{
Ball.yVel+=||-= randomVelocity;

if(Ball.xVel==3)
{
Bal.xVel-=6;
}
}
else if(Ball.x==x)&&(SDLK_UP)
{
Ball.yVel-= randomVelocity;

if(Ball.xVel==3)
{
Ball.xVel-=6;
}
}
else(Ball.x==x)&&(SDLK_DOWN)
{
Ball.yVel+=randomVelocity;

if(Ball.xVel==3)
{
Ball.xVel-=6;
}
}
};
Player_Two_Bat::Player_Two_Bat_Handle_Input()
{
if(event.type==SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_UP:y-=yVel;break;
case SDLK_DOWN:y+=yVel;break;
}
}
};

apply_surface(intx,inty,SDL_Surface*source,SDL_Surface*destination)
{
SDL_Rect offset;
offset.x=x;
offset.y=y;
SDL_BlitSurface(source,NULL,destination,&offset);
};

SDL_Surface*load_image(string filename)
{
SDL_Surface*loadedImage=NULL;
SDL_Surface*optimizedImage=NULL;
loadedImage=SDL_LoadBMP(filename.c_str());

if(loadedImage!=NULL)
{
optimizedImage=SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
};

int main (int argc, char*args [])
{
if(SDL_Init(SDL_INIT_EVERYTHING)==-1)
{
return 1;
}
SDL_Surface *screen=NULL;
SDL_Surface *background=NULL;
SDL_Surface *Player_One_Bat=NULL;
SDL_Surface *Cpu_Bat=NULL;
SDL_Surface *Player_Two_Bat=NULL;
SDL_Surface *MessagePong=NULL;
SDL_Surface *MessageOnePlayer=NULL;
SDL_Surface *messageTwoPlayer=NULL;
SDL_Surface *Message0=NULL;
SDL_Surface *Message1=NULL;
SDL_Surface *Message2=NULL;
SDL_Surface *Message3=NULL;
SDL_Surface *Message4=NULL;
SDL_Surface *Message5=NULL;
SDL_Surface *Message6=NULL;
SDL_Surface *Message7=NULL;
SDL_Surface *Message8=NULL;
SDL_Surface *Message9=NULL;
SDL_Surface *Message10=NULL;
SDL_Surface *MessageCongratsP1=NULL;
SDL_Surface *MessageCongratsCpu=NULL;
SDL_Surface *MessageCongratsP2=NULL;
SDL_Surface *Ball=NULL;


TTF_Font*font=NULL:
TTF_Font*font2=NULL;



SDL_Color textColor={255,255,255};
screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);

if(screen==NULL)
{
return 1;
}

if(TTF_Init()==-1)
{
return false;
}

SDL_WM_SetCaption("Ping Pong",NULL);

background=load_image("background.bmp");
Player_One_Bat=load_image("paddle.bmp");
Player_Two_Bat=load_image("paddle.bmp");
Cpu_Bat=load_image("paddle.bmp");
Ball=load_image("ball.bmp");

if(background==NULL)
{
return false;
}
if(Player_One_Bat==NULL)
{
return false;
}
if(Player_Two_Bat==NULL)
{
return false;
}
if(Cpu_Bat==NULL)
{
return false;
}
if(Ball==NULL)
{
return false;
}
font=TTF_OpenFont("EthnocentricRg-Regular",36);
font2=TTF_OpenFont("EthnocentricRg-Regular",28);

if(font==NULL)
{
return false;
}
if(font2==NULL)
{
return false;
}

MessagePong=TTF_RenderText_Solid(font,"Ping Pong",textColor);
MessageOnePlayer=TTF_RenderText_Solid(font2,"One Player",textColor);
MessageTwoPlayer=TTF_RenderText_Solid(font2,"Two Player",textColor);
Message0=TTF_RenderText_Solid(font2,"0",textColor);
Message1=TTF_RenderText_Solid(font2,"1",textColor);
Message2=TTF_RenderText_Solid(font2,"2",textColor);
Message3=TTF_RenderText_Solid(font2,"3",textColor);
Message4=TTF_RenderText_Solid(font2,"4",textColor);
Message5=TTF_RenderText_Solid(font2,"5",textColor);
Message6=TTF_RenderText_Solid(font2,"6",textColor);
Message7=TTF_RenderText_Solid(font2,"7",textColor);
Message8=TTF_RenderText_Solid(font2,"8",textColor);
Message9=TTF_RenderText_Solid(font2,"9",textColor);
Message10=TTF_RenderText_Solid(font2,"10",textColor);
MessageCongratsP1=TTF_RenderText_Solid(font2,"Congratulations Player One",textColor);
MessageCongratsCpu=TTF_RenderText_Solid(font2,"Congratulations Cpu",textColor);
MessageCongratsP2=TTF_RenderText_Solid(font2,"Congratulations Player Two",textColor);

if(MessagePong==NULL)
{
return 1;
}
if(MessageOnePlayer==NULL)
{
return 1;
}
if(MessageTwoPlayer==NULL)
{
return 1;
}
if(Message0==NULL)
{
return 1;
}
if(Message1==NULL)
{
return 1;
}
if(Message2==NULL)
{
return 1;
}
if(Message3==NULL)
{
return 1;
}
if(Message4==NULL)
{
return 1;
}
if(Message5==NULL)
{
return 1;
}
if(Message6==NULL)
{
return 1;
}
if(Message7==NULL)
{
return 1;
}
if(Message8==NULL)
{
return 1;
}
if(Message9==NULL)
{
return 1;
}
if(Message10==NULL)
{
return 1;
}
if(MessageCongratsP1==NULL)
{
return 1;
}
if(MessageCongratsCpu==NULL)
{
return 1;
}
if(MessageCongratsP2==NULL)
{
return 1;
}

SDL_Event event;



while(quit=false)
{
fps.start();

if(game_state==0)
{
apply_surface(0,0,background,screen);
apply_surface(310,10,MessagePong,screen);
Player_One_Button.Show();
Player_Two_Button.Show();
}
else if(game_state==1)
{
Ball.Ball_Track();
Ball.Ball_Wall_Collision();
Cpu_Bat.Cpu_Bat_Ai();
Cpu_Bat.Cpu_Bat_Collision();
Player_One_Bat.Player_One_Bat_Collision();

Ball.Show_Ball();
Player_One_Bat.Show();
Cpu_Bat.Show();
apply-surface(30,10,Message0,screen);
apply-surface(600,10,Message0,screen);
}
else if(game_state==2)
{
Ball.Ball_Two_Player_Track();
Ball.Ball_Wall_Collision();
Player_One_Bat.Player_One_Bat_Collision();
Player_Two_Bat.Player_Two_Bat_Collision();

Ball.Show_Ball();
Player_One_Bat.Show();
Player_Two_Bat.Show();
apply-surface(30,10,Message0,screen);
apply-surface(600,10,Message0,screen);
}
while(SDL_PollEvent(&event))
{
if(game_state==0)
{
One_Player_Button.handle_events();
Two_Player_Button.handle_events();

if(event.type==SDL_QUIT)
{
quit=true;
}
}
else if(game_state==1)
{
Player_One_Bat.Player_One_Bat_Handle_Input();

if(event.type==SDL_QUIT)
{
quit=true;
}
}
else(game_state==2)
{
Player_One_Bat.Player_One_Bat_Handle_Input();
Player_Two_Bat.Player_Two_Bat_Handle_Input();

if(event.type==SDL_QUIT)
{
quit=true;
}
}
}
if(SDL_Flip(screen)==-1)
{
return 1;
}
frame++;

if((cap==true)&&(fps.get_ticks()<1000/FRAMES_PER_SECOND))
{
SDL_Delay((1000/FRAMES_PER_SECOND)-fps.get_ticks());
}

}
SDL_FreeSurface(background);

return 0;
}



What is the problem, it won't compile?

Share this post


Link to post
Share on other sites
Advertisement
Big code! I think there's a code tag or something. Let's have a look. Also I just drank a ton of whiskey before sitting down so if I type something stupid, sorry in advance.

The compiler should tell you why it doesn't compile, please add what the compiler is telling you.

But when I read through it myself, the first thing is you say "Const". C++ is case sensitive. This means that "Const" is different from "const". Trawl through your code and see how many times you make a case mistake. C++ will throw a fit.

Also generally speaking I recommend C# as a starter language but if you're not in the mood to change, don't worry about it; not a big deal.

I'm a little concerned with all the if 1 do this, if 2 do that, if 3 yada yada type code and the Message1 Message2 etc. declarations.

Are you familiar with the Standard Templates?

That means vectors, maps, etc.

Vectors, maps and arrays and so on are "containers" and are absolutely crucial concepts before you can build a bigger program.

See if you can edit that post with the code tag or whatever it's called now (GDnet got all rejigged back in January or something and I'm totally lost) and also tell us what the compiler is spittin' out and what tool chain you're using (what compiler vendor, platform, etc.)

Share this post


Link to post
Share on other sites
Aggggh, my eyes!

Put code bracers around that, and correct your typos! And explain what you're doing, what you're seeing, and any ideas you might have.

Share this post


Link to post
Share on other sites
As previously mentioned that code looks terrible, no indentation. Use code tags, or attach your code file, or post your code at ideone.com. No one want's to read your code as it is now.

intrandomNumber=rand();
intrandomVelocity(randomNumber%6)+1;

You need a space (or any whitespace character) between int and the variable name. You need to use = when giving a value to randomVelocity.

Share this post


Link to post
Share on other sites
My eyes bleed as well.

It would help to know what errors you are getting...as mentioned previously using "const" instead of "Const" will be a good starting point.

Share this post


Link to post
Share on other sites
Hate to say this, but what's wrong with the code is that it is perfect TheDailyWTF-material.

In particular, use an array instead of 10 variables Message0 to Message9, and use loops to setup the array. Then use array indexing instead of endless if-else-chains to access the messages that are stored there. (You might also consider rendering those strings on the fly, but that's not really the point.)

As far as your original question is concerned: it is rather impolite (and inefficient) to simply dump a huge amount of code somewhere, say "it doesn't compile", and ask "what is the problem?". When your code doesn't compile, your compiler gives you an error message. What is the error message? Which line of code is referenced by it? Do you understand the error message? Why not? Can you isolate the relevant parts of the code to generate a smaller example that exhibits the problem? Then post that smaller sample, since it makes it easier for people who want to help you.

Share this post


Link to post
Share on other sites
Oh I gotta add about him just dumping it here that he asked me in another thread if I'd take a look at it and I said yessir.

Share this post


Link to post
Share on other sites
I didn't know how to put in a code snippet or whatever you said. it does have indentations in notepad, i am using Bloodshed Dev C++ with SDL, the message's are a font and text. sorry about the trash code, do u think its good for someone who is 16 and is quite new to programming?

Share this post


Link to post
Share on other sites
Hidden
Also these:

[color=#1C2837][size=2]int Player_One_Points,Cpu_Points,Player_Two_Points=0;

C++ does not assign to multiple variables. That will initialize Palyer_Two_Points to 0, but not the others!

Player_One_Points and Cpu... will be left at their default values which are undefined.

That it's undefined means it might be zero on your current compiler with current settings but this could change with no warning. Never rely on undefined behaviors. If you see in a manual the term "undefined behavior" that means it can explode in your face without warning.
[color="#1C2837"][size=2][color="#000000"]



[color="#1C2837"][size=2][color="#000000"]

Also:
[color="#1C2837"][size=2][color="#000000"]



[color="#1C2837"][size=2][color="#000000"]

[color=#1C2837][size=2]int game_state=o;
[color=#1C2837][size=2]

[color=#1C2837][size=2]You accidentally wrote the letter o instead of the number 0.
[color="#1C2837"][size=2]

[color="#1C2837"][size=2]That's a pretty bad one but I guess the o is right next to the 0.
[color="#1C2837"][size=2]

[color="#1C2837"][size=2]But seriously - are you Chinese and new to Roman letters? I've never seen someone make that mistake. Your other code is almost there - you're using initialization lists and things, good job - but that mistake is just super super funny.

Share this post


Link to post

I didn't know how to put in a code snippet or whatever you said.


[ c o d e ]
code goes here
[ / c o d e ]

(Delete the spaces between the letters in the brackets.)

i am using Bloodshed Dev C++ with SDL[/quote]

I'm not familiar with that... No comment.

sorry about the trash code, do u think its good for someone who is 16 and is quite new to programming?[/quote]

Never mind your age; lots of folks start around 8 like I did.

And you accidentally typed 'o' for '0' in at least one spot which is pretty funny.

But other than that you're using things like initialization lists and such and that's good. You're learning C++, which is a monster language!

But basically it's like this, there's lots and lots of little problems and even once you get it to compile, you'll find it doesn't work.

Also, C++ doesn't do multiple assignments. So you have some code up top like:

int a,b,c=0;

Or something. You might think that this will assign 0 to a, b and c, but it will only assign to c. a and b will be left unassigned.

Just a reminder, never assume that an unassigned variable will be 0, NULL or false. The compiler will do whatever it darn well pleases. It may or may not automatically assign to 0 depending on compiler and compiler settings. We call this "undefined behavior".

But back to the programming, have you written simpler programs and are you familiar with the standard templates? Let's work those out first.

I suspect you have a brain for programming (unless this is a whole lot of copy and paste) but you need to learn the basic tools including maps and vectors.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!