Game Random Kata Menggunakan Netbeans


sekarang R92M Share koding bikin geme,,, cihuiiiiiiiiiiiiiiiiiii Game…..

package uts;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.imageio.*;
import java.util.Random;
import javax.sound.sampled.*;

public class uts extends JPanel implements Runnable ,KeyListener{
private static final int PERIOD = 50;

Thread t;
int x = 200;
int y = 65;

boolean main=false;
Image bg;

String suarq=”src/uts/sic.wav”;
String suarq1=”src/uts/preview-1.wav”;
String suarak = “src/uts/Click.wav”;

String pertanyaan = “”;
String jawaban = “”;
int jawab = 0;

int benar = 0;
int score = 0;
int waktu = 20;

String pesan = “Nyawa : 3”;
int nyawa = 3;

//    String pertanyaan2 = “”;
//    String jawaban2 = “”;
//    int jawab2 = 0;
//
//    int benar2 = 0;
//    int score2 = 0;
//    int waktu2 = 20;
//
//    String pesan2 = “Nyawa : 3”;
//    int nyawa2 = 3;
//
//    String pertanyaan3 = “”;
//    String jawaban3 = “”;
//    int jawab3 = 0;
//
//    int benar3 = 0;
//    int score3 = 0;
//    int waktu3 = 20;
//
//    String pesan3 = “Nyawa : 3”;
//    int nyawa3 = 3;

AudioInputStream suara;
Clip klip;

void fl(){
pertanyaan = “”;
jawaban = “”;
jawab = 0;

benar = 0;
score = 0;
waktu = 20;

pesan = “Nyawa : 3”;
nyawa = 3;
}

//   void fl2(){
//    pertanyaan2 = “”;
//    jawaban2 = “”;
//    jawab2 = 0;
//
//    benar2 = 0;
//    score2 = 0;
//    waktu2 = 20;
//
//    pesan2 = “Nyawa : 3”;
//    nyawa2 = 3;
//   }
//   void fl3(){
//    pertanyaan3 = “”;
//    jawaban3 = “”;
//    jawab3 = 0;
//
//    benar3 = 0;
//    score3 = 0;
//    waktu3 = 20;
//
//    pesan3 = “Nyawa : 3”;
//    nyawa3 = 3;
//   }

void suara2(){
try {
suara = AudioSystem.getAudioInputStream(new File(suarak));
klip =AudioSystem.getClip();
klip.open(suara);
klip.loop(0);

} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
} catch (LineUnavailableException e) {}
}

void suara1(){
try {
suara = AudioSystem.getAudioInputStream(new File(suarq1));
klip =AudioSystem.getClip();
klip.open(suara);
klip.loop(0);

} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
} catch (LineUnavailableException e) {}
}

void suara(){
try {
suara = AudioSystem.getAudioInputStream(new File(suarq));
klip =AudioSystem.getClip();
klip.open(suara);
klip.loop(100);

} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
} catch (LineUnavailableException e) {}
}

public uts() {

this.setLayout(null);
try {
bg = ImageIO.read(getClass().getResource(“board.png”));
} catch (Exception e) {}

}

public void random() {
String angka[] = {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9” , “0”};
String operator[] = {“+”, “-“, “*”};
Random ra = new Random();
int indexo = ra.nextInt(operator.length);

int index = ra.nextInt(angka.length);
int index2 = ra.nextInt(angka.length);

int angka1 = Integer.parseInt(angka[index]);
int angka2 = Integer.parseInt(angka[index2]);

String opr = operator[indexo];

if (opr.equalsIgnoreCase(“+”)) {
pertanyaan = String.valueOf(angka1) + “+” + String.valueOf(angka2);
jawab = angka1 + angka2;
} else if (opr.equalsIgnoreCase(“-“)) {
pertanyaan = String.valueOf(angka1) + “-” + String.valueOf(angka2);
jawab = angka1 – angka2;
}else if (opr.equalsIgnoreCase(“*”)) {
pertanyaan = String.valueOf(angka1) + “*” + String.valueOf(angka2);
jawab = angka1 * angka2;
}
x = 200;
y=60;
jawaban = “”;
run();
}
//    public void random2() {
//        String angka[] = {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”};
//        String operator[] = {“+”, “-“, “*”};
//        Random ra = new Random();
//        int indexo = ra.nextInt(operator.length);
//
//        int index = ra.nextInt(angka.length);
//        int index2 = ra.nextInt(angka.length);
//
//        int angka1 = Integer.parseInt(angka[index]);
//        int angka2 = Integer.parseInt(angka[index2]);
//
//        String opr = operator[indexo];
//
//        if (opr.equalsIgnoreCase(“+”)) {
//            pertanyaan2 = String.valueOf(angka1) + “+” + String.valueOf(angka2);
//            jawab2 = angka1 + angka2;
//        } else if (opr.equalsIgnoreCase(“-“)) {
//            pertanyaan2 = String.valueOf(angka1) + “-” + String.valueOf(angka2);
//            jawab2 = angka1 – angka2;
//        }else if (opr.equalsIgnoreCase(“*”)) {
//            pertanyaan2 = String.valueOf(angka1) + “*” + String.valueOf(angka2);
//            jawab2 = angka1 * angka2;
//        }
//           x = 200;
//                y=60;
//                jawaban2 = “”;
//                run2();
//    }

//    public void random3() {
//        String angka[] = {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”};
//        String operator[] = {“+”, “-“, “*”, “/”};
//        Random ra = new Random();
//        int indexo = ra.nextInt(operator.length);
//
//        int index = ra.nextInt(angka.length);
//        int index2 = ra.nextInt(angka.length);
//
//        int angka1 = Integer.parseInt(angka[index]);
//        int angka2 = Integer.parseInt(angka[index2]);
//
//        String opr = operator[indexo];
//
//        if (opr.equalsIgnoreCase(“+”)) {
//            pertanyaan3 = String.valueOf(angka1) + “+” + String.valueOf(angka2);
//            jawab3 = angka1 + angka2;
//        } else if (opr.equalsIgnoreCase(“-“)) {
//            pertanyaan3 = String.valueOf(angka1) + “-” + String.valueOf(angka2);
//            jawab3 = angka1 – angka2;
//        }else if (opr.equalsIgnoreCase(“*”)) {
//            pertanyaan3 = String.valueOf(angka1) + “*” + String.valueOf(angka2);
//            jawab3 = angka1 * angka2;
//        }else if (opr.equalsIgnoreCase(“/”)) {
//            pertanyaan3 = String.valueOf(angka1) + “/” + String.valueOf(angka2);
//            jawab3 = angka1 / angka2;
//        }
//           x = 200;
//                y=60;
//                jawaban3 = “”;
//                run3();
//
//    }

public void keyTyped(KeyEvent e) {

}

public void keyPressed(KeyEvent e) {
suara2();
if (e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_1 ||
e.getKeyCode() == KeyEvent.VK_2 || e.getKeyCode() == KeyEvent.VK_3 ||
e.getKeyCode() == KeyEvent.VK_4 || e.getKeyCode() == KeyEvent.VK_5 ||
e.getKeyCode() == KeyEvent.VK_6 || e.getKeyCode() == KeyEvent.VK_7 ||
e.getKeyCode() == KeyEvent.VK_8 || e.getKeyCode() == KeyEvent.VK_9 ||
e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_MINUS ||
e.getKeyCode() == KeyEvent.VK_COMMA) {
jawaban += String.valueOf(e.getKeyChar());
}
//        }else if(e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_1 ||
//            e.getKeyCode() == KeyEvent.VK_2 || e.getKeyCode() == KeyEvent.VK_3 ||
//            e.getKeyCode() == KeyEvent.VK_4 || e.getKeyCode() == KeyEvent.VK_5 ||
//            e.getKeyCode() == KeyEvent.VK_6 || e.getKeyCode() == KeyEvent.VK_7 ||
//            e.getKeyCode() == KeyEvent.VK_8 || e.getKeyCode() == KeyEvent.VK_9 ||
//            e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_MINUS) {
//            jawaban2 += String.valueOf(e.getKeyChar());
//        }else if(e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_1 ||
//            e.getKeyCode() == KeyEvent.VK_2 || e.getKeyCode() == KeyEvent.VK_3 ||
//            e.getKeyCode() == KeyEvent.VK_4 || e.getKeyCode() == KeyEvent.VK_5 ||
//            e.getKeyCode() == KeyEvent.VK_6 || e.getKeyCode() == KeyEvent.VK_7 ||
//            e.getKeyCode() == KeyEvent.VK_8 || e.getKeyCode() == KeyEvent.VK_9 ||
//            e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_MINUS) {
//            jawaban3 += String.valueOf(e.getKeyChar());
//        }
if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
if (jawaban.length() > 0) {
jawaban = jawaban.substring(0, jawaban.length() – 1);
//            }else if (jawaban2.length() > 0) {
//                jawaban2 = jawaban2.substring(0, jawaban2.length() – 1);
//            }else if (jawaban3.length() > 0) {
//                jawaban3 = jawaban3.substring(0, jawaban3.length() – 1);
}

}

if(e.getKeyCode()==KeyEvent.VK_A){
if(main==false){
main=true;
suara();
t = new Thread(this);
random();
t.start();
}
//        }else if(e.getKeyCode()==KeyEvent.VK_B){
//            if(main==false){
//            main=true;
//            suara();
//        t = new Thread(this);
//        random2();
//        t.start();
//        }
//        }else if(e.getKeyCode()==KeyEvent.VK_C){
//            if(main==false){
//            main=true;
//            suara();
//        t = new Thread(this);
//        random3();
//        t.start();
//        }
}
if(e.getKeyCode()== KeyEvent.VK_ESCAPE){
System.exit(0);
}

if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (String.valueOf(jawab).equalsIgnoreCase(jawaban)) {
x = 200;
y=60;
jawaban = “”;
score += 10;
if (score == 50 || score == 100 || score == 150) {
waktu = waktu / 2;
}

random();

} else{
nyawa -=1;
if (nyawa == 3) {
pesan = “Nyawa : 3”;
random();
} else if (nyawa == 2) {
pesan = “Nyawa : 2”;
random();
} else if (nyawa == 1) {
pesan = “Nyawa : 1”;
System.out.println(nyawa);
random();
} else if (nyawa == 0) {
klip.close();
pesan = “Nyawa : 0”;
repaint();
t.suspend();
suara1();

Object[] options = {“MaiN LaGi”, “KeLuaR”};
int n = JOptionPane.showOptionDialog(this, “NiLai aNDa : “+score+”\n APaKaH aNDa Mau MaiN LaGi?”, “KoNFiRMaSi !”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,options, options[0]);
if(n==1){
System.exit(0);
}
fl();

t.resume();
random();

suara();
}

}
}

//        if (String.valueOf(jawab2).equalsIgnoreCase(jawaban2)) {
//                x = 200;
//                y=60;
//                jawaban2 = “”;
//                score2 += 10;
//                if (score2 == 50 || score2 == 100 || score2 == 150) {
//                    waktu2 = waktu2 / 2;
//                }
//
//                random2();
//
//
//            } else{
//                nyawa2 -=1;
//                if (nyawa2 == 3) {
//                    pesan2 = “Nyawa : 3”;
//                    random2();
//                } else if (nyawa2 == 2) {
//                    pesan2 = “Nyawa : 2”;
//                    random2();
//                } else if (nyawa2 == 1) {
//                    pesan2 = “Nyawa : 1”;
//                    System.out.println(nyawa2);
//                    random2();
//                } else if (nyawa2 == 0) {
//                    klip.close();
//                    pesan2 = “Nyawa : 0”;
//                    repaint();
//                   t.suspend();
//                    suara1();
//
//                 Object[] options = {“MaiN LaGi”, “KeLuaR”};
//                    int n = JOptionPane.showOptionDialog(this, “NiLai aNDa : “+score+”\n APaKaH aNDa Mau MaiN LaGi?”, “KoNFiRMaSi !”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,options, options[0]);
//                  if(n==1){
//                        System.exit(0);
//                       }
//    fl2();
//
//    t.resume();
//   random2();
//
//                  suara();
//                }
//
//            }
//       if (String.valueOf(jawab3).equalsIgnoreCase(jawaban3)) {
//                x = 200;
//                y=60;
//                jawaban3 = “”;
//                score3 += 10;
//                if (score3 == 50 || score3 == 100 || score3 == 150) {
//                    waktu3 = waktu3 / 2;
//                }
//
//                random3();
//
//
//            } else{
//                nyawa3 -=1;
//                if (nyawa3 == 3) {
//                    pesan3 = “Nyawa : 3”;
//                    random3();
//                } else if (nyawa3 == 2) {
//                    pesan3 = “Nyawa : 2”;
//                    random3();
//                } else if (nyawa3 == 1) {
//                    pesan = “Nyawa : 1”;
//                    System.out.println(nyawa);
//                    random3();
//                } else if (nyawa3 == 0) {
//                    klip.close();
//                    pesan3 = “Nyawa : 0”;
//                    repaint();
//                   t.suspend();
//                    suara1();
//
//                 Object[] options = {“MaiN LaGi”, “KeLuaR”};
//                    int n = JOptionPane.showOptionDialog(this, “NiLai aNDa : “+score+”\n APaKaH aNDa Mau MaiN LaGi?”, “KoNFiRMaSi !”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,options, options[0]);
//                  if(n==1){
//                        System.exit(0);
//                       }
//    fl3();
//
//    t.resume();
//   random3();
//
//                  suara();
//                }

