Penulisan 3

Nama         : Ery Rivaldi
NPM          : 53414655
Kelas          : 3IA22
Tugas ke-  : 1

1.      Design Skenario
Skenario adalah urutan cerita yang disusun oleh seseorang agar suatu peristiwa terjadi sesuai dengan yang diinginkan. Kalau dasar untuk pembuatan film adalah skenario, maka dasar untuk membuat game adalah design document atau lebih mudahnya disebut skenario game. Skenario game adalah langkah awal dalam membuat sebuah game, dengan skenario game dapat mempermudah kita menyelesaikan game yang akan kita buat.
Design Skenario untuk game Tic Tac Toe bisa dilihat pada tampilan dibawah ini yang terdiri dari tampilan pemain ketika menang, tampilan ketika pemain kalah, tampilan ketika permainan seri, tampilan rule permainan dan tampilan ketika ingin keluar dari program.

·        







 Tampilan pemain menang





·         Tampilan pemain kalah







·             Tampilan pemain seri 



·         Tampilan aturan game




·         Tampilan keluar game



2.      Skrip game Tic Tac Toe
Dalam pemrograman komputer, naskah adalah sebuah program atau urutan instruksi yang ditafsirkan atau dilakukan dengan program lain daripada oleh komputer prossesor. Skrip (script) adalah semacam bahasa pemrograman dalam tingkat kesulitan yang lebih rendah, tanpa aplikasi hasil kompilasi interpreter; skrip biasanya disisipkan ke dalam bahasa pemrograman yang lebih kompleks dan hasil skrip digunakan oleh bahasa pemrograman yang lebih kompleks itu. 
Skrip untuk game Tic Tac Toe sendiri menggunakan Bahasa pemrograman Java, berikut adalah skrip dari game Tic Tac Toe:

package mytictac;

import java.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MT1 extends javax.swing.JFrame {
    MenuBar mb1;
    Menu m1;
 
  MenuItem rules, gamebaru, about, backmenu;
  static String Status[] =new String[10];
  static String thewinner="";
  boolean available=false;
  String sign="X";
  static JButton button[];
  ImageIcon ic;
       
    public MT1() {
       // initComponents();
        super("Tic Tac Toe Sulit");

JPanel pan=new JPanel();
pan.setLayout(new BorderLayout());
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(3,3));
p1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
//*************************** Untuk menu bar***********************************
       mb1=new MenuBar();
       m1=new Menu();
                gamebaru = new MenuItem("NEW GAME");
       rules=new MenuItem("ATURAN GAME");
                about = new MenuItem("ABOUT");
                backmenu = new MenuItem("BACK TO MENU");
       m1.setLabel("GAME");
      

gamebaru.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){               
    newgame();
}});

backmenu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){               
    awal a = new awal();
    a.setVisible(true);
    dispose();
}});

rules.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
JOptionPane.showMessageDialog( MT1.this,
         ".:: Aturan game Tic Tac Toe ::.\n"
         + "    1. Pemain dalam permainan ini dibatasi untuk satu lawan satu,\n"
         + "        dilakukan bergiliran antara pemain pertama (manusia) dan pemain kedua (komputer).\n"
         + "    2. Pemain manusia (player) akan dihalangi oleh komputer\n"
         + "        untuk mencapai tujuan (goal) karena komputer telah diberi kecerdasan buatan\n"
         + "        sehingga komputer juga berusaha untuk menjadi pemenang.\n"
         + "    3. Untuk memberikan langkah, setiap pemain harus mengisi bidak\n"
         + "        dengan simbol pemain masing-masing, dengan X atau O.\n"
         + "    4. Setiap pemain hanya mempunyai satu kali kesempatan \n"
         + "        pada setiap giliran.\n"
         + "    5. Bidak yang sudah terisi tidak bisa ditimpa oleh langkah berikutnya.\n"
         + "    6. Langkah yang sudah diambil tidak dapat dibatalkan atau diganti dengan \n"
         + "        langkah yang lain",
"ATURAN GAME!!", JOptionPane.INFORMATION_MESSAGE );
}});

about.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
JOptionPane.showMessageDialog( MT1.this,
 ".:: Project PKB tentang game Tic Tac Toe ::.\n"
         + "    Team Developer :\n"
         + "    1. Adinda Febriyanto    (50414264)\n"
         + "    2. Chyntia Dwinovita     (52414396)\n"
         + "    3. Dimas Herianto         (53414099)\n"
         + "    4. Ery Rivaldi                  (53414655)",
"About Project", JOptionPane.INFORMATION_MESSAGE );
}});

m1.add(gamebaru);
m1.add(rules);
m1.add(about);
m1.add(backmenu);
mb1.add(m1);
setMenuBar(mb1);

//*********************************************windowListener*************************************************************      
addWindowListener(new WindowAdapter(){
  public void windowCloseing(WindowEvent evt){
       exitt();
       }
  });
//****************************************Defining the buttons**************************************************************
button=new JButton[10];
for(int i=1;i<10;i++){
  button[i]=new JButton();
  button[i].setFocusPainted(false);
  button[i].setActionCommand(Integer.toString(i));
  button[i].setFont(new Font("Arial",Font.BOLD,50));
  button[i].setToolTipText("click the button");
  button[ i ].addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e ) {
                    buttonAction( e.getActionCommand() ); }
            } );
  p1.add(button[i]);
  }
//****************************************************additional button**************************************************************
  JPanel pi=new JPanel();
  pi.setLayout(new GridLayout(1,3));
       add(p1,"Center");
       add(pi,"South");
  setSize(500,400);
  setLocation(450,150);
  setVisible(true);
  setResizable(false);
  newgame();
  }

//***************************************** Definining the button action listener***************************************************************
public void buttonAction(String btn){
int index=Integer.parseInt(btn);
if(button[index].getText()==""){
  button[index].setText(sign);
  button[index].setForeground(Color.red);
  //button[index].setBackground(Color.gray);
  Status[index]=sign;
 
       
  GameStatusCheck();
  nextMove();
 
  }
  else
       JOptionPane.showMessageDialog(MT1.this,"Ooww bidak sudah terisi,\n"
                        + "    pilih bidak yang belum terisi.","SORRY!!!!!",JOptionPane.ERROR_MESSAGE);
      
}
public void nextMove() {

           
                  int win=0;
//************************************First try to attack*************************************************************************************      
                  if ((( Status[ 1 ]=="O") && (Status [ 2 ] =="O"))&&(Status[3]==""))
       win=3;
       else if(((Status[ 2] =="O") &&( Status[ 3 ] =="O"))&&(Status[1]=="") )
       win=1;
            else if(( ( Status[ 1 ] =="O") &&(Status [ 3 ]=="O" ))&&(Status[2]==""))
            win=2;
  else if( (( Status[ 4] =="O")&&( Status [ 5 ]=="O" ))&&(Status[6]==""))
       win=6;
            else if (( ( Status[ 5 ] =="O")&&( Status [ 6 ]=="O")) &&(Status[4]==""))
            win=4;
                 else if( (( Status[ 4] =="O")&& (Status [ 6 ]=="O" ))&&(Status[5]==""))
                 win=5;
       else if( (( Status[ 7] =="O")&&(Status [ 8]=="O" ))&&(Status[9]==""))
            win=9;
                 else if( (( Status[ 7] =="O")&& (Status [ 9]=="O" ))&&(Status[8]==""))
                      win=8;
                 else if( (( Status[ 8] =="O")&&( Status [ 9 ]=="O" ))&&(Status[7]==""))
                      win=7;
       else if(( ( Status[ 1] =="O")&&( Status [ 4] =="O"))&&(Status[7]==""))
            win=7;
            else if(( ( Status[ 1] =="O")&&( Status [ 7 ]=="O" ))&&(Status[4]==""))
             win=4;
                 else if(( ( Status[ 4] =="O")&&( Status [ 7 ]=="O" ))&&(Status[1]==""))
                                         win=1;
       else if( (( Status[ 2] =="O")&&( Status [ 5]=="O") )&&(Status[8]==""))
            win=8;
            else if( (( Status[ 2] =="O")&&( Status [ 8 ]=="O" ))&&(Status[5]==""))
             win=5;
                 else if( (( Status[ 5] =="O")&&( Status [ 8 ]=="O" ))&&(Status[2]==""))
                                         win=2;
       else if( (( Status[ 3] =="O")&&( Status [ 6]=="O" ))&&(Status[9]==""))
            win=9;
            else if( (( Status[ 3] =="O")&&( Status [ 9 ]=="O") )&&(Status[6]==""))
             win=6;
                 else if( (( Status[ 6] =="O")&&( Status [ 9]=="O") )&&(Status[3]==""))
                                         win=3;
       else if( (( Status[ 1] =="O")&&( Status [ 5]=="O" ))&&(Status[9]==""))
            win=9;
            else if( (( Status[ 1] =="O")&& ( Status [ 9 ]=="O" ))&&(Status[5]==""))
             win=5;
                 else if(( ( Status[ 5] =="O")&&( Status [ 9 ]=="O") )&&(Status[1]==""))
                                         win=1;
       else if( (( Status[ 3] =="O")&& (Status [ 5]=="O" ))&&(Status[7]==""))
            win=7;
            else if( (( Status[ 3] =="O")&&( Status [ 7 ]=="O") )&&(Status[5]==""))
             win=5;
                 else if(( ( Status[ 5] =="O")&&( Status [ 7 ]=="O" ))&&(Status[3]==""))
                 win=3;
       /**********Defencinve Move********************                        
else
  if (( Status[ 1 ]=="X") && (Status [ 2 ] =="X")&&(Status[3]==""))
       win=3;
       else if((Status[ 2] =="X") &&( Status[ 3 ] =="X")&&(Status[1]=="") )
       win=1;
            else if(( ( Status[ 1 ] =="X") &&(Status [ 3 ]=="X" ))&&(Status[2]==""))
            win=2;
  else if( ( Status[ 4] =="X")&&( Status [ 5 ]=="X" )&&(Status[6]==""))
       win=6;
            else if ( ( Status[ 5 ] =="X")&&( Status [ 6 ]=="X") &&(Status[4]==""))
            win=4;
                 else if( ( Status[ 4] =="X")&& (Status [ 6 ]=="X" )&&(Status[5]==""))
                 win=5;
       else if( ( Status[ 7] =="X")&&(Status [ 8]=="X" )&&(Status[9]==""))
            win=9;
                 else if( ( Status[ 7] =="X")&& (Status [ 9]=="X" )&&(Status[8]==""))
                      win=8;
                 else if( ( Status[ 8] =="X")&&( Status [ 9 ]=="X" )&&(Status[7]==""))
                      win=7;
       else if( ( Status[ 1] =="X")&&( Status [ 4] =="X")&&(Status[7]==""))
            win=7;
            else if( ( Status[ 1] =="X")&&( Status [ 7 ]=="X" )&&(Status[4]==""))
             win=4;
                 else if( ( Status[ 4] =="X")&&( Status [ 7 ]=="X" )&&(Status[1]==""))
                                         win=1;
       else if( ( Status[ 2] =="X")&&( Status [ 5]=="X" )&&(Status[8]==""))
            win=8;
            else if( ( Status[ 2] =="X")&&( Status [ 8 ]=="X" )&&(Status[5]==""))
             win=5;
                 else if( ( Status[ 5] =="X")&&( Status [ 8]=="X" )&&(Status[2]==""))
                                         win=2;
       else if( ( Status[ 3] =="X")&&( Status [ 6]=="X" )&&(Status[9]==""))
            win=9;
            else if( ( Status[ 3] =="X")&&( Status [ 9 ]=="X" )&&(Status[6]==""))
             win=6;
                 else if( ( Status[ 6] =="X")&&( Status [ 9]=="X" )&&(Status[3]==""))
                                         win=3;
       else if( (( Status[ 1] =="X")&&( Status [ 5]=="X" ))&&(Status[9]==""))
            win=9;
            else if( (( Status[ 1] =="X")&& ( Status [ 9 ]=="X" ))&&(Status[5]==""))
             win=5;
                 else if( (( Status[ 5] =="X")&&( Status [ 9 ]=="X" ))&&(Status[1]==""))
                                         win=1;
       else if( (( Status[ 5] =="X")&& (Status [ 9]=="X" ))&&(Status[1]==""))
            win=1;
            else if(( ( Status[ 1] =="X")&&( Status [ 9 ]=="X" ))&&(Status[5]==""))
             win=5;
                 else if( (( Status[ 1] =="X")&&( Status [ 5 ]=="X" ))&&(Status[9]==""))
                 win=9;
                 // ************************RANDOM MOVE AT LAST*******************************************
           
                
                 else if((Status[1]=="")&&(Status[2]=="")&&(Status[3]=="")&&(Status[4]=="")&&(Status[5]=="")&&(Status[6]=="")&&(Status[7]=="")
                                        &&(Status[8]=="")&&(Status[9]==""))
                 win=7;
                
                 else if(Status[ 5] =="")
                 win=5;
                 else if(Status[5]=="X")
                 win=3;
                
                
            else if((Status[1]=="X")&&(Status[9]=="X")||(Status[3]=="X")&&(Status[7]=="X"))
            win=2;   
                 else
            win=randomMove()
            //System.out.println(win);
                     
       if ( button[ win].getText() != "" )
                nextMove();
                     
        if ( button[win].getText() == "" ){
       button[win].setText( "O" );
       button[win].setForeground( Color.blue);
            //button[win].setBackground(Color.yellow);
           
            Status[win] = "O"; 
           
       GameStatusCheck();
       }
    }
  //*********************************************************Random move*****************************************************
public int randomMove() {
        int randomValue = 0;
        if ( available ) {           
            randomValue = ( 1+ ( int ) ( Math.random() * 9 ) );   
        }
        return randomValue;
    }
      
  //***************************************NEW GAME************************** 
public static void newgame(){
for(int j=1;j<10;j++){
button[j].setText("");
//Color c=new Color(0,100,50);
button[j].setForeground(Color.cyan);
//button[j].setBackground(Color.cyan);
Status[j]="";
thewinner="";
}
}
//***********************************************************check the game status**********************************************************
private void GameStatusCheck(){
//fo the top horizontal line
if ( ( Status[ 1 ] != "" ) && ( Status[ 1 ] == Status [ 2 ] && Status[ 2 ] == Status[ 3 ] ) )
       {
            thewinner = Status[ 1 ];
            gameStop( thewinner );
        }
  //for the middle horozontal line
if((Status[4] != "") && (Status[4]==Status[5] && Status[5]==Status[6]))
  {
       thewinner=Status[4];
       gameStop(thewinner);
  }
  //for the botton horizontal line
if((Status[7]!="") && (Status[7]==Status[8] && Status[8]==Status[9]))
  {
       thewinner=Status[7];
       gameStop(thewinner);
  }
  //for the vertial first line
if((Status[1]!="") && (Status[1]==Status[4] && Status[4]==Status[7]))
  {
       thewinner=Status[1];
       gameStop(thewinner);
  }
  //middle
if((Status[2]!="") && (Status[2]==Status[5] && Status[5]==Status[8]))
  {
       thewinner=Status[2];
       gameStop(thewinner);
  }
  //last vertical
if((Status[3]!="") && (Status[3]==Status[6] && Status[6]==Status[9]))
  {
       thewinner=Status[3];
       gameStop(thewinner);
  }
  //diagonal 1
if((Status[1]!="") && (Status[1]==Status[5] && Status[5]==Status[9]))
  {
       thewinner=Status[1];
       gameStop(thewinner);
  }
// the second diagonal
if((Status[3]!="") && (Status[3]==Status[5] && Status[5]==Status[7]))
  {
       thewinner=Status[3];
       gameStop(thewinner);
  }
//*********************************************Check  for the treminating condition***********************************************
 
 
  for(int a=1;a<10;a++){
       if(Status[a]==""){
       available=true;
       break;
       }
       else
            available=false;
            }
           
            if(!available)
                 gameStop("tie");
                 }
//***********************************************display  of the result*******************************************************
  public  void gameStop( String winner ) {
        if ( winner == "tie" ){
            JOptionPane.showMessageDialog( MT1.this, "Pasti MENANG di game selanjutnya!!",
                                        ".... SERI ....", JOptionPane.INFORMATION_MESSAGE );
            newgame();
        }
        else {
       String output;
       int choice;
         if(winner=="X"){
            output = "\tSELAMAT, ANDA MENANG !!!!! \nMau main Lagi?";
            choice = JOptionPane.showConfirmDialog( MT1.this, output,
                ".... MENANG ....", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE );
            }
            else{
             output="\tPayah, kau kalah !!!!!! \n Mau main Lagi?";
                            choice = JOptionPane.showConfirmDialog( MT1.this, output,
                                ".... KALAH ....", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE );
                 }
            if ( choice == 0 )
                newgame();
            else
               exitt();   
        }
    }
        public void exitt(){
            JOptionPane.showMessageDialog( MT1.this,
                "Terimakasih telah mencoba :)",
                "Terimakasih", JOptionPane.INFORMATION_MESSAGE );
            dispose();
    }

    public static void main(String args[]) {
        MT1 tic=new MT1();
    }         
}

Sumber :

You Might Also Like

0 komentar

Diberdayakan oleh Blogger.