Hi,
Thanks for reply, this is my project i'm new to java using applet here are some information needed to my project.
1. This is online betting game.
2. This game have track race.
3. This game have an information regarding classes of rats,wieght,character,breeds of rats.etc.
4. This game need real time and not only one person can bet but multiple bet in one race.
I hope u give me some feedback about this project, this game is something similar to game of horse racing.
Thank u very much..
Well, for starters ... if more than one person is going to access this (presumably from differnet computers and locations), then you need a server that runs the actual races. You can do this with servlets. If you run the race inside the applet, each person gets a different race, assuming that the race's winner isn't the same every time for similar starting conditions.
You'll need to learn about writing applets and servvlets for starters - try visiting http://java.sun.com and looking in the left-hand column for tutorials.
How much time do you have to complete this project?
Here is a very simple horse racing game app that I did for someone in the new to forum a few months back. You will have to make a few simle horsey gif's to see it working - SMALL 15 x 15 pixels or so and make sure that the last 5 pixels on the left hand side are the same colour as the background of the applet. The applet here isn't finished, so it may provide ideas and give you a bit of scope to develop it further.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class HorseRacing extends Applet implements ActionListener{
Button startGameButton,race;
TextField betAmountBox;
Label winLab;
CheckboxGroup chooseHorse;
Checkbox chooseRed,chooseYellow,chooseBlue,chooseOrange;
Image title, redHorse, yellowHorse, blueHorse, orangeHorse;
int bank=1000,bet,oddR,oddY,oddB,oddO,xPos1,xPos2,xPos3,xPos4,fin;
public void init(){
this.setLayout(null);
setBackground(Color.gray);
title= getImage(getCodeBase(), "titlepicture.gif");
redHorse= getImage(getCodeBase(),"horsered.gif");
yellowHorse = getImage(getCodeBase(),"horseyellow.gif");
blueHorse= getImage(getCodeBase(),"horseblue.gif");
orangeHorse = getImage(getCodeBase(),"horseorange.gif");
startGameButton=new Button("Start Game");
startGameButton.setBounds(230,255,75,23);
startGameButton.addActionListener(this);
add(startGameButton);
race=new Button("Race!!");
race.addActionListener(this);
race.setBounds(450,220,60,23);
betAmountBox = new TextField("50",5);
betAmountBox.setBounds(125,218,60,25);
winLab = new Label("You have $"+bank+" in the bank");
winLab.setBounds(200,218,200,25);
chooseHorse=new CheckboxGroup();
chooseRed=new Checkbox("Red ", chooseHorse,false);
chooseRed.setBounds(20,183,70,25);
chooseRed.setBackground(Color.red);
chooseYellow=new Checkbox("Yellow ", chooseHorse,false);
chooseYellow.setBounds(90,183,70,25);
chooseYellow.setBackground(Color.yellow);
chooseBlue=new Checkbox("Blue ", chooseHorse,false);
chooseBlue.setBounds(160,183,70,25);
chooseBlue.setBackground(Color.blue);
chooseOrange=new Checkbox("Orange ", chooseHorse,true);
chooseOrange.setBounds(230,183,70,25);
chooseOrange.setBackground(Color.orange);
}
public void getOdds(){
oddR = (int)(Math.random()*3+1);
oddY = (int)(Math.random()*3+1);
oddB = (int)(Math.random()*3+1);
oddO = (int)(Math.random()*3+1);
}
public void actionPerformed(ActionEvent e){
Graphics g=getGraphics();
String arg = e.getActionCommand();
if(arg.equals("Start Game")){
remove(startGameButton);
add(race);
add(chooseRed);
add(chooseYellow);
add(betAmountBox);
add(winLab);
add(chooseBlue);
add(chooseOrange);
validate();
}
if(arg.equals("Race!!")) {
getOdds();
fin=0;
if(chooseRed.getState()==true)arg="red";
else if(chooseBlue.getState()==true) arg="blue";
else if(chooseOrange.getState()==true)arg="orange";
else arg="yellow";
bet=Integer.parseInt(betAmountBox.getText() );
if(bet < bank){
winLab.setText("You have bet $"+bet+" on the "+arg+" horse");
xPos1=xPos2=xPos3=xPos4=46;
startGame();
}
else winLab.setText("You don't have enough for that bet");
}
}
public void startGame(){
chooseRed.setEnabled(false);
chooseYellow.setEnabled(false);
chooseBlue.setEnabled(false);
chooseOrange.setEnabled(false);
betAmountBox.setEnabled(false);
int i=4, j=2;
Graphics g = getGraphics();
g.clearRect(50,10,475,300);
while((xPos1<434)||(xPos2<434)||(xPos3<434)||(xPos4<434)){
try{
Thread.sleep(5);
xPos1+=(int)(Math.random()*i+j);
xPos2+=(int)(Math.random()*i+j);
xPos3+=(int)(Math.random()*i+j);
xPos4+=(int)(Math.random()*i+j);
g.drawImage(redHorse,xPos1,15,31,22,this);
g.drawImage(yellowHorse, xPos2,45,31,22,this);
g.drawImage(blueHorse,xPos3,75,31,22,this);
g.drawImage(orangeHorse, xPos4,105,31,22,this);
if((xPos1<=335)||(xPos2<=335)||(xPos3<=335)||(xPos4<=335)){i=3;j=1;}
if((xPos1<=395)||(xPos2<=395)||(xPos3<=395)||(xPos4<=395)){i=2;j=0;}
if((xPos1>435)||(xPos2>435)||(xPos3>435)||(xPos4>435)){finalPos();fin++;}
}
catch(Exception e){}
}
}
public void finalPos(){
Graphics g = getGraphics();
g.drawImage(redHorse,xPos1,15,31,22,this);
g.drawImage(yellowHorse, xPos2,45,31,22,this);
g.drawImage(blueHorse,xPos3,75,31,22,this);
g.drawImage(orangeHorse, xPos4,105,31,22,this);
if(xPos1>435) g.drawString("The red horse wins", 300,35);
else if(xPos2>435) g.drawString("The yellow horse wins", 300,65);
else if(xPos3>435) g.drawString("The blue horse wins", 300,95);
else if(xPos4>435) g.drawString("The orange horse wins", 300,125);
else{}
if(fin==1){
if((chooseRed.getState()==true)&&(xPos1>435)) {
g.drawString("You win! $"+(bet*oddR),300,160);
bank+=(bet*oddR);
}
else if((chooseYellow.getState()==true)&&(xPos2>435)){
g.drawString("You win! $"+(bet*oddY),300,160);
bank+=(bet*oddY);
}
else if((chooseBlue.getState()==true)&&(xPos3>435)){
g.drawString("You win! $"+(bet*oddB),300,160);
bank+=(bet*oddB);
}
else if((chooseOrange.getState()==true)&&(xPos4>435)){
g.drawString("You win! $"+(bet*oddO),300,160);
bank+=(bet*oddO);
}
else {
g.drawString("Hah hah sucker! You lose",300,160);
bank-=bet;
}
}
winLab.setText("You have $"+bank+" in the bank");
chooseRed.setEnabled(true);
chooseYellow.setEnabled(true);
chooseBlue.setEnabled(true);
chooseOrange.setEnabled(true);
betAmountBox.setEnabled(true);
validate();
}
}