//           }

}

public void keyReleased(KeyEvent e) {
}

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(bg, 0, 0, 984,589, this);

g.setFont(new Font(“Snap ITC”, Font.BOLD, 20));
g.drawString(String.valueOf(score), 810, 260);
g.drawString(pesan, 470, 310);
g.setFont(new Font(“Snap ITC”, Font.PLAIN, 20));
g.drawString(“Skor :”, 790, 220);
g.setFont(new Font(“Snap ITC”, Font.BOLD, 50));
g.drawString(“=”+jawaban, 120, 250);
g.setFont(new Font(“whiteboard modern”, Font.PLAIN, 50));
g.drawString(pertanyaan, x+10, 100);
//g.drawString(jawaban, 70, 525);
//        g.setFont(new Font(“Snap ITC”, Font.BOLD, 20));
//        g.drawString(String.valueOf(score2), 780, 480);
//        g.drawString(pesan2, 700, 440);
//        g.setFont(new Font(“Snap ITC”, Font.PLAIN, 20));
//        g.drawString(“Skor :”, 700, 480);
//        g.setFont(new Font(“Snap ITC”, Font.BOLD, 50));
//        g.drawString(“=”+jawaban2, 220, 445);
//        g.setFont(new Font(“whiteboard modern”, Font.PLAIN, 50));
//        g.drawString(pertanyaan2, x+10, 100);
//
//        g.setFont(new Font(“Snap ITC”, Font.BOLD, 20));
//        g.drawString(String.valueOf(score3), 780, 480);
//        g.drawString(pesan3, 700, 440);
//        g.setFont(new Font(“Snap ITC”, Font.PLAIN, 20));
//        g.drawString(“Skor :”, 700, 480);
//        g.setFont(new Font(“Snap ITC”, Font.BOLD, 50));
//        g.drawString(“=”+jawaban3, 220, 445);
//        g.setFont(new Font(“whiteboard modern”, Font.PLAIN, 50));
//        g.drawString(pertanyaan3, x+10, 100);

}

public static void main(String args[]){
uts a = new uts();
JFrame p = new JFrame();
p.getContentPane().add(a);
p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.setSize(984,589);
p.setUndecorated(true);
p.setLocationRelativeTo(null);
p.addKeyListener(a);
p.setVisible(true);
}

public void run() {
while (Thread.currentThread() == t) {
try {
x++;

if(x%2==0 && x<300){
y++;
}
if(x%2==0 && x>350){
y–;
}

Thread.sleep(waktu);

if(x==459){
nyawa -=1;
System.out.println(nyawa);
if (nyawa == 3) {
pesan = “Nyawa : 3”;
random();
} else if (nyawa == 2) {
pesan = “Nyawa : 2”;
random();
} else if (nyawa == 1) {
pesan = “Nyawa : 1”;
random();
} else if (nyawa == 0) {
klip.close();
pesan = “Nyawa : 0”;
repaint();
suara1();
Object[] options = {“Main Lagi”, “Keluar”};
int n = JOptionPane.showOptionDialog(this, ”    Kamu dapat nilai : “+score+”\n Apakah anda mau main lagi?”, “Pertanyaanq untukmu”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,options, options[0]);

if(n==1){
System.exit(0);
}
suara();
fl();
random();
}
}
} catch (Exception e) {}

repaint();
}
}

