bm 1.sınıf öğrencisiyim hoca bizden oyun yapmamızı istedi (visual c++ da) kodları yazmaya başladık ancak araba hareketinde bir problem var nasıl düzelteceğimizi bulamıyoruz problem sağ ve sol harekette araba sağa ve sola gidip kayboluyor sürekli kalmasını sağlamalıyız yardımcı olursanız sevinirim
#include "graphics.h"
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
void arabaMaviSol()
{
setcolor(BLUE);
rectangle(330,425,370,475);
rectangle(335,410,365,425);
}
void arabaMaviSag()
{
setcolor(BLUE);
rectangle(430,425,470,475);
rectangle(435,410,465,425);
}
void arabaKırmızıSag()
{
setcolor(RED);
rectangle(230,425,270,475);
rectangle(235,410,265,425);
}
void arabaKırmızıSol()
{
setcolor(RED);
rectangle(130,425,170,475);
rectangle(135,410,165,425);
}
void ödül (int y, int randSayi)
{
if (randSayi==0)
{
setcolor(RED);
rectangle(135,y+50,165,y+80);
rectangle(140,y+55,160,y+75);
}
if (randSayi==1)
{
setcolor(RED);
rectangle(235,y+50,265,y+80);
rectangle(240,y+55,260,y+75);
}
if(randSayi==2)
{
setcolor(BLUE);
rectangle(435,y+45,465,y+75);
rectangle(440,y+50,460,y+70);
}
if(randSayi==3)
{
setcolor(BLUE);
rectangle(335,y+45,365,y+75);
rectangle(340,y+50,360,y+70);
}
{
if(randSayi==4)
{
setcolor(BLUE);
circle(150,y+350,15);
circle(150,y+350,10);
}
if(randSayi==5)
{
setcolor(BLUE);
circle(450,300+y,15);
circle(450,300+y,10);
}
if(randSayi==6)
{
setcolor(RED);
circle(250,350+y,15);
circle(250,350+y,10);
}
if(randSayi==7)
{
setcolor(BLUE);
circle(350,300+y,15);
circle(350,300+y,10);
}
}
}
void ödül(int y)
{
setcolor(RED);
circle(150,y+45,15);
circle(150,y+50,10);
}
void serit()
{
line(100,0,100,1000);
line(200,0,200,1000);
line(300,0,300,1000);
line(400,0,400,1000);
line(500,0,500,1000);
}
void arkaPlan()
{
setcolor(BLACK);
line(100,0,100,1000);
line(101,0,101,1000);
line(102,0,102,1000);
line(103,0,103,1000);
line(200,0,200,1000);
line(201,0,201,1000);
line(300,0,300,1000);
line(301,0,301,1000);
line(400,0,400,1000);
line(401,0,401,1000);
line(500,0,500,1000);
line(501,0,501,1000);
line(502,0,502,1000);
line(503,0,503,1000);
}
int main()
{
int x=0;
int y=0;
char girdi;
int sur=DETECT,gmode;
initgraph(&sur,&gmode,"");
while(true)
{
serit();
setcolor(RED);
rectangle(130,425,170,475);
rectangle(135,410,165,425);
setcolor(BLUE);
rectangle(430,425,470,475);
rectangle(435,410,465,425);
setbkcolor(WHITE);
while(true)
{
arkaPlan();
srand(time(NULL));
int randSayi;
randSayi=rand() %8;
for(int i = 0; i<100;i++)
{
ödül(y,randSayi);
}
char karakter1 = getch();
setcolor(RED);
if(karakter1=='a')
arabaKırmızıSol();
else if(karakter1=='d')
arabaKırmızıSag();
//char karakter = getch();
if(karakter1=='j')
arabaMaviSol();
else if(karakter1=='l')
arabaMaviSag();
delay(100);
cleardevice();
x++;
y=y+10;
setcolor(RED);
circle(150,350+y,15);
circle(150,350+y,10);
setcolor(BLUE);
circle(450,300+y,15);
circle(450,300+y,10);
}
}
getchar();
closegraph();
return 0;
}
#include "graphics.h"
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
void arabaMaviSol()
{
setcolor(BLUE);
rectangle(330,425,370,475);
rectangle(335,410,365,425);
}
void arabaMaviSag()
{
setcolor(BLUE);
rectangle(430,425,470,475);
rectangle(435,410,465,425);
}
void arabaKırmızıSag()
{
setcolor(RED);
rectangle(230,425,270,475);
rectangle(235,410,265,425);
}
void arabaKırmızıSol()
{
setcolor(RED);
rectangle(130,425,170,475);
rectangle(135,410,165,425);
}
void ödül (int y, int randSayi)
{
if (randSayi==0)
{
setcolor(RED);
rectangle(135,y+50,165,y+80);
rectangle(140,y+55,160,y+75);
}
if (randSayi==1)
{
setcolor(RED);
rectangle(235,y+50,265,y+80);
rectangle(240,y+55,260,y+75);
}
if(randSayi==2)
{
setcolor(BLUE);
rectangle(435,y+45,465,y+75);
rectangle(440,y+50,460,y+70);
}
if(randSayi==3)
{
setcolor(BLUE);
rectangle(335,y+45,365,y+75);
rectangle(340,y+50,360,y+70);
}
{
if(randSayi==4)
{
setcolor(BLUE);
circle(150,y+350,15);
circle(150,y+350,10);
}
if(randSayi==5)
{
setcolor(BLUE);
circle(450,300+y,15);
circle(450,300+y,10);
}
if(randSayi==6)
{
setcolor(RED);
circle(250,350+y,15);
circle(250,350+y,10);
}
if(randSayi==7)
{
setcolor(BLUE);
circle(350,300+y,15);
circle(350,300+y,10);
}
}
}
void ödül(int y)
{
setcolor(RED);
circle(150,y+45,15);
circle(150,y+50,10);
}
void serit()
{
line(100,0,100,1000);
line(200,0,200,1000);
line(300,0,300,1000);
line(400,0,400,1000);
line(500,0,500,1000);
}
void arkaPlan()
{
setcolor(BLACK);
line(100,0,100,1000);
line(101,0,101,1000);
line(102,0,102,1000);
line(103,0,103,1000);
line(200,0,200,1000);
line(201,0,201,1000);
line(300,0,300,1000);
line(301,0,301,1000);
line(400,0,400,1000);
line(401,0,401,1000);
line(500,0,500,1000);
line(501,0,501,1000);
line(502,0,502,1000);
line(503,0,503,1000);
}
int main()
{
int x=0;
int y=0;
char girdi;
int sur=DETECT,gmode;
initgraph(&sur,&gmode,"");
while(true)
{
serit();
setcolor(RED);
rectangle(130,425,170,475);
rectangle(135,410,165,425);
setcolor(BLUE);
rectangle(430,425,470,475);
rectangle(435,410,465,425);
setbkcolor(WHITE);
while(true)
{
arkaPlan();
srand(time(NULL));
int randSayi;
randSayi=rand() %8;
for(int i = 0; i<100;i++)
{
ödül(y,randSayi);
}
char karakter1 = getch();
setcolor(RED);
if(karakter1=='a')
arabaKırmızıSol();
else if(karakter1=='d')
arabaKırmızıSag();
//char karakter = getch();
if(karakter1=='j')
arabaMaviSol();
else if(karakter1=='l')
arabaMaviSag();
delay(100);
cleardevice();
x++;
y=y+10;
setcolor(RED);
circle(150,350+y,15);
circle(150,350+y,10);
setcolor(BLUE);
circle(450,300+y,15);
circle(450,300+y,10);
}
}
getchar();
closegraph();
return 0;
}