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

📄 gameboardfactory.java

📁 一个基于J2ME的pacman游戏
💻 JAVA
字号:
/**

 * PacMan for J2ME Devices

 * CS 327 - Design Project, Fall 2002

 * University of Illinois, Urbana-Champaign

 * 

 * file: GameBoardFactory.java 

 * contact: Braden Kowitz

 * date: 11/24/02

 **/



//----------------------------------------------------------------------------//



/**

 * Partial implementation of a Factory object to create GameBoard objects.

 **/

public class GameBoardFactory

{

	/**

	 * 2-D array of GridNode objects that represent the board

	 **/

	private static GridNode nodes[][];

	

	/**

	 * Creates a sample board

	 **/

	public static GameBoard test()

	{

	

	

		GridNode.setSize(13);



		GameBoard gb = new GameBoard();

		

		int size = 8;

		nodes = new GridNode[size][size-2];



		for (int i=0; i<size; i++) {

		for (int j=0; j<size-2; j++)

		{

			nodes[i][j] = new GridNode(i,j);

			gb.addGridNode(nodes[i][j]);

		

		} }





		// here we define our board:



		PacmanActor pac = new PacmanActor(nodes[4][3]);

		gb.setPacman(pac);



		GhostActor ghost;

		ghost = new GhostActor(nodes[0][0],pac);

		gb.addGhost(ghost);

		ghost = new GhostActor(nodes[0][5],pac);

		gb.addGhost(ghost);

		ghost = new GhostActor(nodes[7][0],pac);

		gb.addGhost(ghost);



		nodes[0][0].setPellet(GridNode.BIG_PELLET);

		nodes[0][5].setPellet(GridNode.BIG_PELLET);

		nodes[7][0].setPellet(GridNode.BIG_PELLET);

		nodes[7][5].setPellet(GridNode.BIG_PELLET);



		UDLink(1,1,1,2);

		UDLink(1,2,1,3);

                UDLink(1,3,1,4);

                UDLink(1,4,1,5);

		UDLink(1,5,1,6);

		UDLink(2,2,2,3);

                UDLink(2,3,2,4);

		UDLink(2,4,2,5);

		UDLink(3,2,3,3);

		UDLink(3,4,3,5);

		UDLink(4,1,4,2);

		UDLink(4,5,4,6);

		UDLink(5,1,5,2);

		UDLink(5,5,5,6);

		UDLink(6,2,6,3);

		UDLink(6,4,6,5);

		UDLink(7,2,7,3);

		UDLink(7,3,7,4);

		UDLink(7,4,7,5);

		UDLink(8,1,8,2);

		UDLink(8,2,8,3);

                UDLink(8,3,8,4);

                UDLink(8,4,8,5);

		UDLink(8,5,8,6);

		

		LRLink(1,1,2,1);

                LRLink(2,1,3,1);

		LRLink(3,1,4,1);

                LRLink(4,1,5,1);

		LRLink(5,1,6,1);

                LRLink(6,1,7,1);

                LRLink(7,1,8,1);

                LRLink(1,2,2,2);

                LRLink(3,2,4,2);

                LRLink(5,2,6,2);

                LRLink(7,2,8,2);

                LRLink(2,3,3,3);

                LRLink(3,3,4,3);

                LRLink(4,3,5,3);

                LRLink(5,3,6,3);

                LRLink(6,3,7,3);

                LRLink(2,4,3,4);

                LRLink(3,4,4,4);

                LRLink(4,4,5,4);

                LRLink(5,4,6,4);

                LRLink(6,4,7,4);

                LRLink(1,5,2,5);

                LRLink(3,5,4,5);

                LRLink(5,5,6,5);

                LRLink(7,5,8,5);

		LRLink(1,6,2,6);

                LRLink(2,6,3,6);

		LRLink(3,6,4,6);

                LRLink(4,6,5,6);

		LRLink(5,6,6,6);

                LRLink(6,6,7,6);

                LRLink(7,6,8,6);





		return gb;

	}



	/**

	 * Creates a up-down link in the nodes[][] array.

	 * - Upper left is (1,1)

	 **/

	private static void UDLink(int x1, int y1, int x2, int y2)

	{

		nodes[x1-1][y1-1].setDown(nodes[x2-1][y2-1]);

		nodes[x2-1][y2-1].setUp(nodes[x1-1][y1-1]);

	}

	/**

	 * Creates a left-right link in the nodes[][] array.

	 * - Upper left is (1,1)

	 **/

	private static void LRLink(int x1, int y1, int x2, int y2)

	{

		nodes[x1-1][y1-1].setRight(nodes[x2-1][y2-1]);

		nodes[x2-1][y2-1].setLeft(nodes[x1-1][y1-1]);

	}

}



//----------------------------------------------------------------------------//

⌨️ 快捷键说明

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