Toyota Yaris Forums - Ultimate Yaris Enthusiast Site
 

 


 
Go Back   Toyota Yaris Forums - Ultimate Yaris Enthusiast Site > Members Area > Off-topic / Other Cars / Everything else Discussions
  The Tire Rack

Reply
 
Thread Tools Display Modes
Old 10-17-2014, 02:10 AM   #1
NaviLupets
 
Drives: toyota yaris
Join Date: Mar 2012
Location: Illinois
Posts: 15
Drag Racing Yaris Java Game

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.util.Random;

public class TestRace extends JFrame
{//
int a,b,c,d,connected=0,col,row, i=0,j=0;

JButton[][] board;
Car[] Cars=new Car[36];
int size=12,n=3;
int count=0,random=0;
int points=0;
Random rand = new Random();
JLabel score=new JLabel("Score:"+points+" Computer is Driving:");
JLabel messege1=new JLabel("Pick a Car to Race with!");
JLabel messege2=new JLabel();
double QMT;
double ZSIX;
String ComputerCar1;





public TestRace()
{

Cars[0]= makeCar("2002 Lingenfelter" ,1.97,9.1,36);
Cars[1]= makeCar("2002 Hennessey Venom 1000TT" ,2.2,9.4,2);
Cars[2]= makeCar("2012 Ariel Atom 500 (V-8) " ,2.3,9.5,3);
Cars[3]= makeCar("2011 Bugatti Veyron 16.4 Super Sport " ,2.4,9.6,4);
Cars[4]= makeCar("2009 Bugatti Veyron EB 16.4" ,2.4,10.1,5);
Cars[5]= makeCar("2007 Caparo T1 " ,2.5,10.2,6);
Cars[6]= makeCar("2012 Hennessey Venom GT" ,2.5,10.3,7);
Cars[7]= makeCar("2010 Bugatti Veyron 16.4 Grand Sport " ,2.5,9.99,8);
Cars[8]= makeCar("2013 Caterham Seven R600 Roadster " ,2.5,10.1,9);
Cars[9]= makeCar("2006 Ultima GTR 720" ,2.6,9.9,10);
Cars[10]= makeCar("2010 Pagani Zonda R " ,2.6,9.99,11);
Cars[11]= makeCar("2013 Ariel Atom 3.5" ,2.6,10.5,12);
Cars[12]= makeCar("2012 Koenigsegg Agera R " ,2.7,9.99,13);
Cars[13]= makeCar("2014 Porsche 918 Spyder " ,2.7,10.6,14);
Cars[14]= makeCar("2014 McLaren P1" ,2.7,10.7,15);
Cars[15]= makeCar("2012 BAC Mono" ,2.7,10.7,16);
Cars[16]= makeCar("2012 Lamborghini Aventador LP700-4 " ,2.8,10.7,17);
Cars[17]= makeCar("2011 HTT Plethore " ,2.8,10.8,18);
Cars[18]= makeCar("2011 Lamborghini Gallardo LP570-4 Superleggra " ,2.8,10.9,19);
Cars[19]= makeCar("2010 Koenigsegg Trevita " ,2.8,10.9,20);
Cars[20]= makeCar("2013 Lamborghini Veneno " ,2.8,9.1,21);
Cars[21]= makeCar("2005 Ferrari FXX Enzo " ,2.8,9.1,22);
Cars[22]= makeCar("2009 Caparo T1 Race Extreme " ,2.8,9.1,23);
Cars[23]= makeCar("2011 Dodge Viper Hennessey Venom GT " ,2.9,9.1,24);
Cars[24]= makeCar("2009 Heffner Lamborghini Gallardo LP560-4 " ,2.9,10.3,25);
Cars[25]= makeCar("2006 Mosler MT900 GTR " ,2.9,10.4,26);
Cars[26]= makeCar("2011 Ariel Atom 3 Mugen " ,2.9,10.5,27);
Cars[27]= makeCar("2011 Porsche 911 Turbo S " ,2.9,10.6,28);
Cars[28]= makeCar("2011 Ferrari 599XX " ,2.9,10.7,29);
Cars[29]= makeCar("2011 McLaren MP4-12C " ,2.9,10.8,30);
Cars[30]= makeCar("2009 Ariel Atom 3 " ,2.9,10.9,31);
Cars[31]= makeCar("2010 Noble M600 " ,2.9,10.9,32);
Cars[32]= makeCar("2012 Nissan GT-R " ,2.9,11.1,33);
Cars[33]= makeCar("2011 Dodge Viper Hennessey Venom GT " ,2.9,11.1,34);
Cars[34]= makeCar("2012 Zenvo ST1 " ,2.9,11.1,35);
Cars[35]= makeCar("2008 Toyota Yaris 2dr HB " ,6.9,15.969,1);


board=new JButton [size][n];

JPanel panelone=new JPanel();
JPanel paneltwo=new JPanel();


paneltwo.setLayout(new GridLayout(1,3));
paneltwo.add(messege1);
paneltwo.add(score);
paneltwo.add(messege2);
random = rand.nextInt(35) + 1;
ComputerCar1=Cars[random].carName;
messege2.setText(ComputerCar1);


panelone.setLayout(new GridLayout(size,n));
AllButtonListener All = new AllButtonListener();

for(int i=0;i<size;i++){
for(int j=0;j<n;j++){
board[i][j]=new JButton(Cars[count].carName);
panelone.add( board[i][j]);
board[i][j].addActionListener(All);

count++;
}}


add(paneltwo, BorderLayout.NORTH);

add(panelone);
setSize(665,665);

//int random2 = rand.nextInt(36) + 1;
//String ComputerCar=Cars[random2].carName;
//messege2.setText(" "+ComputerCar);

}

class AllButtonListener implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
int r=0,c=0,yourRank=0,yourRealRank=0;
String temp="";
int DriverRank;



for(i=0;i<size;i++)
for(j=0;j<n;j++){
yourRank++;
if(e.getSource()==board[i][j])
{r=i;c=j;
yourRealRank=yourRank-1;

temp=board[r][c].getText();
//yourRealRank=temp.getRank();
QMT=Cars[yourRealRank].getQuarter();
ZSIX=Cars[yourRealRank].getZeroSixty();
}}

if(temp.equals(ComputerCar1)){
JOptionPane.showMessageDialog(null, temp+" VS "+ComputerCar1,"It's a tie! Score:"+points,
JOptionPane.PLAIN_MESSAGE);
System.out.println(temp+" QMT="+QMT+" zeroTo60="+ZSIX+" rank="+yourRealRank);

messege1.setText("It's a tie!");
}
else if(yourRealRank<random){
points=points+100;

JOptionPane.showMessageDialog(null, temp+" VS "+ComputerCar1,"Player Wins! Score:"+points,
JOptionPane.PLAIN_MESSAGE);
System.out.println(temp+" QMT="+QMT+" zeroTo60="+ZSIX+" rank="+yourRealRank);

score.setText("Score:"+points);
messege1.setText("Power Win! ");

}
else{
points=points-100;
JOptionPane.showMessageDialog(null, temp+" VS "+ComputerCar1, "Player Loses! Score:"+points,
JOptionPane.PLAIN_MESSAGE);
System.out.println(temp+" QMT="+QMT+" zeroTo60="+ZSIX+" rank="+yourRealRank);
score.setText("Score:"+points);
messege1.setText("Player Loses!");

}
/* for(i=0;i<size;i++)
for(j=0;j<n;j++){
if(temp==board[i][j].getText();)

}

board[r][c].setText(temp);

*/
//MakeRandom();

random = rand.nextInt(35) + 1;
ComputerCar1=Cars[random].carName;
messege2.setText("Computers Car:"+ComputerCar1);

}
}

