Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
VarunKhambhata authored Aug 16, 2019
1 parent b3b5f05 commit 48ab23d
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 0 deletions.
Binary file added THE GAME/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added THE GAME/Runner.class
Binary file not shown.
106 changes: 106 additions & 0 deletions THE GAME/Runner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Runner implements Runnable,KeyListener
{
Thread t;
JFrame f;
JLabel rnnr1, rnnr2, fnsh;
int rnr1_pos=5;
int rnr2_pos=5;
int c=0,a;
JLabel msg=new JLabel();
boolean start=false;
Runner()
{
rnnr1=new JLabel(new ImageIcon("0.png"));
rnnr2=new JLabel(new ImageIcon("0.png"));
fnsh=new JLabel(new ImageIcon("finish.jpg"));
f=new JFrame("Foot Race");
f.setSize(800,500);
f.add(rnnr1);
f.add(rnnr2);
f.add(fnsh);
rnnr1.setBounds(5,5,100,135);
rnnr2.setBounds(5,200,100,135);
fnsh.setBounds(675,5,200,500);
f.setLayout(null);
f.addKeyListener(this);
f.getContentPane().setBackground(Color.WHITE);
f.add(msg);
msg.setBounds(400,100,100,100);
msg.setVisible(false);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
}
public static void main(String[] arg)
{
Runner game=new Runner();
game.t=new Thread(game);
game.t.start();
}

public void run()
{
try
{
while(true)
{
//rnr1_pos+=10;
//rnr2_pos+=10;
if(start)
{
if(a>500)
a=1;
else
a+=12;
if(c==7)
c=0;
else c+=1;
rnnr1.setBounds(rnr1_pos,5,100,135);
rnnr2.setBounds(rnr2_pos,200,100,135);
rnnr1.setIcon(new ImageIcon(c+".png"));
rnnr2.setIcon(new ImageIcon(c+".png"));
if(rnr1_pos>=700)
{
msg.setText("Winner: Player 1");
msg.setVisible(true);
t.stop();
}
else if(rnr2_pos>=700)
{
msg.setText("Winner: Player 2");
msg.setVisible(true);
t.stop();
}
}


t.sleep(90);
}


}
catch(InterruptedException e){}
}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e)
{
if(!start)
start=true;
if(e.getKeyCode()==KeyEvent.VK_A)
{
rnr1_pos+=10;
}
if(e.getKeyCode()==KeyEvent.VK_L)
{
rnr2_pos+=10;
}

}
public void keyPressed(KeyEvent e){}


}
Binary file added THE GAME/finish.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 48ab23d

Please sign in to comment.