Bài tập java


Diễn đàn chia sẻ kiến thức, kinh nghiệm về IT và cuộc sống!
 
Trang ChínhGalleryTìm kiếmLatest imagesĐăng kýĐăng Nhập
Top posters
Sakura (1124)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
hotboy (705)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
Già Làng (373)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
con_ca_nho90 (289)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
that_true (154)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
theanhkkt (143)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
phamay (137)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
lovelonelyman (134)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
o0ovioletstaro0o (128)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
stevenhung (122)
Bài tập java Vote_lcapBài tập java Voting_barBài tập java Vote_rcap 
Âm - Dương lịch
Clock
Logo
11TH02 Pro!
Liên kết
Tin tức 60s
Tin công nghệ
Thời sự 24h
Game Moblie

Share
 

 Bài tập java

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Tác giảThông điệp
control_duty

Bài tập java Stars16


Nam Scorpio

Số bài viết : 16
Điểm : 20
Được cảm ơn : 0
Ngày sinh : 10/11/1988
Tham gia ngày : 21/09/2010
Tuổi : 35
Đến từ : hat

Bài tập java Empty
Bài gửiTiêu đề: Bài tập java   Bài tập java I_icon_minitime23/10/2010, 23:37

Tình hình là bữa trước thầy Thành có kêu làm 1 số bài tập, nhưng chủ yếu là những dạng đã quen rồi như Calculator hay tính phương trình bậc 2 nên chắc không có gì để nhắc đên.
Tuy nhiên có 1 cái rất hay đó là bài Trò chơi Bomb >> cái này mới nên mình bỏ chút thời gian xây dựng cách để làm ra nó :
Code:

/**
 * @(#)bomp.java
 *
 * bomp Applet application
 *
 * @author
 * @version 1.00 2005/1/3
 */
import java.util.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.Event;
public class bomp extends Applet implements ActionListener{
   private Button[] b;
   private Label[] l;
   private int[] kt;
   private int temp;
   public void init()
   {
      b = new Button[100];
      nhapkt();
      Set();
      setLayout(new GridLayout(11,10));
      nhapl();
      for(int i =0;i<100;i++){b[i] = new Button();add(b[i]);b[i].addActionListener(this);}
   }
   public void nhapkt()
   {
      kt = new int[144];
      for(int i =0;i<144;i++){kt[i]=0;}
   }
   public void  nhapl()
   {
      l = new Label[10];
      for(int i=0;i<10;i++){l[i] = new Label();add(l[i]);}
   }
   public void Set()
   {
      Random rd = new Random();
      for(int i=0;i<144;i++)
      {
         if(rd.nextInt(144)>110)
         {
            kt[i]=1;
         }
      }
      for(int i=0;i<12;i++)
      {
         kt[i]=kt[i+132]=0;
      }
      for(int i=11;i<132;)
      {
         kt[i]=kt[i+1] =0;
         i+=12;
      }
      
   }
   public void f(int n)
   {
      int _n = n-13;
      int _m = n-10;
      int _n1 = n+11;
      int _m1 = _n1 +3;
      for(int i =_n;i<_m;i++)
      {
         if(kt[i]==1)
         {
            this.temp +=1;
         }
      }
      for(int i=_n1;i<_m1;i++)
      {
         if(kt[i]==1)
         {
            this.temp +=1;
         }
      }
      if(kt[n-1]==1)
      {
         this.temp +=1;
      }
      if(kt[n+1] ==1)
      {
         this.temp +=1;
      }
   }
   public void actionPerformed(ActionEvent e)
   {
      this.temp=0;
      for(int i=0;i<10;i++)
      {
         if(e.getSource()==b[i])
         {
            if(kt[i+13]==1)
            {
               b[i].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+13);
               b[i].setLabel(Integer.toString(temp));
               this.temp = 0;
               l[5].setText(" ");
               l[6].setText(" ");
               l[7].setText(" ");
            }
            
         }
         
         else if(e.getSource()==b[i+10])
         {
            if(kt[i+25]==1)
            {
               b[i+10].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+25);
               b[i+10].setLabel(Integer.toString(temp));
               this.temp = 0;
               l[5].setText(" ");
               l[6].setText(" ");
               l[7].setText(" ");
            }
            
               
         }
         else if(e.getSource()==b[i+20])
         {
            if(kt[i+37]==1)
            {
               b[i+20].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+37);
               b[i+20].setLabel(Integer.toString(temp));
               this.temp = 0;
               l[5].setText(" ");
               l[6].setText(" ");
               l[7].setText(" ");
            }
            
         }
         else if(e.getSource()==b[i+30])
         {
            if(kt[i+49]==1)
            {
               b[i+30].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+49);
               b[i+30].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         else if(e.getSource()==b[i+40])
         {
            if(kt[i+61]==1)
            {
               b[i+40].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+61);
               b[i+40].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         else if(e.getSource()==b[i+50])
         {
            if(kt[i+73]==1)
            {
               b[i+50].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+73);
               b[i+50].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         else if(e.getSource()==b[i+60])
         {
            if(kt[i+85]==1)
            {
               b[i+60].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+85);
               b[i+60].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         else if(e.getSource()==b[i+70])
         {
            if(kt[i+97]==1)
            {
               b[i+70].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+97);
               b[i+70].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         else if(e.getSource()==b[i+80])
         {
            if(kt[i+109]==1)
            {
               b[i+80].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+109);
               b[i+80].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         else if(e.getSource()==b[i+90])
         {
            if(kt[i+121]==1)
            {
               b[i+90].setLabel("Bum");
               l[5].setText("Trung ");
               l[6].setText("bom ");
               l[7].setText("roi!");
               for(int j=0;j<100;j++){b[j].setLabel(" ");}
               this.temp =0;
            }
            else
            {
               f(i+121);
               b[i+90].setLabel(Integer.toString(temp));
               this.temp = 0;
            }
            
         }
         
      }
      
   }
   
}


Đây chỉ là sườn để các bạn nắm lấy cách làm bài tập này >>> còn vụ làm sao cho nó giống game của MS thì tự mò nhé
Về Đầu Trang Go down
 

Bài tập java

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 
Trang 1 trong tổng số 1 trang

 Similar topics

-
» LỖI BT JAVA
» [Bai tap 01] java
» Đề thi mẫu Java! Các bạn chú ý!
» Bài tập java ngày mai đây
» Lập trình java.

Permissions in this forum:Bạn không có quyền trả lời bài viết
IT World! :: HỌC TẬP :: HỌC KỲ V :: Lập Trình Java-