Skip to content

Instantly share code, notes, and snippets.

@susumuishigami
Created October 23, 2011 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save susumuishigami/1307015 to your computer and use it in GitHub Desktop.
Save susumuishigami/1307015 to your computer and use it in GitHub Desktop.
昔(2001年頃)作ったiアプリ用ゲーム「分子作成」のソースコードを公開します。
// copyright(c) 2001 Susumu ISHIGAMI
// Licensed under MPL 1.1
// http://www.mozilla.org/MPL/
// http://www.mozilla.org/MPL/MPL-1.1.html
import com.nttdocomo.ui.*;
import com.nttdocomo.util.*;
import java.io.*;
import javax.microedition.io.*;
import java.util.*;
public class bunshi extends IApplication {
static final String VERSION = "1.a";
MainCanvas cvs;
public void start() {
cvs = new MainCanvas();
Display.setCurrent(cvs);
}
}
/*==============================================================
◆変数表(主な物のみ)◆
int
flag メインフラグ
fallRes 落下抑制度
energy エネルギー
long
Score ゲーム得点
StartTime タイムアタック用開始時刻(ミリ秒)を保存
HighScore ハイスコア(通常モード用)
MinTime 最小時間(タイムアタックモード用)
byte
mode ゲームモード(0: フリー; 1: タイムアタック)
mov_x,
mov_y 移動中原子の座標
mov_atom 移動中の原子 ※ String[] atom_char 参照
next_atom 次の原子
old_x,
old_y 移動前の位置
配列
byte[8][5] area_sta
各場所の状態(上と右に作業用空白)
byte[5]x_atoms
1列辺りの原子数
boolean[8][5] next_clear
area_staに対応し、次に消える物を覚える
String[] atom_char
mov_atom などの値に対応する元素の文字
"", "H", "C", "N", "O", "S", "Cl", "◆", "◇"
int[] atom_color
同様にそれに対応する色
その他 → ソース参照
==============================================================*/
class MainCanvas extends Canvas implements TimerListener{
int flag, fallRes, energy;
long Score, StartTime, HighScore, MinTime;
byte mode, rensa;
byte mov_x, mov_y, mov_atom, next_atom;
byte[][] area_sta = new byte[8][5];
byte[] x_atoms = new byte[5];
byte old_x, old_y;
boolean[][] next_clear = new boolean[8][5];
boolean paused; // ポーズか否か
int f_light = 1; // 照明がついてるかどうか
Graphics G; // 描画用
Timer timDropper; // 落下用タイマー
Dialog dlg; // 情報表示ダイアログ
Random rnd = new Random(); // 乱数
Image img = null; // イメージ
String[] atom_char = { "", "H", "C", "N", "O", "S", "Cl", "◆", "◇" };
int[] atom_color = {
0, 4, 0, 12, 1, 10, 5, 0, 0
// 黒,赤,黒,栗,青, 緑,紫,黒,黒゙
};
MainCanvas() {
// スクラッチパッドから
try {
DataInputStream DIS = Connector.openDataInputStream("scratchpad:///0;pos=0");
HighScore = DIS.readLong();
MinTime = DIS.readLong();
DIS.close();
if (HighScore < 1000) HighScore = 1000;
if (MinTime == 0) MinTime = 3599000; // 59分59秒
} catch (java.io.IOException e) {
HighScore = 1000;
MinTime = 3599000 ; // 59分59秒
}
PhoneSystem.setAttribute(0, f_light); // 照明をON!
G = this.getGraphics();
timDropper = new Timer();
timDropper.setListener(this);
timDropper.setRepeat(true);
dlg = new Dialog(Dialog.DIALOG_INFO, "分子作成");
setBackground( Graphics.getColorOfName(Graphics.WHITE) );
try {
MediaImage mi = MediaManager.getImage("resource:///nh3.gif");
mi.use();
img = mi.getImage();
} catch (Exception e) {
}
reset(); // 変数の初期化
}
void delay(long n) { // 設定ミリ秒止まる
long fin = (new Date()).getTime() + n; // 今 + 設定ミリ秒
while ((new Date()).getTime() < fin) {
}
}
int posX(byte n) {
return 8 + 14 * n;
}
int posY(byte n) {
return 15 + 104 - 12 * n;
}
int random(int n) {
return (rnd.nextInt() & 0x7fffffff) % n;
}
public void reset() { // 初期化
chgFlag(0);
timDropper.stop();
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 5; j++) {
area_sta [i][j] = 0;
next_clear [i][j] = false;
}
}
for (int i = 0; i < 5; i++)
x_atoms[i] = 0;
}
public void gameStart() {
Score = 0;
energy = 0;
fallRes = 200;
paused = false;
next_atom = 1;
paint(getGraphics());
go_next();
if (mode == 1)
StartTime = (new Date()).getTime();
}
public void go_next() {
mov_x = 2;
mov_y = 7;
old_x = -1;
old_y = -1;
mov_atom = next_atom;
next_atom = (byte)(random(8) + 1); // 次の元素を設定
// 次の表示-----
G.setColor(Graphics.getColorOfName(Graphics.YELLOW));
G.fillRect(82, 19, 20, 26);
G.setColor(Graphics.getColorOfName(Graphics.BLACK));
G.drawString("次", 84, 31);
G.drawString(atom_char[next_atom], 89, 43);
// -------------
timDropper.setTime(fallRes * 10);
timDropper.start();
flag = 12;
repaint();
}
public void drop() {
if (mov_y > x_atoms[mov_x]) {
old_y = mov_y;
old_x = mov_x;
mov_y--;
paint(G);
}
else
atom_land();
}
public void atom_land() {
timDropper.stop();
flag = 11;
x_atoms[mov_x]++;
area_sta[mov_y][mov_x] = mov_atom;
search();
// タイムアタック用クリアー判定
if (mode == 1 && Score >= 3000) {
game_clear();
}
else if (area_sta[7][2] != 0) {
game_over();
} else
go_next();
}
public void game_over() {
dlg.setText("ゲームオーバー\nScore = " + Score);
dlg.show();
if (HighScore < Score) {
dlg.setText("新記録です!");
dlg.show();
HighScore = Score;
renew_record();
}
reset();
}
public void game_clear() {
// 今から開始時刻を引く(ミリ秒)
long time = (new Date()).getTime() - StartTime;
time = time / 1000;
long min = (time / 60);
long sec = (time % 60);
dlg.setText("ゲームクリアー\nキロク = " + min + "分" + sec + "秒");
dlg.show();
time = time * 1000; // 無駄があるような、無いような (--;
if (MinTime > time) {
dlg.setText("新記録です!");
dlg.show();
MinTime = time;
renew_record();
}
reset();
}
public void renew_record() {
try {
DataOutputStream DOS = Connector.openDataOutputStream("scratchpad:///0;pos=0");
DOS.writeLong(HighScore);
DOS.writeLong(MinTime);
DOS.close();
} catch (java.io.IOException e) {
}
}
// ★検索ルーチン ==============================================
boolean check_Sakusan(int px, int py) { // 酢酸検索
// *位置関係は以下の通り
// a h
// b c d e f
// g i
int a = area_sta[px][py];
int b = area_sta[px+1][py-1];
int c = area_sta[px+1][py];
int d = area_sta[px+1][py+1];
int e = area_sta[px+1][py+2];
int f = area_sta[px+1][py+3];
int g = area_sta[px+2][py];
int h = area_sta[px][py+1];
int i = area_sta[px+2][py+1];
if (a == 1 && b == 1 && c == 2 && d == 2 && e == 4 && f == 1 && g == 1) {
if (h == 4)
next_clear[px][py+1] = true;
else if (h == 4)
next_clear[px+2][py+1] = true;
else
return false;
}
// 以下分子発生時
hassei(31);
// 次に消える分の印を付ける
next_clear[px][py] = true;
next_clear[px+1][py-1] = true;
next_clear[px+1][py] = true;
next_clear[px+1][py+1] = true;
next_clear[px+1][py+2] = true;
next_clear[px+1][py+3] = true;
next_clear[px+2][py] = true;
Score += 6000; // おまけ。
return true;
}
boolean check_H4R(int px, int py) { // ロ型水素核融合検索
int w = area_sta[px][py];
int x = area_sta[px][py+1];
int y = area_sta[px+1][py];
int z = area_sta[px+1][py+1];
if (!(w == 1 && x != 1 && y == 1 && z == 1)) // 条件を満たさないとき
return false;
// 以下分子発生時
hassei(32);
Score += 800;
// 次に消える分の印を付ける
next_clear[px][py] = true;
next_clear[px][py+1] = true;
next_clear[px+1][py] = true;
next_clear[px+1][py+1] = true;
return true;
}
boolean check5X(int px, int py) {
int v = area_sta[px][py]; // 中心
int w = area_sta[px-1][py];
int x = area_sta[px+1][py];
int y = area_sta[px][py+1];
int z = area_sta[px][py-1];
if (v == 4 && w == 1 && x == 1 && y == 1 && z == 1) // C H4 メタン
hassei(28);
else if (v == 2 && (
(w == 1 && x == 6 && y == 6 && z == 6) |
(w == 6 && x == 1 && y == 6 && z == 6) |
(w == 6 && x == 6 && y == 1 && z == 6) |
(w == 6 && x == 6 && y == 6 && z == 1)
)
)
hassei(29); // C H Cl3
else if (v == 2 && w == 6 && x == 6 && y == 6 && z == 6) // C Cl4 四塩化炭素
hassei(30);
else
return false;
// 以下分子発生時
// 次に消える分の印を付ける
next_clear[px][py] = true;
next_clear[px+1][py] = true;
next_clear[px-1][py] = true;
next_clear[px][py+1] = true;
next_clear[px][py-1] = true;
Score += 600; // おまけ。
return true;
}
boolean check4T(
int px1, int py1, int px2, int py2, int px3, int py3, int px4, int py4 )
{
int w = area_sta[px1][py1]; // 中心
int x = area_sta[px2][py2];
int y = area_sta[px3][py3];
int z = area_sta[px4][py4];
if (x == y && x == z) {
if (w == 1 && x == 1) { // 水素核融合! ←発生しやすいようにここに書く。
hassei(32);
Score += 600;
}
else if (w == 3 && x == 1) // NH3 アンモニア
hassei(23);
else if (w == 5 && x == 4) // SO3 三酸化硫黄
hassei(24);
else if (w == 3 && x == 6) // NCl3 塩化窒素
hassei(25);
else if (w == 3 && x == 4) // NO3 三酸化窒素
hassei(26);
else
return false; // これを書かないとそのほかの反応も起きてしまう
}
else
return false;
// 以下分子発生時
// 次に消える分の印を付ける
next_clear[px1][py1] = true;
next_clear[px2][py2] = true;
next_clear[px3][py3] = true;
next_clear[px4][py4] = true;
Score += 200; // おまけ。
return true;
}
boolean check4str(int px, int py, boolean yoko) {
// 反応があったら true を返す。
int w, x, y, z;
if (yoko) { // よこ
w = area_sta[px][py];
x = area_sta[px][py+1];
y = area_sta[px][py+2];
z = area_sta[px][py+3];
}
else { // たて
w = area_sta[px][py];
x = area_sta[px-1][py];
y = area_sta[px-2][py];
z = area_sta[px-3][py];
}
if (w == z && x == y) {
if (w == 1 && x == 4) // H O O H 過酸化水素
hassei(19);
else if (w == 3 && x == 2) // N C C N シアン
hassei(20);
else if (w == 1 && x == 2) // H C C H アセチレン
hassei(21);
else if (w == 6 && x == 5) // Cl S S Cl 一塩化硫黄
hassei(22);
else
return false; // これを書かないと例えば C C C C も反応する。
}
else if (
(w == 1 && x == 4 && y == 3 && z == 4) |
(w == 4 && x == 3 && y == 4 && z == 1)
)
hassei(27); // H O N O 亜硝酸
else // なにも発生しない時
return false;
// 以下分子発生時
// 次に消える分の印を付ける
if (yoko) { // よこ
next_clear[px][py] = true;
next_clear[px][py+1] = true;
next_clear[px][py+2] = true;
next_clear[px][py+3] = true;
}
else { // たて
next_clear[px][py] = true;
next_clear[px-1][py] = true;
next_clear[px-2][py] = true;
next_clear[px-3][py] = true;
Score += 200; // おまけ
}
return true;
}
boolean check3(int px1, int py1, int px2, int py2, int px3, int py3) {
// 反応があったら true を返す。
int x = area_sta[px1][py1];
int y = area_sta[px2][py2];
int z = area_sta[px3][py3];
int a = x + z;
int b = x * z;
if (a == 4 && b == 3 && y == 2) // H C N シアン化水素
hassei(10);
else if (a == 2 && b == 1 && y == 4) // H O H 水蒸気
hassei(11);
else if (a == 2 && b == 1 && y == 5) // H S H 硫化水素
hassei(13);
else if (a == 8 && b == 16) { // 二酸化物
if (y == 2) hassei(14); // O C O 二酸化炭素
else if (y == 3) hassei(15); // O N O 二酸化窒素
else if (y == 4) hassei(12); // O O O オゾン
else if (y == 5) hassei(16); // O S O 二酸化硫黄
else if (y == 6) hassei(17); // O Cl O 二酸化塩素
else return false; // これを書かないと O H O も反応してしまう
}
else if (a == 12 && b == 36 && y == 4) // Cl O Cl 一酸化二塩素
hassei(18);
else // なにも発生しない時
return false;
// 以下分子発生時
// 次に消える分の印を付ける
next_clear[px1][py1] = true;
next_clear[px2][py2] = true;
next_clear[px3][py3] = true;
Score += 50; // おまけ。
return true;
}
boolean check2(int px1, int py1, int px2, int py2) {
// 反応があったら true を返す。
int x = area_sta[px1][py1];
int y = area_sta[px2][py2];
int a = x + y;
int b = x * y;
if (a == 2 && b == 1) // H H 水素
hassei(0);
else if (a == 6 && b == 9) // N N 窒素
hassei(1);
else if (a == 8 && b == 16) // O O 酸素
hassei(2);
else if (a == 12 && b == 36) // Cl Cl 塩素
hassei(3);
else if (a == 7 && b == 6) // H Cl 塩化水素
hassei(4);
else if (a == 6 && b == 8) // C O 一酸化炭素
hassei(5);
else if (a == 7 && b == 12) // N O 一酸化窒素
hassei(6);
else if (a == 9 && b == 20) // S O 一酸化硫黄
hassei(7);
else if (a == 10 && b == 24) // Cl O 一酸化塩素
hassei(8);
else if (a == 7 && b == 10) // C S 一硫化炭素
hassei(9);
else // なにも発生しない時
return false; // さっさと処理を抜ける
// 以下分子発生時
// 次に消える分の印を付ける
next_clear[px1][py1] = true;
next_clear[px2][py2] = true;
return true;
}
boolean search_bunshi() { // n個で消える
// −−−5個十字型検索−−−
for (byte i = 1; i <= 3; i++)
for (byte j = 1; j < x_atoms[i] - 1; j++)
if ( check5X(j,i) ) {
return true;
}
// −−−4個ストレート検索−−−
// よこ4
for (byte i = 0; i <= 1; i++)
for (byte j = 0; j < x_atoms[i]; j++)
if ( check4str(j,i, true) ) {
return true;
}
// たて4
for (byte i = 0; i <= 4; i++)
for (byte j = 3; j < x_atoms[i]; j++)
if ( check4str(j,i, false) ) {
return true;
}
// −−−4個T型検索−−−
for (byte i = 0; i <= 4; i++)
for (byte j = 0; j < x_atoms[i]; j++) {
if ( i < 4 && j > 0 && j < x_atoms[i]-1 && // ト型
check4T(j,i, j-1,i, j,i+1, j+1,i) ) return true;
if ( i > 0 && j > 0 && j < x_atoms[i]-1 && // 逆ト型
check4T(j,i, j-1,i, j,i-1, j+1,i) ) return true;
if ( i > 0 && i < 4 && j < x_atoms[i]-1 && // 逆T型
check4T(j,i, j,i-1, j+1,i, j,i+1) ) return true;
if ( i > 0 && i < 4 && j > 0 && // T型
check4T(j,i, j,i-1, j-1,i, j,i+1) ) return true;
}
// −−−3個検索−−−
// よこ3
for (byte i = 0; i <= 2; i++)
for (byte j = 0; j < x_atoms[i]; j++)
if ( check3(j,i, j,i+1, j,i+2) ) {
return true;
}
// たて3
for (byte i = 0; i <= 4; i++)
for (byte j = 2; j < x_atoms[i]; j++)
if ( check3(j,i, j-1,i, j-2,i) ) {
return true;
}
// L字型 (4タイプ)
for (byte i = 0; i <= 3; i++) // ↓の式では三項演算子※を使用しています。
for (byte j = 1;
j < ( x_atoms[i] > x_atoms[i+1] ? x_atoms[i] : x_atoms[i+1] ); j++)
{
if ( check3(j,i, j-1,i, j-1,i+1) ) return true;
if ( check3(j-1,i, j-1,i+1, j,i+1) ) return true;
if ( check3(j-1,i+1, j,i+1, j,i) ) return true;
if ( check3(j,i+1, j,i, j-1,i) ) return true;
}
// ※三項演算子;
// 条件 ? X1 : X2
// 「条件が真の時 X1 が、偽の時 X2 が返される」
// −−−2個検索−−−
// よこ2
for (byte i = 0; i <= 3; i++)
for (byte j = 0; j < x_atoms[i]; j++)
if ( check2( j,i, j,i+1) ) {
return true;
}
// たて2
for (byte i = 0; i <= 4; i++)
for (byte j = 1; j < x_atoms[i]; j++)
if ( check2( j,i, j-1,i) ) {
return true;
}
return false;
}
public void search() {
boolean f_made; // 一回検索で一度でも発生したかどうか。
rensa = 0; // 連鎖を初期化
// ◆ここからが検索の元処理
do {
paint(G); // まず、現在の状態を描画する
// ※↑確実にこの場で処理されるようにrepaint()は使わない
// ★一回判定する★
f_made = search_bunshi();
if (f_made)
check_nextclear();
fall_space(); // 状態が0の部分を詰める
} while (f_made == true);
}
// 検索ルーチンここまで===============================================
public void hassei(int m) {
String[] name = {
"水素", "窒素", "酸素", "塩素",
"塩化水素", "一酸化炭素", "一酸化窒素",
"一酸化硫黄", "一酸化塩素", "一硫化炭素",
"シアン化水素", "水", "オゾン",
"硫化水素", "二酸化炭素", "二酸化窒素",
"二酸化硫黄", "二酸化塩素", "一酸化二塩素",
"過酸化水素", "シアン", "アセチレン", "一塩化硫黄",
"アンモニア", "三酸化硫黄", "塩化窒素",
"三酸化窒素", "亜硝酸",
"メタン", "クロロホルム", "四塩化炭素",
"酢酸", "水素核融合"
};
int[] yokusei = {
2, 8, 30, -2,
-2, -3, -2,
-1, -2, -1,
-10, 40, -3,
-1, 0, -2,
-2, -1, -2,
-1, -5, 0, -3,
-3, -3, -2,
-1, -2,
-1, -1, -2,
+5, +100
};
G.setColor(Graphics.getColorOfName(Graphics.BLACK));
G.drawString(name[m] + "発生!", 8, 12);
fallRes += yokusei[m] + rensa - 1;
if (fallRes < 20) { // 落下抑制度が20より下回ったとき
Score -= (20-fallRes) * 3; // 下回った分の3倍得点減少!
fallRes = 20;
}
else if (fallRes > 300){ // 逆に300を越えた時
Score += (fallRes - 300) * 3; // 越えた文の3倍増加!
fallRes = 300;
}
Score += 20 * (401 - fallRes)/200 * ++rensa;
// 連鎖数と落下速度が大きいほど得点が高い
// 水素核融合限定エネルギー!
if (m == 32)
energy = energy + 100 * rensa * rensa; // energy = 原子崩壊!
// 連鎖エネルギー
if (rensa < 3) ; // なにもしない。
else if (rensa < 5) energy += 10;
else energy += 20;
if (energy >= 500) { // エネルギーが500
delay(1000);
G.setColor(Graphics.getColorOfName(Graphics.RED));
G.fillRect(8, 0, 104, 12);
G.setColor(Graphics.getColorOfName(Graphics.WHITE));
G.drawString("エネルギー解放!", 8, 12);
energy -= 500;
Score += 10000;
// ◇→◆, ◆→C, C→N
for (byte i = 0; i < 5; i++)
for (byte j = 0; j < x_atoms[i]; j++) {
if (area_sta[j][i] == 2) area_sta[j][i] = 3; // C→N
else if (area_sta[j][i] == 7) area_sta[j][i] = 2; // ◆→C
else if (area_sta[j][i] == 8) area_sta[j][i] = 7; // ◇→◆
}
}
}
public void check_nextclear() {
for (byte i = 0; i < 5; i++)
for (byte j = 0; j < x_atoms[i]; j++)
if (next_clear[j][i]) {
// 黄色く囲む
G.setColor(Graphics.getColorOfName(Graphics.YELLOW));
G.fillRect(posX(i), posY(j) -12, 14, 12);
// 囲まれた部分の文字
G.setColor(Graphics.getColorOfName(Graphics.BLACK));
G.drawString(atom_char[ area_sta[j][i] ], posX(i), posY(j));
area_sta[j][i] = 0;
next_clear[j][i] = false;
// ◆ → C , ◇ → ◆
byte[] c_change = {8, 7, 2}; // 炭素の変化順を示した配列
for (int k = 1; k >=0; k--) {
if (i < 4)
if (area_sta[j][i+1] == c_change[k]) {
area_sta[j][i+1] = c_change[k+1];
Score += 5;
}
if (i > 0)
if (area_sta[j][i-1] == c_change[k]) {
area_sta[j][i-1] = c_change[k+1];
Score += 5;
}
if (j < 7)
if (area_sta[j+1][i] == c_change[k]) {
area_sta[j+1][i] = c_change[k+1];
Score += 5;
}
if (j > 0)
if (area_sta[j-1][i] == c_change[k]) {
area_sta[j-1][i] = c_change[k+1];
Score += 5;
}
}
}
// 全消し判定
boolean is_Zen = true;
for (int i=0; i<5; i++)
is_Zen = is_Zen & (x_atoms[i]==0);
if (is_Zen) { // 全消し
delay(1000);
G.setColor(Graphics.getColorOfName(Graphics.BLUE));
G.fillRect(8, 0, 104, 12);
G.setColor(Graphics.getColorOfName(Graphics.WHITE));
G.drawString("全消し", 8, 12);
Score += 100;
}
delay(1000);
}
public void fall_space() {
for (byte i = 0; i < 5; i++)
for (byte j = 0; j < x_atoms[i]; j++)
while (area_sta[j][i] == 0 && j < x_atoms[i]) { // 空白がある限り
for (byte k = j; k < x_atoms[i]-1; k++)
area_sta[k][i] = area_sta[k+1][i]; // 一つずつ下に詰める
area_sta[ x_atoms[i]-1 ][i] = 0;
x_atoms[i] --;
}
}
public void Pause() {
paused = !paused;
if (paused) {
timDropper.stop(); // タイマーを止める。
G.setColor(Graphics.getColorOfName(Graphics.BLACK));
G.fillRect(8, 15, 71, 105);
G.setColor(Graphics.getColorOfName(Graphics.WHITE));
G.drawString("ゲーム", 20, 38);
G.drawString("停止中", 20, 50);
G.drawString("\ue6eb リセット", 20, 100);
setSoftLabel(SOFT_KEY_1, "再開");
}
else {
flag = 10; paint(G); // 全体を描画
flag = 12; paint(G); // フラグを戻して描画
// プログラムの神様!フラグを勝手にいじったことをどうかお許しを(笑)
timDropper.start(); // タイマーを動かし一件落着!
setSoftLabel(SOFT_KEY_1, "停止");
}
}
public void data_reset() {
Dialog dlg = new Dialog(Dialog.DIALOG_YESNO, "よろしいですか?");
dlg.setText("ハイスコアデータを削除します。復活はできません。");
if (dlg.show() == Dialog.BUTTON_YES) {
HighScore = 1000;
MinTime = 3599000;
}
repaint();
renew_record();
}
public void chgFlag(int f) {
// フラグの管理は全体の中枢☆(微妙に意味不明 ^^;)
/* フラグの意味
0: タイトル
3: バージョン
10: ゲーム画面初期化
11: 元素落下
12: 元素描画
*/
flag = f;
if (f == 0) {
setSoftLabel(SOFT_KEY_1, "");
setSoftLabel(SOFT_KEY_2, "終了");
}
else if (f == 3) {
setSoftLabel(SOFT_KEY_1, "戻る");
setSoftLabel(SOFT_KEY_2, "ショキカ");
}
else if (f == 10) {
setSoftLabel(SOFT_KEY_1, "停止");
setSoftLabel(SOFT_KEY_2, "");
gameStart();
}
repaint();
}
public void paint(Graphics g) {
switch (flag) {
case 0:
g.clearRect(0, 0, 120, 130);
g.setColor(0);
g.drawString("物 質 作 成", 6, 12);
g.drawString("-分子ができるよ-", 14, 26);
g.drawString("(c)2003", 74, 109);
g.drawString("about&キロク \ue6eb", 42, 120);
g.drawImage(img, 44, 34);
g.drawString("\ue6e2 = フリ-モード", 10, 78);
g.drawString("\ue6e3 = タイムアタック", 10, 90);
break;
case 3:
long time = MinTime / 1000;
long min = time / 60;
long sec = time % 60;
g.clearRect(0, 0, 120, 130);
g.drawString("物 質 作 成", 6, 12);
g.drawString("Version " + bunshi.VERSION, 14, 24);
g.drawRect( 4,30, 112,46 );
g.drawString("[キロク]", 6, 46);
g.drawString("フリーモード: " + HighScore, 14, 60);
g.drawString("タイムアタック: " + min + "分" + sec + "秒", 14, 72);
g.drawString("Push Soft_1 key !", 10, 92);
g.drawString("制作 Si_Densetsu", 4, 108);
g.drawString("原案 えいちつ〜お〜", 4, 120);
break;
case 10: // ゲーム画面初期化
case 11: // 落下後の処理
g.lock();
g.setColor(Graphics.getColorOfName(Graphics.LIME));
g.fillRect(0, 0, 120, 130);
g.setColor(Graphics.getColorOfName(Graphics.BLACK));
g.drawRect(7, 14, 72, 106);
// g.drawRect(98, 18, 19, 27);
g.setColor(Graphics.getColorOfName(Graphics.WHITE));
g.fillRect(8, 15, 71, 105);
g.setColor(Graphics.getColorOfName(Graphics.YELLOW));
g.fillRect(82, 19, 20, 26);
g.setColor(Graphics.getColorOfName(Graphics.BLACK));
g.drawString(Integer.toString(rensa) + "連鎖", 90, 64);
g.drawString("E " + Integer.toString(energy), 80, 78);
g.drawString("抑 " + Integer.toString(fallRes), 80, 90);
g.drawString("Score ", 82, 104);
g.drawString("次", 84, 31);
g.drawString(atom_char[next_atom], 89, 43);
g.drawString(Long.toString(Score), 82, 116);
for (byte i = 0; i < 5; i++ )
for (byte j = 7; j >= 0; j-- )
if (area_sta[j][i] != 0) {
byte atm = area_sta[j][i];
g.setColor( Graphics.getColorOfName( atom_color[atm] ) );
g.drawString(atom_char[ atm ], posX(i), posY(j));
}
g.unlock(true);
break;
case 12: // 原子部分描画
if (old_x != -1) { // まず前の位置を消去
g.setColor(Graphics.getColorOfName(Graphics.WHITE));
g.fillRect(posX(old_x), posY(old_y) - 12, 14, 12);
}
g.setColor( Graphics.getColorOfName( atom_color[mov_atom] ) );
g.drawString(atom_char[ mov_atom ], posX(mov_x), posY(mov_y));
}
}
public void processEvent(int type, int param) {
if (type == Display.KEY_PRESSED_EVENT) {
if (param == Display.KEY_POUND) { // #キー
f_light = 1 - f_light; // 1と0とを行ったりきたり!
PhoneSystem.setAttribute(0, f_light); // 照明をON/OFF
}
if ( flag == 0) {
mode = 0; // 仮にモードをフリーにする。
if (param == Display.KEY_0)
chgFlag(3); // バージョン情報
if (param == Display.KEY_2)
mode = 1; // TimeAttackモードにする。
if (param == Display.KEY_1 || param == Display.KEY_2)
chgFlag(10); // ゲーム開始
if (param == Display.KEY_SOFT2)
IApplication.getCurrentApp().terminate(); // 終了
}
// バージョン情報・記録
if (flag == 3) {
if (param == Display.KEY_SOFT1)
reset();
else if (param == Display.KEY_SOFT2)
data_reset();
}
if (flag == 12) {
if (param == Display.KEY_SOFT1) { // Soft1はポーズ
Pause();
}
if (paused) {
if ( param == Display.KEY_0 ) { // ポーズ中[0]を押したらリセット。
reset();
}
}
// 以下,ポーズ中でない。
else {
if ( param == Display.KEY_LEFT )
if (mov_x > 0 && x_atoms[mov_x -1] <= mov_y) {
old_x = mov_x;
old_y = mov_y;
mov_x--;
repaint();
}
if ( param == Display.KEY_RIGHT )
if (mov_x < 4 && x_atoms[mov_x +1] <= mov_y) {
old_x = mov_x;
old_y = mov_y;
mov_x++;
repaint();
}
if ( param == Display.KEY_DOWN) {
Score++;
drop();
}
if ( param == Display.KEY_SELECT) {
Score += 15;
if (fallRes < 100) fallRes++; // 勇気ある人にはおまけ ^^;
old_x = mov_x;
old_y = mov_y;
mov_y = x_atoms[mov_x];
atom_land();
}
if ( param == Display.KEY_4 ) { // エネルギーが得点に
G.setColor(Graphics.getColorOfName(Graphics.BLACK));
G.drawString("エネルギーが得点に!", 8, 12);
Score += energy * energy / 25;
energy = 0;
}
}
}
if (flag == 12 && paused) {
}
}
}
public void timerExpired(Timer tm) {
if (flag == 12)
drop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment