Java kodlarıyla zar atma oyunu
Merhaba Zar atma oyunun kodlarını size verecem şimdi,Aşağıdaki kodları yazdığınız zaman oyunumuz çalışacaktır, iyi çalışmalar
http://selahattindemirboga.blogspot.com/
package zaratmaörnegibarlı;
import java.util.*;
import javax.swing.*;
public class Zaratmaprogressbar extends javax.swing.JFrame {
public Zaratmaprogressbar() {
initComponents();
}
@SuppressWarnings("unchecked")
int o1z1 , o1z2 , o2z1 , o2z2 , a , b , e=25;
Random rast = new Random();
private void buton1ActionPerformed(java.awt.event.ActionEvent evt) {
o1z1 = rast.nextInt(10)+1;
o1z2 = rast.nextInt(10)+1;
o2z1 = rast.nextInt(10)+1;
o2z2 = rast.nextInt(10)+1;
oyu1z1.setText(""+o1z1);
oyu1z2.setText(""+o1z2);
oyu2z1.setText(""+o2z1);
oyu2z2.setText(""+o2z2);
a= o1z1 + o1z2;
b= o2z1 + o2z2;
if(a>b)
{
e = e + (a-b) ;
oyu1bar.setText("" + e);
oyu2bar.setText("" + (50-e));
bar1.setValue(e);
}
if(b>a)
{
e = e - (b-a) ;
oyu2bar.setText("" + (50-e));
oyu1bar.setText("" + e );
bar1.setValue(e);
}
if(bar1.getValue() == 0)
{
JOptionPane.showMessageDialog(this," !!! KAZANAN OYUNCU 2 " );
buton1.setEnabled(false);
buton2.setEnabled(true);
}
if(bar1.getValue() == 50)
{
JOptionPane.showMessageDialog(this," !!! KAZANAN OYUNCU 1 " );
buton1.setEnabled(false);
buton2.setEnabled(true);
}
}
private void buton2ActionPerformed(java.awt.event.ActionEvent evt) {
buton1.setEnabled(true);
buton2.setEnabled(false);
e = 25 ;
bar1.setValue(e);
oyu1z1.setText("" + 0);
oyu1z2.setText("" + 0);
oyu2z1.setText("" + 0);
oyu2z2.setText("" + 0);
oyu1bar.setText("" + 25);
oyu2bar.setText("" + 25);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Zaratmaprogressbar().setVisible(true);
}
});
}
Yorumlar