프로그래밍 사악한 천재를위한 비디오 게임 : 프로젝트 10 : 과격한 레이싱 자동차
Iv'e이 책에 대한 답변 모든 것을 보았다. 그리고 나는이 책을 읽으려고하는 다른 사람이 같은 방식으로 느낀다는 것을 압니다. "이블 천재를위한 비디오 게임 프로그래밍"이 책을 읽은 사람이 있습니까? 저는 프로젝트 10에 있습니다 : 래디컬 레이싱 - 자동차. 모든 것은 올바르게 컴파일되지만 어떤 이유로 JFrame의 정확한 위치에 내 차가 나타나지 않습니다. 그들은 두 개의 흰 선 아래 나타나야합니다. 저는 코드가 책과 정확히 같지만 책이 잘못되었음을 긍정적입니다. 나는 원점의 HEIGHT 부분을 이미 변경하려고 시도했지만, 내가하는 일이 무엇이든 상관없이 그것은 움직이지 않는다. 적어도 10 명의 담당자가 없기 때문에 이미지를 첨부 할 수 없습니다. 이것은 자동차 배치를 다루는 코드입니다.
public class TheCars extends JFrame
{
final int WIDTH = 900; int HEIGHT = 650;
double p1Speed = .5, p2Speed = .5;
Rectangle p1 = new Rectangle(WIDTH/9,HEIGHT/2, WIDTH/30,WIDTH/30);
Rectangle p2 = new Rectangle(((WIDTH/9)+((int)((WIDTH/9)*1.5)/2)),(HEIGHT/2)+
(HEIGHT/10),WIDTH/30,WIDTH/30);
//the constructor
public TheCars()
{
//the following code creates the JFrame
super("Radical Racing");
setSize(WIDTH,HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//start the inner class (which works on it's own because it is a thread)
Move1 m1 = new Move1();
Move2 m2 = new Move2();
m1.start();
m2.start();
}
//this will draw the cars and the racetrack
public void paint(Graphics g)
{
super.paint(g);
//set the color to blue for p1
g.setColor(Color.BLUE);
//now draw the actual player
g.fill3DRect(p1.x,p1.width,p1.width,p1.height,true);
//set the color to red for p2
g.setColor(Color.red);
//now draw the actual player
g.fill3DRect(p2.x,p2.width,p2.width,p2.height,true);
}
private class Move1 extends Thread
{
public void run()
//This should all be in an infinite loop so that the process repeats.
{
while(true)
{
//now put in the try block. This will let
//the program exit if there is an error
try
{
//first refresh the screen
repaint();
//increase speed a bit
if(p1Speed<=5)
p1Speed+=.2;
p1.y-=p1Speed;
//this delays the refresh rate
Thread.sleep(75);
}
catch(Exception e)
{
//if there is an exception (an error), exit the loop
break;
}
}
}
}
private class Move2 extends Thread
{
public void run()
{
//this should all be in an infinite loop so the process repeats
while(true)
{
//now put the code in a "try" block.
//this will let the program exit if there is an error
try
{
//first refresh the screen
repaint();
//increase the speed a bit
if(p2Speed<=5)
p2Speed+=.2;
p2.y-=p2Speed;
//this delays the refresh rate
Thread.sleep(75);
}
catch(Exception e)
{
//if there is an exception (an error), exitthe loop
break;
}
}
}
}
public static void main(String[]args)
{
new TheCars();
}
}
이 질문은 향후 방문자를 돕기는 어려울 수 있습니다. 작은 지리적 영역, 특정 순간에만 관련이 있거나 인터넷의 전 세계 시청자에게 일반적으로 적용 할 수없는 매우 좁은 상황에서만 관련이 있습니다. 도움이 필요하면 책이없는 사람들도 도움을 줄 수 있도록 자세한 정보를 게시해야합니다. –
HEIGHT 및 WIDTH의 값은 무엇입니까? –
더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. 지금 내가 추측 할 수있는 최선은 '코드가 잘못되었습니다'입니다. –