public Car makeCar(String Name,double Sixty,double quarter,int rankNum){

Car newCar=new Car();
newCar.rank=rankNum;
newCar.zeroSixty=Sixty;
newCar.quarterMile=quarter;
newCar.carName=Name;


return newCar;
}

/*public void MakeRandom(){

int count=0;
String name;
int randy;

for(i=0;i<size;i++){
for(j=0;j<n;j++){

randy = rand.nextInt(35) + 1;
board[i][j].setText(Cars[randy].getName());

count++;

}}


}*/

class Car{

private int rank;
private double zeroSixty;
private double quarterMile;
private String carName;

public void makeCar(String Name,double Sixty,double quarter,int rankNum){

rank=rankNum;
zeroSixty=Sixty;
quarterMile=quarter;
carName=Name;


}

public String newComputerCar(){
random = rand.nextInt(36) + 1;
String ComputerCar1=Cars[random].carName;
messege2.setText("Computers Car:"+ComputerCar1);

return ComputerCar1;

}

public String getCarName(){
return carName;
}

public double getZeroSixty() {
return zeroSixty;
}
public int getRank(){
return rank;
}
public double getQuarter() {
return quarterMile;
}
}





// private boolean checkForWinner(char mark){ }

public static void main(String[] args)
{ JFrame frame = new TestRace();
frame.setTitle("Lets Drag Race! Lets see what you got!");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true); }
} // end Race

