📄 freshman.java
字号:
/**
F R E S H - F E R R A R I
"Name: Fresh Ferrari V 2.01"
"Author: WILLIAM TSOBGNY alias Fresh El Muchacho"
"E-Mail : freshelm@yahoo.fr, freshmuchacho@hotmail.com"
"URL : http://www.ifrance.com/lefresh/"
I Hope u will enjoy playing and performing this game, replace all pictures with yours
And enjoy the FreshFerrari Game!
*///
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.util.*;
import java.awt.font.*;
import javax.swing.*;
import javax.swing.border.*;
import java.applet.*;
import javax.swing.border.*;
import javax.swing.plaf.TabbedPaneUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import java.applet.*;
public class FreshMan extends JFrame implements ActionListener
{
public Thread runner;//Runner of the clock
protected int tie, sec;
protected final int Delay = 1000;
//the size of the m_data array also determines the size of the level
//(the product of m_nx and m_ny)
//Note: The m_data String array can be easily modified to produce a new level.
//We also can easily modify the program to read this information from an external file.
//These features would be natural enhancements to make if we were to expand upon this game.////
protected String[] m_data ;
protected JLabel2D lbl10 = new JLabel2D("PLAYER 1");
protected JLabel2D lbl102 = new JLabel2D("PLAYER 2");
//protected JLabel2D lbl103 = new JLabel2D("PLAYER 3");
private Help ab = new Help (this);
private LevelBox lb = new LevelBox (this);
// status bar
private JPanel statusBar = new JPanel();
private JLabel count = new JLabel();
private JLabel status = new JLabel();
// menu bar
private JMenuBar menuBar = new JMenuBar();
// menu file
private JMenu menuGame = new JMenu("Game");
private JMenuItem menuGameNew = new JMenuItem("New Game");
private JMenuItem menuGamePause = new JMenuItem("Pause");
private JMenuItem menuGameResume = new JMenuItem("Resume");
private JMenuItem menuGameExit = new JMenuItem("Exit");
// menu edit
private JMenu menuOptions = new JMenu("Options");
private JComboBox LevelChoice = new JComboBox () ;
private JComboBox PlayerChoice = new JComboBox () ;
//private JMenuItem menuOptionsLevel = new JMenuItem("Level");
//private JMenuItem menuOptionsPlayer = new JMenuItem("Nbr Of Player");
//private JMenuItem menuOptionsName = new JMenuItem("Names Of Players");
// menu help
private JMenu menuHelp = new JMenu ("Help");
private JMenuItem menuHelpAbout = new JMenuItem("About...");
private JMenuItem menuHelpInstruction = new JMenuItem("Instructions...");
protected FreshMan2D field;
protected player2D pane;
protected player2D2 pane2;
final String[] chois= { "One Player", "Two Players"};
int responses;
public FreshMan()
{
JPanel contentPane = new JPanel ();
ActionListener actListener;
Dimension size;
// address frame
this.setTitle ("F R E S H F E R R A R I");
this.setResizable (false);
// status bar
count.setText ("0");
count.setBorder (BorderFactory.createLoweredBevelBorder ());
size = count.getPreferredSize ();
size.width = 100;
count.setPreferredSize (size);
status.setText (" ");
status.setBorder (BorderFactory.createLoweredBevelBorder ());
size = status.getPreferredSize ();
size.width = 350;
status.setPreferredSize (size);
statusBar.setLayout (new GridBagLayout ());
statusBar.add (count,
new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets (0, 0, 0, 0), 0, 0));
statusBar.add (status,
new GridBagConstraints (1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets (0, 0, 0, 0), 0, 0));
// build the menu bar ...
setJMenuBar(menuBar);
// build the menu "Game" ...
menuBar.add(menuGame);
// build the Game's items...
menuGame.add(menuGameNew); menuGameNew.addActionListener(this);
menuGame.add(menuGamePause); menuGamePause.addActionListener(this);
menuGame.add(menuGameResume); menuGameResume.addActionListener(this);
menuGame.add(menuGameExit); menuGameExit.addActionListener(this);
// build the menu Options...
menuBar.add(menuOptions);
menuOptions.add(PlayerChoice);
menuOptions.add(LevelChoice);
// build the Options's items...
//menuOptions.add(menuOptionsLevel); menuOptionsLevel.addActionListener(this);
//menuOptions.add(menuOptionsPlayer); menuOptionsPlayer.addActionListener(this);
//menuOptions.add(menuOptionsName); menuOptionsName.addActionListener(this);
// build the menu help...
menuBar.add(menuHelp);
// build the help's items...
menuHelp.add(menuHelpAbout); menuHelpAbout.addActionListener(this);
menuHelp.add(menuHelpInstruction); menuHelpInstruction.addActionListener(this);
//menuBar.add(LevelChoice);
for (int i=0; i<=7; i++) LevelChoice.addItem ("Level " + i) ;
LevelChoice.addItem("Bonus Stage");
LevelChoice.setEditable(false);
PlayerChoice.addItem("One Player");PlayerChoice.addItem("Two Players");
// getContentPane().setLayout(new BorderLayout());
//field.life = 0; field.life2 = 0;
//field = new FreshMan2D(this);
//pane = new player2D(this, field);
//pane2 = new player2D2(this, field);
//getContentPane().add(pane, BorderLayout.NORTH);
//getContentPane().add(field, BorderLayout.CENTER);
//getContentPane().add(pane2, BorderLayout.SOUTH);
initGame();
}
public void initGame(){
getContentPane().removeAll();
getContentPane().add(new JLabel(ImageOf.initGame));
pack();
setResizable(false);
setVisible(true);
}
public void newGame(){
if(LevelChoice.getSelectedIndex() == 8) {initGame();
JFrame f = new JFrame("T O W E R O F H A N O I");
Tower t = new Tower(); f.getContentPane().add(t, BorderLayout.CENTER);
f.setSize(500,500);f.setResizable(true);
f.show(); }
else{
//Discuss about case 1 and case 2
responses=menuOptionsPlayer_actionPerformed();
menuOptionsLevel_actionPerformed();
//Hier ist the real stop() method of runner
if (runner != null)
runner.stop();
runner = null;//**
getContentPane().removeAll();
lbl102 = new JLabel2D("PLAYER 2");
//MODIFIER LE TEMPS REQUIS POUR JOUER.....................+++++++++++.......
tie = 0; sec= 10;
menuOptionsName_actionPerformed();
//IF ONE PLAYERS
if(chois[responses] == chois[0]) {
field = new FreshMan2D(this);
pane = new player2D(this, field);
pane2 = new player2D2(this, field);
repaint();
getContentPane().add(pane, BorderLayout.NORTH);
getContentPane().add(field, BorderLayout.CENTER);
getContentPane().add(pane2, BorderLayout.SOUTH);
field.m_runner.start();
m_dataLife();
runner = new Thread() {
public void run()
{
while (true) {
if(tie == 0) {sec--; tie = 9;}
else {tie--;}
pane.lbl50.setText(" "+sec+" : "+tie+" ");repaint();
if((sec == 0)&(tie == 0)) //JOptionPane for the game over
{
gameOver();
}
try{
Thread.sleep(Delay);
} catch(InterruptedException e){ }
}
}
}; //Fin du Thread m_runner
runner.start();
}
//IF TWO PLAYER
else { getContentPane().removeAll();
field = new FreshMan2D(this);
pane = new player2D(this, field);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -