this.singleHeightY * y + 1, this.singleWidthX - 2, this.singleHeightY - 2, this.cooPos, this.cooPos ); }
private void createBean( Point temp ) { LP: while( true ) { temp.x = (int) (Math.random() * this.horizontalGrid); temp.y = (int) (Math.random() * this.verticalGrid); snakeSq = mainSnake.iterator(); while ( snakeSq.hasNext() ) { if( snakeSq.next().equals( new Point( temp.x, temp.y ) ) ) { continue LP; } } break; } } }
ConfigMenu.java
package SnakeGame;
import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class ConfigMenu extends JMenuBar {
GameFrame owner; JMenu[] menu; JMenuItem[] menuItem; JRadioButtonMenuItem[] speedItem, modelItem, standardItem; private UIManager.LookAndFeelInfo looks[]; public ConfigMenu( GameFrame owner ) { this.owner = owner; owner.setJMenuBar( this ); String[] menu_name = {"Snake Game", "Game Configure", "Game Help"}; menu = new JMenu[menu_name.length]; for( int i = 0; i < menu_name.length; i++ ) { menu[i] = new JMenu( menu_name[i] ); menu[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) ); this.add( menu[i] ); }
String[] menuItem_name = {"Start Game", "Stop Game", "Exit Game", "Game Color", "About..."}; menuItem = new JMenuItem[menuItem_name.length]; for( int i = 0; i < menuItem_name.length; i++ ) { menuItem[i] = new JMenuItem( menuItem_name[i] ); menuItem[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) ); menuItem[i].addActionListener( new ActionHandler() ); } menu[0].add( menuItem[0] ); menu[0].add( menuItem[1] ); menu[0].addSeparator(); menu[0].add( menuItem[2] ); menu[1].add( menuItem[3] ); menu[2].add( menuItem[4] );
String[] inner_menu_name = {"Game Speed", "Window Model", "Game Standard "}; JMenu[] inner_menu = new JMenu[inner_menu_name.length]; for( int i = 0; i < inner_menu_name.length; i++ ) { inner_menu[i] = new JMenu( inner_menu_name[i] ); inner_menu[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) ); menu[1].add( inner_menu[i] ); }
ButtonGroup temp1 = new ButtonGroup(); String[] speedItem_name = {"Speed-1", "Speed-2", "Speed-3", "Speed-4", "Speed-5"}; speedItem = new JRadioButtonMenuItem[speedItem_name.length]; for( int i = 0; i < speedItem_name.length; i++ ) { speedItem[i] = new JRadioButtonMenuItem( speedItem_name[i] ); inner_menu[0].add( speedItem[i] ); speedItem[i].setFont( new Font( "Courier", Font.PLAIN, 12 ) ); speedItem[i].addItemListener( new ItemHandler() ); temp1.add( speedItem[i] ); }
ButtonGroup temp2 = new ButtonGroup(); String[] modelItem_name = { "Linux", "Mac", "Windows" }; modelItem = new JRadioButtonMenuItem[modelItem_name.length]; |