//    public void run2() {
//        while (Thread.currentThread() == t) {
//            try {
//                x++;
//
//                if(x%2==0 && x<300){
//                y++;
//                }
//                if(x%2==0 && x>350){
//                y–;
//                }
//
//                Thread.sleep(waktu);
//
//                if(x==459){
//              nyawa2 -=1;
//                System.out.println(nyawa2);
//                if (nyawa2 == 3) {
//                    pesan2 = “Nyawa : 3”;
//                    random2();
//                } else if (nyawa2 == 2) {
//                    pesan2 = “Nyawa : 2”;
//                    random2();
//                } else if (nyawa2 == 1) {
//                    pesan2 = “Nyawa : 1”;
//                    random2();
//                } else if (nyawa2 == 0) {
//                    klip.close();
//                    pesan2 = “Nyawa : 0”;
//                    repaint();
//                   suara1();
//                   Object[] options = {“Main Lagi”, “Keluar”};
//                   int n = JOptionPane.showOptionDialog(this, ”    Kamu dapat nilai : “+score+”\n Apakah anda mau main lagi?”, “Pertanyaanq untukmu”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,options, options[0]);
//
//                    if(n==1){
//                        System.exit(0);
//                       }
//                  suara();
//         fl2();
//         random2();
//                }
//                }
//            } catch (Exception e) {}
//
//            repaint();
//                   }
//        }
//
//    public void run3() {
//        while (Thread.currentThread() == t) {
//            try {
//                x++;
//
//                if(x%2==0 && x<300){
//                y++;
//                }
//                if(x%2==0 && x>350){
//                y–;
//                }
//
//                Thread.sleep(waktu3);
//
//                if(x==459){
//              nyawa3 -=1;
//                System.out.println(nyawa3);
//                if (nyawa3 == 3) {
//                    pesan3 = “Nyawa : 3”;
//                    random3();
//                } else if (nyawa3 == 2) {
//                    pesan3 = “Nyawa : 2”;
//                    random3();
//                } else if (nyawa3 == 1) {
//                    pesan3 = “Nyawa : 1”;
//                    random3();
//                } else if (nyawa3 == 0) {
//                    klip.close();
//                    pesan3 = “Nyawa : 0”;
//                    repaint();
//                   suara1();
//                   Object[] options = {“Main Lagi”, “Keluar”};
//                   int n = JOptionPane.showOptionDialog(this, ”    Kamu dapat nilai : “+score+”\n Apakah anda mau main lagi?”, “Pertanyaanq untukmu”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,options, options[0]);
//
//                    if(n==1){
//                        System.exit(0);
//                       }
//                  suara();
//         fl3();
//         random3();
//                }
//                }
//            } catch (Exception e) {}
//
//            repaint();
}

Dowload projeknya

Beli T-Shirt, Raglan dan Kids T-Shirt Original Ocean Seven

  1. T-Shirt, Raglan dan Kids T-Shirt Anime, Manga, Gamers dan Cartoon World (OceanSeven)
  2. T-Shirt, Raglan dan Kids T-Shirt Footbal Series (OceanSeven)
  3. T-Shirt, Raglan dan Kids T-Shirt Music Series (OceanSeven)
  4. T-Shirt, Raglan dan Kids T-Shirt OceanSeven – Custom dan Basic Tees (OceanSeven)
  5. T-Shirt, Raglan dan Kids T-Shirt OceanSeven -Kids Collections (OceanSeven)
  6. T-Shirt, Raglan dan Kids T-Shirt OceanSeven -Signature Serues (OceanSeven)
  7. T-Shirt, Raglan dan Kids T-Shirt  Social Media dan Photography (OceanSeven)
  8. T-Shirt, Raglan dan Kids T-Shirt Sport, Automotive dan Adventure (OceanSeven)
  9. T-Shirt, Raglan dan Kids T-Shirt Superheroes dan Movies (OceanSeven)

Satu pemikiran pada “Game Random Kata Menggunakan Netbeans

  1. selamat siang bang. kalau misalnya itu project di pindahhin ke jframe bisa gak si ?? saya mau buat tampilan awalnya gak bisa😥

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s