#WW

#WW
Home » » Program Counter Strike Java

Program Counter Strike Java

Written By Unknown on Friday, 21 March 2014 | 01:53

Program Counter Strike Java

import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BoomDefusal {
    public BoomDefusal() {
    }

    public static void main(String[] args) throws IOException {
        System.out.println("PERATURAN MAIN");
        System.out.println("1. Ada 2 BOM yang harus di defuse. Defuse bom pertama dulu sebelum bom kedua defuse");
        System.out.println("2. Masukan angka 0-9 untuk defuse BOM. <Hati2 angka acak>");
        System.out.println("3. Hitungan BOM akan terus berjalan. Jika Anda salah penginputan");
        System.out.println("4. Selamat Bermain B-)");
        System.out.println("INGAT Anda harus cepat waktunya hanya 15 detik!!");
        System.out.println("TEKAN ENTER UNTUK MEMULAI!");
        BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
        String s = new String(b.readLine());
        System.out.println("Kedua BOM berjalan bersamaan.");
        for(int i=5; i>0; i--){
            System.out.println("Pesan ini akan hancur dalam "+i+" detik");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(BoomDefusal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        int x = new Random().nextInt(10);
        int y = new Random().nextInt(10);
        Bom b1 = new Bom("1", x);
        b1.setDetik(15);
        Bom b2 = new Bom("2", y);
        b2.setDetik(15);
        BomSiteA a = new BomSiteA(b1, b2);
        a.start();
        if(a.isPlaying()){
            try {
                b1.Defuse();
                b2.Defuse();
            } catch (IOException ex) {
               
            }
        }
        if(b2.isDefuse()){
           System.out.println("MENANG");
        }
    }
}





import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Bom {
    private String nama;
    private int defusalTool;
    private int detik;
    private boolean ijinDefuse=true;
    private boolean defuse=false;

    public Bom(String nama, int defusalTool) {
        this.nama=nama;
        this.defusalTool=defusalTool;
    }
   
    public void setIjinDefuse(boolean ijinDefuse) {
        this.ijinDefuse=ijinDefuse;
    }

    public boolean isIjinDefuse() {
        return ijinDefuse;
    }
   
    public void setDefuse(boolean defuse) {
        this.defuse=defuse;
    }

    public boolean isDefuse() {
        return defuse;
    }

    public void setDetik(int detik) {
        this.detik=detik;
    }

    public int getDetik(){
        return this.detik;
    }

    public int getDefusalTool() {
        return this.defusalTool;
    }

    public String getNama() {
        return this.nama;
    }

    public synchronized void display() {
            if(!this.isIjinDefuse()){

            }
            else{
                if(!this.isDefuse()){
                    System.out.println("BOM "+nama+" akan meladak dalam "+this.detik+" detik");
                }
                else{
                    System.out.println("BOM "+this.nama+" berhasil dijinakan");
                }
            }
           
      
       
    }

    public void Defuse() throws IOException{
        BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
        while((!isDefuse())&&(isIjinDefuse())){
        String a = new String(b.readLine());
        int x = Integer.parseInt(a);  
        if(this.defusalTool!=x){
            System.out.println("Angka anda tidak cocok");
        }
        else if(this.defusalTool==x){
            System.out.println("Angka anda Benar");
            this.defuse=true;
            this.ijinDefuse=false;
        }
        }
    }
}

0 komentar:

Post a Comment