📄 nokiagameeffects.java
字号:
import com.nokia.mid.sound.Sound;
import com.nokia.mid.ui.DeviceControl; // Nokia GameEffects provides a 'Nokia device specific' implementation
// of game effects such as vibration, flashing lights and
// playing game sounds.
class NokiaGameEffects /*extends GameEffects*/ {
private volatile boolean isPaused = true;
private Sound sound = null;
private volatile int currentPriority = 0; // The sound byte arrays are in 'Smart Messaging' ringing tone format. 18:30 15.2.2004
private final static byte[] S_MIL1 =
{
(byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x55, (byte)0x35, (byte)0xA5, (byte)0xB1, (byte)0xA5, (byte)0xBC, (byte)0x04,
(byte)0x00, (byte)0x9A, (byte)0xD8, (byte)0xF4, (byte)0x11, (byte)0x82, (byte)0x8A, (byte)0x40, (byte)0xC4, (byte)0x0D,
(byte)0xC1, (byte)0x65, (byte)0x20, (byte)0xA3, (byte)0x70, (byte)0x31, (byte)0x02, (byte)0x8C, (byte)0x29, (byte)0x03,
(byte)0x10, (byte)0x37, (byte)0x05, (byte)0x94, (byte)0x82, (byte)0x8D, (byte)0xC0, (byte)0xC4, (byte)0x0A, (byte)0x30,
(byte)0xA4, (byte)0x0C, (byte)0xC1, (byte)0x64, (byte)0x60, (byte)0x52, (byte)0x04, (byte)0x60, (byte)0xA3, (byte)0x30,
(byte)0x28, (byte)0xC2, (byte)0x90, (byte)0x33, (byte)0x05, (byte)0x91, (byte)0x81, (byte)0x48, (byte)0x11, (byte)0x82,
(byte)0x8C, (byte)0xC0, (byte)0xA3, (byte)0x09, (byte)0x40, (byte)0xB4, (byte)0x0C, (byte)0xC1, (byte)0x64, (byte)0xA0,
(byte)0xA3, (byte)0x30, (byte)0x2D, (byte)0x02, (byte)0x4C, (byte)0x25, (byte)0x02, (byte)0xD0, (byte)0x33, (byte)0x05,
(byte)0x92, (byte)0x82, (byte)0x8C, (byte)0xC0, (byte)0xB4, (byte)0x09, (byte)0x30, (byte)0x9C, (byte)0x0B, (byte)0x40,
(byte)0xC4, (byte)0x16, (byte)0x46, (byte)0x0A, (byte)0x31, (byte)0x02, (byte)0xD0, (byte)0x26, (byte)0xC2, (byte)0x70,
(byte)0x31, (byte)0x03, (byte)0x90, (byte)0x59, (byte)0x38, (byte)0x28, (byte)0xE4, (byte)0x0C, (byte)0x40, (byte)0x9C,
(byte)0x00
};
// Bullet 'ringing tone' sound effect
private final static byte[] S_TACNO1 =
{ (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x80, (byte)0x40, (byte)0x00, (byte)0xF3, (byte)0x48, (byte)0x22, (byte)0xC3, (byte)0x4C, (byte)0x35, (byte)0x02, (byte)0xAC, (byte)0x22, (byte)0xC0, (byte)0x00 };
// Base explosion 'ringing tone' sound effect
private final static byte[] S_NETACNO1 =
{ (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x80, (byte)0x40, (byte)0x01, (byte)0x52, (byte)0x48, (byte)0x2D, (byte)0x02, (byte)0x71, (byte)0x49, (byte)0x18, (byte)0x20, (byte)0xD4, (byte)0x12, (byte)0x72, (byte)0x00, (byte)0x00 };
// Block explosion 'ringing tone' sound effect
private final static byte[] S_TACNO2 =
{ (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x80, (byte)0x40, (byte)0x00, (byte)0xD2, (byte)0xC8, (byte)0x31, (byte)0x03, (byte)0x90, (byte)0x23, (byte)0x12, (byte)0xB0, (byte)0x00 };
// The 'game over' music played when the player looses.
// It is from the old tune "Loch Lomond", starting at the
// notes for the verse "Oh, you'll take the high road ...".
// It is defined as a 'ringing tone' byte arrary.
private final static byte[] S_PUBLIKA =
{ (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x80, (byte)0x40, (byte)0x06, (byte)0xB2, (byte)0x08, (byte)0x22, (byte)0x82, (byte)0xC8, (byte)0x2C, (byte)0xC3, (byte)0x0C, (byte)0x34, (byte)0x83, (byte)0x4C, (byte)0x30, (byte)0xC2, (byte)0xC8, (byte)0x2C, (byte)0xC2, (byte)0x6C, (byte)0x22, (byte)0x82, (byte)0x2C, (byte)0x2A, (byte)0xC2, (byte)0xC8, (byte)0x2C, (byte)0xC2, (byte)0xCC, (byte)0x2C, (byte)0x83, (byte)0x4C, (byte)0x49, (byte)0x16, (byte)0x13, (byte)0x21, (byte)0x14, (byte)0x10, (byte)0x81, (byte)0x14, (byte)0x13, (byte)0x41, (byte)0x36, (byte)0x11, (byte)0x62, (byte)0x0D, (byte)0x20, (byte)0xD3, (byte)0x12, (byte)0x45, (byte)0x88, (byte)0x38, (byte)0xC3, (byte)0x4C, (byte)0x30, (byte)0xC2, (byte)0xCC, (byte)0x26, (byte)0x82, (byte)0x2C, (byte)0x26, (byte)0xC2, (byte)0xD0, (byte)0x2C, (byte)0xD3, (byte)0x50, (byte)0x49, (byte)0x16, (byte)0x93, (byte)0x41, (byte)0x16, (byte)0x20, (byte)0xD3, (byte)0x0C, (byte)0x10, (byte)0xB1, (byte)0x00, (byte)0x00 };
// This 'game over' music is played when the player wins.
// It is from the old tune "Yankee Doodle", starting at
// the notes for the verse "Yankee Doodle keep it up, Yankee
// Doodle dandy ...". It is defined as a 'ringing tone' byte arrary.
private final static byte[] S_DANE =
{ (byte)0x02, (byte)0x4A, (byte)0x3A, (byte)0x80, (byte)0x40, (byte)0x04, (byte)0x11, (byte)0xE8, (byte)0x2C, (byte)0xD3, (byte)0x10, (byte)0x2C, (byte)0xC2, (byte)0x6C, (byte)0x2C, (byte)0xC3, (byte)0x0C, (byte)0x34, (byte)0xC2, (byte)0xCC, (byte)0x2A, (byte)0xD2, (byte)0xD0, (byte)0x2A, (byte)0xC2, (byte)0x6C, (byte)0x22, (byte)0xD2, (byte)0x70, (byte)0x2A, (byte)0xC2, (byte)0x0C, (byte)0x2C, (byte)0xD3, (byte)0x10, (byte)0x2C, (byte)0xC2, (byte)0x6C, (byte)0x2C, (byte)0xC3, (byte)0x0C, (byte)0x34, (byte)0xC2, (byte)0xCC, (byte)0x2A, (byte)0xC3, (byte)0x4C, (byte)0x30, (byte)0xC3, (byte)0x8C, (byte)0x34, (byte)0x83, (byte)0x4C, (byte)0x00 };
NokiaGameEffects() { }
// Game Settings methods
boolean hasSoundCapability()
{ return true; }
boolean hasVibrationCapability()
{ return true; }
// Game Effects methods
private synchronized void setIsPaused(boolean isPaused)
{ this.isPaused = isPaused; }
void pause()
{ setIsPaused(true);
if (sound != null) {
sound.stop(); }
DeviceControl.stopVibra(); }
void resume() {
// Note: The 'Game Settings' may change during a pause.
// In general, one might need to handle that during the resume.
// But we don't need to do anything to handle that before resuming
// because any sound or vibration that were in progress just
// before pausing were cancelled when pause() was called,
// and any 'Game Settings' changes will take effect after the resume.
setIsPaused(false); }
private void playSound(int priority, byte[] bytes) {
if (!isPaused && hasSoundCapability() ) {
try {
if (sound == null || sound.getState() != Sound.SOUND_PLAYING) {
sound = new Sound(bytes, Sound.FORMAT_TONE);
sound.setGain(128);
sound.play(1); // loop = 1
currentPriority = priority;
} else {
// A sound exists in the SOUND_PLAYING state.
if (priority > currentPriority) {
sound.stop();
sound.init(bytes, Sound.FORMAT_TONE);
sound.play(1); // loop = 1
currentPriority = priority;
}
}
} catch (Exception e) {
currentPriority = 0;
// allow any new request to play
}
}
}
void playTacno1() {
// Lowest priority game sound
playSound(4, S_TACNO1);
}
void playMil1() {
// Lowest priority game sound
playSound(1, S_MIL1);
}
void playTacno2() {
// Higher priority game sound
playSound(4, S_TACNO2);
}
void playNetacno1() {
// Highest priority game sound
playSound(4, S_NETACNO1);
}
void playDaNe() {
playSound(3, S_DANE);
}
void playPomoc() {
playSound(4, S_DANE);
}
void playPublika() {
playSound(1, S_PUBLIKA);
}
void vibrate() {
try {
DeviceControl.startVibra(100, 300); } catch (Exception e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -