生命游戏 GAME OF LIFE

    文档

 
 

主页

 
  介绍  
  L'applet  
  文档  
 

下载

 
     

注意: 运行程序需要 Java Runtime Environment (JRE) 6u1


生命游戏在线JavaDoc. 这里

 

<<使用文挡>>

生命游戏主要有两个界面区域构成 :

一个细胞显示区域。

一个控制面板区域。

Applet下载到本地缓存的时候,一些已经定义好的形状文件将自动下载,这些文件是被提前定义在‘\source\shapes\shapes.txt’文件里。下载完成后这些形状将被添加到形状菜单中。

 ‘file:/  Exemple ( 要打开一个文件 'C:\exemple.xml'  -->输入  ‘file:/c:/exemple.xml’)

如果希望建立一个新的形状文件,需要手动建立一个 (XML)文件.

这个 XML 文件包括 :

<?xml version="1.0" encoding="UTF-8"?>

<shapes>

</shapes>

Pour <Save>la forme dans un fichier, il faut avoir un fichier <Open> en cours. Et plus donner un nom de cette forme dans la zone de texte « New shape name » et appuyer la bouton « SaveInFile ».

 

 

<<如何添加一个算法>>

如果要重新定义一个算法,你可以建立一个新的算法class这个class extend « Algorithm ».

在你的算法class中,你要;

重新定义你的方法 :

public abstract State getCellStateByNeighbor(State state, Cell []neighbor );

Les deux paramétrers sont le valeur d’entre de cellier courant.

给三个变量赋值:

       /*

        * The objet States.

        * In your class, you must redefine this value.

        * They are make up of the color. 

        * Ex:    'Color colors[]=new Color[]{Color.white,Color.red,Color.black};'

        *           'states=new States(3,colors);'

        */

       public States states;

       /*

        * The number loop, it value is possible change with applet interface.

        * In your class, for the method Util.getNombreNeighbor,you need this value. 

        */

       public int neighbor_loop;

       /*

        * The String rule, it value is possible change with applet interface.

        * The form of this value is you want (Ex: '14/45/12' or '1,2,3/4,5'...)

        * In your class, for the method getCellStateByNeighbor(),you need this value. 

        */

       public String rules; 

注意 : 建立完成算法class后,要把这个class的名字添加到这个文件中 ‘\source\algorithm\listeAlgorithms.txt’.

 

 

<<一个算法class的例子>>

package org.univ.paris5.GameOfLife.algorithms;

 

import org.univ.paris5.GameOfLife.Algorithm;

import org.univ.paris5.GameOfLife.States;

import org.univ.paris5.GameOfLife.State;

import org.univ.paris5.GameOfLife.Cell;

import org.univ.paris5.GameOfLife.Util;

 

import java.awt.Color;

 

/**

 * One algoritm with 3 state.

 *

 * @author PengFei DONG

 * @author Ke LIANG

 */

public class Algorithm_8_States extends Algorithm {

         public Algorithm_8_States(){

                   Color colors[]=new Color[]{Color.white,Color.red,Color.black,Color.green};

                   states=new States(4,colors);

                   neighbor_loop=1;

                   rules="22/22";

         }

         public State getCellStateByNeighbor(State state, Cell []neighbor ){

                   int n1=0,n2=0,n3=0,n4=0,i;

                   String nb[]=rules.split("/");

                   String nb1=nb[0];

                   String nb2=nb[1];

                   int numbreNeighbor=Util.getNombreNeighbor(neighbor_loop);

                   //Algoritm....

                   for(i=0;i<numbreNeighbor;i++)

                   {

                            if(neighbor[i].state.getIndex().equals("1")){ n1++;continue;}

                            if(neighbor[i].state.getIndex().equals("2")){ n2++;continue;}

                            if(neighbor[i].state.getIndex().equals("3")){ n3++;continue;}

                            if(neighbor[i].state.getIndex().equals("4")){ n4++;continue;}

                    }

                  

                   if (state.getIndex().equals("2"))

                   {

                            if(nb1.contains(""+n2)) {return states.getStateByIndex("2");}

                            else

                            {

                                     if(nb1.contains(""+n3)) {return states.getStateByIndex("3");}

                                     else

                                     {

                                               return states.getStateByIndex("1");}

                            }

                   }

                   else

                   {

                            if (state.getIndex().equals("3"))

                            {

                                     if(nb1.contains(""+n2)) {return states.getStateByIndex("2");}

                                     else

                                     {if(nb1.contains(""+n4)) {return states.getStateByIndex("4");}

                                     else

                                                        return states.getStateByIndex("1");

                                     }

                            }

                            else

                            {

                                     if(nb2.contains(""+n1)) {return states.getStateByIndex("3");}

                                     else

                                     {

                                               if(nb2.contains(""+n2)) {return states.getStateByIndex("2");}

                                               else

                                               {  if(n1>n4) return states.getStateByIndex("1");

                                                        //System.out.println("*********3");

                                               else return states.getStateByIndex("4");}

                                     }

                            }

                   }

 

         }

}

 

 

<<Classes  UML>>

Classes 组件

 

Classes 算法