Last edited by NaviLupets; 10-17-2014 at 02:09 PM. Reason: little update random cars all the time
NaviLupets is offline   Reply With Quote
Old 10-17-2014, 04:41 AM   #2
tk-421
Super Moderator
 
tk-421's Avatar
 
Drives: 5D-07-LB
Join Date: Jan 2007
Location: Dagobah
Posts: 4,263
Everything about this is awesome, except maybe the "Java" part.
Did you write this yourself?
__________________
tk-421 is offline   Reply With Quote
Old 10-17-2014, 11:31 AM   #3
NaviLupets
 
Drives: toyota yaris
Join Date: Mar 2012
Location: Illinois
Posts: 15
I wrote it myself in one day. Did you run it. What don't you like about the java ? My coding or dislike java in general? I have to do the same concept but in objective c .

Last edited by NaviLupets; 10-17-2014 at 02:10 PM.
NaviLupets is offline   Reply With Quote
Old 10-17-2014, 07:25 PM   #4
tk-421
Super Moderator
 
tk-421's Avatar
 
Drives: 5D-07-LB
Join Date: Jan 2007
Location: Dagobah
Posts: 4,263
I'll be sure to try it out soon...

You're code looks fine! I was referring to Java itself... Reminds me too much of my early years of coding, along with Visual Studio...

You may want to check out the Kivy framework, which is a modern (and dare I say fun) way of creating cross-platform openGL games/apps. You can even package native iOS and Android apps with it. Plus it's written in Python, which I enjoy using a lot.
__________________
tk-421 is offline   Reply With Quote
Old 11-25-2014, 03:34 PM   #5
vivalaflam
Enthusiast
 
vivalaflam's Avatar
 
Drives: 07 Yaris HB 1.3 (EU)
Join Date: Nov 2014
Location: Greece
Posts: 181
Can you compile an apk from it? So we can all try it?

Sent from my HTC Explorer A310e or my awesome Xperia Z1 C6903 using Tapatalk.
__________________
Cheers, George.
vivalaflam is offline   Reply With Quote
Old 12-02-2014, 02:20 PM   #6
ilikerice
 
ilikerice's Avatar
 
Drives: 2010 black yaris
Join Date: Oct 2010
Location: savannah, ga
Posts: 2,868
This entire thread is above my pay grade....
__________________
-Derrick-
"Racing is important to men who do it well. When you're racing... It's life. Anything that happens before or after, is just waiting."
ilikerice is offline   Reply With Quote
Old 12-11-2014, 02:56 AM   #7
vivalaflam
Enthusiast
 
vivalaflam's Avatar
 
Drives: 07 Yaris HB 1.3 (EU)
Join Date: Nov 2014
Location: Greece
Posts: 181
I dont have a pc. Most apks are based on java. Can you do it for me? Compile at least the java file? I think theres an android app to make apk from java afterwards.

Sent from my awesome Xperia Z1 C6903 using Tapatalk.
__________________
Cheers, George.
vivalaflam is offline   Reply With Quote
Old 02-10-2015, 11:23 AM   #8
ivanstepul
 
Drives: 08 hatchback
Join Date: Jun 2011
Location: chicago
Posts: 85
This is how it looks i just added all the listed cars with picture buttons, and the mighty yaris bottom right.
Attached Images
File Type: png screen shot game.PNG (406.3 KB, 36 views)
File Type: png Capture2.PNG (538.5 KB, 35 views)
ivanstepul is offline   Reply With Quote
Old 02-10-2015, 11:50 AM   #9
vivalaflam
Enthusiast
 
vivalaflam's Avatar
 
Drives: 07 Yaris HB 1.3 (EU)
Join Date: Nov 2014
Location: Greece
Posts: 181
Nice!

Sent from my awesome Xperia Z1 C6903 using Tapatalk.
__________________
Cheers, George.
vivalaflam is offline   Reply With Quote
Old 02-10-2015, 01:05 PM   #10
vaironl
 
vaironl's Avatar
 
Drives: 2010 Yaris 3 door, manual tran
Join Date: Jul 2013
Location: --
Posts: 208
I'm gonna give this a try ASAP... But I do have a question, why not use several classes to make the code cleaner? Sorry if you already mentioned this I'm reading over it extremely quickly.
vaironl is offline   Reply With Quote
Old 02-10-2015, 07:30 PM   #11
ivanstepul
 
Drives: 08 hatchback
Join Date: Jun 2011
Location: chicago
Posts: 85
I made this in one class so it would be easier to compile and run because you just copy and paste all of it in one shot. There are many defined classes but they are all in one file, I didn't separate, it look kinda messy but it works. I could of extended the car class and the different objects and images classes but I didn't really plan to well I just wrote code and tested it as I went on the fly and keepd adding additional features as I went. I did not have a clear plan ahead of me I just tried to make it cool.
ivanstepul is offline   Reply With Quote
Old 02-10-2015, 08:36 PM   #12
vaironl
 
vaironl's Avatar
 
Drives: 2010 Yaris 3 door, manual tran
Join Date: Jul 2013
Location: --
Posts: 208
Quote:
Originally Posted by ivanstepul View Post
I made this in one class so it would be easier to compile and run because you just copy and paste all of it in one shot. There are many defined classes but they are all in one file, I didn't separate, it look kinda messy but it works. I could of extended the car class and the different objects and images classes but I didn't really plan to well I just wrote code and tested it as I went on the fly and keepd adding additional features as I went. I did not have a clear plan ahead of me I just tried to make it cool.
I see now you made this in one day as well! It looks pretty cool!!!
vaironl is offline   Reply With Quote
Old 02-10-2015, 09:01 PM   #13
ivanstepul
 
Drives: 08 hatchback
Join Date: Jun 2011
Location: chicago
Posts: 85
Quote:
Originally Posted by vaironl View Post
I see now you made this in one day as well! It looks pretty cool!!!
Thanks. Did you run it, did it work?
ivanstepul is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NEWS: TOYOTA REVEALS ALL-NEW YARIS SEDAN AT 2006 LOS ANGELES AUTO SHOW VitzBoy General Yaris / Vitz Discussion 7 09-20-2023 07:50 AM
Yaris with racing stripes , spolier , front light modification .... ! Jack Yak Cosmetic Modifications (Exterior/Interior) 9 05-05-2012 11:47 PM
Vendo Espirales Racing Tanabe DF210 yaris urokai Central and South America 6 09-12-2009 09:12 AM
2007 Yaris Pricing Info ! YarisBueller New YARIS Purchase Forum 104 06-24-2009 04:54 PM
TS en 17 segundos (para los que estan interesados en Drag racing) Vic-2NZFE Central and South America 11 04-09-2007 06:19 PM


All times are GMT -4. The time now is 07:10 AM.




YarisWorld
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.