⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameoflife.java

📁 采用jibu实现的Java并行编程的一个例子。 演示的是生命游戏。
💻 JAVA
字号:
package gameoflife;

import java.util.Random;

import graphics.GraphicsFrame;


public class GameOfLife
{
	public static void main(String[] args) throws InterruptedException
	{
		// The size of the world
		int columns = 500;
		int rows = 300;
		
		// Each cell will have width and length = 2 * cellPadding 
		int cellPadding = 1;
		
		// The number of LifeForms to begin with
		int numLifeForms = 200;
		
		// Set this to false to run the game sequentially.
		// If the game is run on a computer with multiple cores, then the
		// speed difference should obvious.
		boolean parallel  = true;
		
		LifeForm[] lifeForms = new LifeForm[numLifeForms];
		Random rand = new Random();
		
		// Generate some life forms that will be placed randomly
		for(int i = 0; i <numLifeForms; i++)
		{
			int x = rand.nextInt(columns);
			int y = rand.nextInt(rows);
			 
			if(i < numLifeForms / 3)
				lifeForms[i] = LifeForm.createGlider(x,y);// 滑翔机
			else if(i < numLifeForms / 2)
				lifeForms[i] =  LifeForm.createPulsar(x,y);// 脉冲星
			else
				lifeForms[i] = LifeForm.createLightweightSpaceship(x,y);// 太空船
		}
		
		// Start the Game of life
		GraphicsFrame fr = new GraphicsFrame("Game of Life" ,
				new GamePanel(columns, rows, cellPadding, lifeForms, parallel));

		fr.setVisible(true);

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -