Langsung ke konten utama

Game Domino Java Netbeans 2 player

Game domino kali ini bisa diamankan berdua.

Berikut coding dan print Screen nya :
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Domino;
import java.util.*;
import javax.swing.JOptionPane;
class Variables {
   static Dice dice=new Dice (49);
   static tiles tile=new tiles();
   static String [] character=new String[3];
   static int charcount=0;
   static int player1[][]=new int[2][49];
   static int player2[][]=new int[2][49];
   static int dicevalue;
   static boolean check;
   static boolean checkroll;
   static boolean checkroll1;
   static boolean checkgame=true;
   static int highhead1=0;
   static int highhead2=0;
   static int hightail1=0;
   static int hightail2=0;
   static int interval[][]=new int[2][98];
   static int x2=49;
   static int y2=49;
   static int xx2=49;
   static int yy2=49;
   static int toplace;
   static int counter1;
   static int counterplayer1;
   static int counterplayer2;
   static int temp;
}
 class Dice {
    Random r =new Random();
    int sides;
 //constructor
    public Dice(int s){
       sides = s;
    }
 //roll method depending on sides up there
    public int roll(){
    return r.nextInt(sides);
    }
}
 class tiles {
  static int headcount=0;
  static int tailcount=0;
  static int a=0;
  static int b=0;
  int handler[][]=new int [2][49];
    public void dominotiles(){
        for(int x=0;x<49 o:p="" x="">
            for(int y=0; y<2 o:p="" y="">
                if(y==0){
                    if(headcount==7){
                        headcount=0;
                        a=a+1;
                    }
                    if(headcount<=6){
                    handler[y][x]=a;
                    headcount=headcount+1;
                    }
                }
                else {
                    if(tailcount==7){
                        tailcount=0;
                    }
                    if(tailcount<=6){
                     handler[y][x]=tailcount;
                    tailcount=tailcount+1;
                    }
                }
            }
        }
    }
}
public class  Mino extends Variables {
    public static void main(String[]args){
      tile.dominotiles();
      for(int x=0;x<49 o:p="" x="">
        for(int y=0; y<2 o:p="" y="">
                    player1[y][x]=7;
                    player2[y][x]=7;
        }
      }
     for(int x=0;x<98 o:p="" x="">
        for(int y=0;y<2 o:p="" y="">
                interval[y][x]=7;
        }
      newCharacter();
      newCharacter();
      JOptionPane.showMessageDialog(null,character[0]+" Di Kocok Secara Acak");
      for(int x=0;x<7 o:p="" x="">
          check=true;
        while(check){
           dicevalue=dice.roll();
            if(tile. handler[0][dicevalue]<7 amp="" dicevalue="" handler="" o:p="" tile.="">
                player1[0][dicevalue]=tile. handler[0][dicevalue];
                player1[1][dicevalue]=tile. handler[1][dicevalue];
                tile. handler[0][dicevalue]=7;
                tile. handler[1][dicevalue]=7;
                if(highhead1
                    highhead1=player1[0][dicevalue];
                    hightail1=player1[1][dicevalue];
                }
                check=false;
            }
        }
      }
            System.out.println(character[0]+"'s tiles");
            for(int x=0;x<49 o:p="" x="">
                    if(player1[0][x]<7 amp="" o:p="" player1="" x="">
                        System.out.print("("+player1[0][x]+","+player1[1][x]+")");
                        System.out.println();
                    }
            }
      JOptionPane.showMessageDialog(null,character[1]+" Di Kocok Secara Acak");
      for(int x=0;x<7 o:p="" x="">
          check=true;
        while(check){
           dicevalue=dice.roll();
            if(tile. handler[0][dicevalue]<7 amp="" dicevalue="" handler="" o:p="" tile.="">
                player2[0][dicevalue]=tile. handler[0][dicevalue];
                player2[1][dicevalue]=tile. handler[1][dicevalue];
                tile. handler[0][dicevalue]=7;
                tile. handler[1][dicevalue]=7;
                if(highhead2
                    highhead2=player2[0][dicevalue];
                    hightail2=player2[1][dicevalue];
                }
                check=false;
            }
        }
      }
            System.out.println(character[1]+"'s tiles");
            for(int x=0;x<49 o:p="" x="">
                    if(player2[0][x]<7 amp="" o:p="" player2="" x="">
                        System.out.print(player2[0][x]+"\t"+player2[1][x]);
                        System.out.println();
                    }
            }
      if(highhead1>highhead2){
          JOptionPane.showMessageDialog(null,character[0]+" first turn");
          game();
      }
      else if(highhead1
          JOptionPane.showMessageDialog(null,character[1]+" first turn play");
          character[2]=character[0];
          character[0]=character[1];
          character[1]=character[2];
          for(int x=0;x<49 o:p="" x="">
              temp=player1[0][x];
              player1[0][x]=player2[0][x];
              player2[0][x]=temp;
              temp=player1[1][x];
              player1[1][x]=player2[1][x];
              player2[1][x]=temp;
          }
          game();
      }
      else{
          if(hightail1>hightail2){
              JOptionPane.showMessageDialog(null,character[0]+" first turn");
              game();
          }
          else{
              JOptionPane.showMessageDialog(null,character[1]+" first turn play");
                character[2]=character[0];
                character[0]=character[1];
                character[1]=character[2];
                for(int x=0;x<49 o:p="" x="">
                    temp=player1[0][x];
                    player1[0][x]=player2[0][x];
                    player2[0][x]=temp;
                    temp=player1[1][x];
                    player1[1][x]=player2[1][x];
                    player2[1][x]=temp;
                }
              game();
          }
      }
            
      
    }
    public static void newCharacter(){
        if (charcount<2 o:p="">
            character[charcount]=JOptionPane.showInputDialog("player:");
            charcount+=1;
        }
    }
    public static void printgamecycle(){
        System.out.println("Aksi Permainan");
        for(int x=0;x<98 o:p="" x="">
                if(interval[0][x]<7 amp="" interval="" o:p="" x="">
                System.out.println(interval[0][x]+"\t"+interval[1][x]);
        }
    }
    
    public static void game(){
        check=true;
        while(check){
            while(check){
                try{
                highhead1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter Masukan angka kartu domino anda :"));
                hightail1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter Masukan angka kartu domino anda :"));
                check=false;
                }
                catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null,"PASS","ERROR",JOptionPane.ERROR_MESSAGE);
                }
            }
            
            if(highhead1<=6&&highhead1>=0&&hightail1<=6&&hightail1>=0){
                   for(int x=0;x<49 o:p="" x="">
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         interval[0][x2]=player1[0][x];
                         interval[1][y2]=player1[1][x];
                         player1[0][x]=7;
                         player1[1][x]=7;
                      }
                  }
                check=false;
            printgamecycle();
            }
            
      }
        
        
while(checkgame){
    counter1=0;
    for(int x=0;x<49 o:p="" x="">
        if(tile. handler[0][x]==7&&tile. handler[1][x]==7)
            counter1+=1;
    }
    if(counter1==49){
        for(int x=0;x<49 o:p="" x="">
            if(player1[0][x]<7 amp="" o:p="" player1="" x="">
                counterplayer1+=1;
            if(player2[0][x]<7 amp="" o:p="" player2="" x="">
                counterplayer2+=1;
        }
        if(counterplayer1
            JOptionPane.showMessageDialog(null,character[0]+"Wins");
            checkgame=false;
            check=false;
            checkroll=false;
            checkroll1=false;
        }
        else if(counterplayer1>counterplayer2){
            JOptionPane.showMessageDialog(null,character[1]+"Wins");
            checkgame=false;
            check=false;
            checkroll=false;
            checkroll1=false;
        }
        else if(counterplayer1==counterplayer2){
            JOptionPane.showMessageDialog(null,"DRAW!!!");
            checkgame=false;
            check=false;
            checkroll=false;
            checkroll1=false;
        }
    }
        while(true){
            check=false;
            checkroll1=true;
            while(checkroll1){
                checkroll=true;
                for(int x=0;x<49 o:p="" x="">
                    if(highhead1==player2[0][x]||highhead1==player2[1][x]||hightail1==player2[0][x]||hightail1==player2[1][x]){
                        check=true;
                        checkroll=false;
                        checkroll1=false;
                    }
                    else if(counter1==49){
                        check=false;
                        checkroll=false;
                        checkroll1=false;
                    }
                    
                } 
                while(checkroll){
                    dicevalue=dice.roll();
                        if(tile. handler[0][dicevalue]<7 amp="" dicevalue="" handler="" o:p="" tile.="">
                            JOptionPane.showMessageDialog(null,character[1]+" chose to pass, required to get new domino from boneyard");
                            player2[0][dicevalue]=tile. handler[0][dicevalue];
                            player2[1][dicevalue]=tile. handler[1][dicevalue];
                            tile. handler[0][dicevalue]=7;
                            tile. handler[1][dicevalue]=7;
                            highhead2=highhead1;
                            hightail2=hightail1;
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                        counter1=0;
                        for(int x=0;x<49 o:p="" x="">
                        if(tile. handler[0][x]==7&&tile. handler[1][x]==7)
                        counter1+=1;
                        }
                        if(counter1==49){
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                 }    
            }
            System.out.println(character[1]+"'s tiles");
            for(int x=0;x<49 o:p="" x="">
                if(player2[0][x]<7 amp="" o:p="" player2="" x="">
                System.out.println("("+player2[0][x]+","+player2[1][x]+")");
            }
            while(check){
                while(check){
                try{
                highhead2=Integer.parseInt(JOptionPane.showInputDialog(character[1]+"'s turn\nEnter a head tile number to use:"));
                hightail2=Integer.parseInt(JOptionPane.showInputDialog(character[1]+"'s turn\nEnter a tail tile number to use:"));
                    while(check){
                    toplace=Integer.parseInt(JOptionPane.showInputDialog("Where to place the tiles:\n[0]head portion\n[1]tail portion"));
                    if(toplace==0||toplace==1){
                        check=false;
                    }
                    else
                    JOptionPane.showMessageDialog(null,"WRONG INPUT","Warning",JOptionPane.WARNING_MESSAGE);
                    }
                check=false;
                }
                catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null,"WRONG INPUT","ERROR",JOptionPane.ERROR_MESSAGE);
                }
                }
                check=true;
            if(toplace==0){ 
                if(highhead2==highhead1){
                   for(int x=0;x<49 o:p="" x="">
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player2[1][x];
                         interval[1][y2]=player2[0][x];
                         highhead2=player2[1][x];
                         hightail2=hightail1;
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                         
                      }
                  }
                }
                else if(hightail2==highhead1){
                     for(int x=0;x<49 o:p="" x="">
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player2[0][x];
                         interval[1][y2]=player2[1][x];
                         hightail2=hightail1;
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            
            else if(toplace==1){
                if(highhead2==hightail1){
                   for(int x=0;x<49 o:p="" x="">
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player2[0][x];
                         interval[1][yy2]=player2[1][x];
                         highhead2=highhead1;
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                      }
                  }
                }
                else if(hightail2==hightail1){
                    for(int x=0;x<49 o:p="" x="">
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player2[1][x];
                        interval[1][yy2]=player2[0][x];
                         highhead2=highhead1;
                         hightail2=player2[0][x];
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            }
            printgamecycle();
                counterplayer2=0;
                for(int x=0;x<49 o:p="" x="">
                if(player2[0][x]<7 amp="" o:p="" player2="" x="">
                counterplayer2+=1;
                }
                if(counterplayer2==0){
                JOptionPane.showMessageDialog(null,character[1]+" Wins!!!");
                checkgame=false;
                check=false;
                checkroll=false;
                checkroll1=false;
                }
                else{
                check=false;
                checkroll1=true;
                }
        break;
    }
                
         
        while(true){ 
            while(checkroll1){
                checkroll=true;
                for(int x=0;x<49 o:p="" x="">
                    if(highhead2==player1[0][x]||highhead2==player1[1][x]||hightail2==player1[0][x]||hightail2==player1[1][x]){
                        check=true;
                        checkroll=false;
                        checkroll1=false;
                    }
                    else if(counter1==49){
                        check=false;
                        checkroll=false;
                        checkroll1=false;
                    }
                }
                while(checkroll){
                    dicevalue=dice.roll();
                        if(tile. handler[0][dicevalue]<7 amp="" dicevalue="" handler="" o:p="" tile.="">
                            JOptionPane.showMessageDialog(null,character[0]+" chose to pass, required to get new domino from boneyard");
                            player1[0][dicevalue]=tile. handler[0][dicevalue];
                            player1[1][dicevalue]=tile. handler[1][dicevalue];
                            tile. handler[0][dicevalue]=7;
                            tile. handler[1][dicevalue]=7;
                            highhead1=highhead2;
                            hightail1=hightail2;
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                        counter1=0;
                        for(int x=0;x<49 o:p="" x="">
                        if(tile. handler[0][x]==7&&tile. handler[1][x]==7)
                        counter1+=1;
                        }
                        if(counter1==49){
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                }
            }
            System.out.println(character[0]+"'s tiles");
            for(int x=0;x<49 o:p="" x="">
                if(player1[0][x]<7 amp="" o:p="" player1="" x="">
                System.out.println(player1[0][x]+"\t"+player1[1][x]);
            }
            while(check){
                while(check){
                try{
                highhead1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter a your head tile number to use:"));
                hightail1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter a your tail tile number to use:"));
                while(check){
                    toplace=Integer.parseInt(JOptionPane.showInputDialog("Where to place the tiles:\n[0]head portion\n[1]tail portion"));
                    if(toplace==0||toplace==1){
                    check=false;
                    }
                    else
                    JOptionPane.showMessageDialog(null,"WRONG INPUT","Warning",JOptionPane.WARNING_MESSAGE);
                    }
                check=false;
                }
                catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null,"WRONG INPUT","ERROR",JOptionPane.ERROR_MESSAGE);
                }
                }
                check=true;
            if(toplace==0){ 
                if(highhead1==highhead2){
                   for(int x=0;x<49 o:p="" x="">
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player1[1][x];
                         interval[1][y2]=player1[0][x];
                         highhead1=player1[1][x];
                         hightail1=hightail2;
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                          
                      }
                  }
                }
                else if(hightail1==highhead2){
                     for(int x=0;x<49 o:p="" x="">
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player1[0][x];
                         interval[1][y2]=player1[1][x];
                         hightail1=hightail2;
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            
            else if(toplace==1){
                if(highhead1==hightail2){
                   for(int x=0;x<49 o:p="" x="">
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                        xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player1[0][x];
                         interval[1][yy2]=player1[1][x];
                         highhead1=highhead2;
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                      }
                  }
                }
                else if(hightail1==hightail2){
                    for(int x=0;x<49 o:p="" x="">
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player1[1][x];
                         interval[1][yy2]=player1[0][x];
                         highhead1=highhead2;
                         hightail1=player1[0][x];
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            }
            printgamecycle();
                counterplayer1=0;
                for(int x=0;x<49 o:p="" x="">
                if(player1[0][x]<7 amp="" o:p="" player1="" x="">
                counterplayer1+=1;
                }
                if(counterplayer1==0){
                JOptionPane.showMessageDialog(null,character[0]+" KAMU MENANG!!!");
                checkgame=false;
                check=false;
                checkroll=false;
                checkroll1=false;
                }
        break;
    }
}
  
}

}
 ===============================================================
Screenshot :





Komentar

Postingan populer dari blog ini

Pro Evolution Soccer 2011-RELOADED [ Mediafire ]

Release Group: RELOADED Release Name: Pro.Evolution.Soccer.2011-RELOADED Release Date: 01-10-2010 Retail Date: 08-10-2010 Filename: rld-pe11 Source: DVD 9 Size: 5.19 GB Genre: Sports Critics: N/A Published by: Konami Developed by: Winning Eleven Productions

Sistem Terdistribusi

sistem terdistribusi adalah sebuah sistem dimana komponen software atau hardware-nya terletak di dalam jaringan komputer dan saling berkomunikasi menggunakan message passing (Message passing adalah sebuah teknik untuk melakukan sinkronisasi dan komunikasi antara proses-proses yang saling berinteraksi). Ada juga yang mengatakan Sistem Terdistribusi adalah sebuah sistem yang terdiri dari beberapa komponen yang terdapat di dalam sebuah jaringan komputer. Komponen-komponen tersebut saling berinteraksi dan berkomunikasi hanya dengan melalui pengiriman pesan. Dengan menjalankan sistem terdistribusi, komputer dapat melakukan :  Koordinasi Aktifitas  Berbagi sumber daya : hardware, software dan data Dengan definisi tersebut diatas maka internet sesungguhnya bukanlah suatu sistem terdistribusi, melainkan infrastruktur dimana sistem terdistribusi dapat di aplikasikan pada jaringan tersebut. Contoh Sistem Terdistribusi 1. Internet: Jaringan komputer dan aplika

Tips untuk menghindari virus dari Flash Drive

Sering banget kan kita mendapat virus dari flashdisk atau removable disk lain ke dalam komputer kita. Virus-virus ini memang menyebalkan, seperti tamu yang ga diundang aja. Tiba-tiba nyelonong masuk ke dalam flashdisk, lalu menginfeksi komputer kita. Logikanya virus akan berjalan jika kita mengeksekusinya. Namun biasanya kita tidak pernah merasa mengeksekusi file yang mengandung virus, lalu kapan virus tersebut kita eksekusi?