A 回答 (2件)
- 最新から表示
- 回答順に表示
No.2
- 回答日時:
以下は、思考ルーチンを除いた三目並べの例です。
import java.awt.*;
import java.awt.event.*;
public class sanmoku extends Frame implements ActionListener {
private Button B[];
private Label ML;
private boolean F;
public sanmoku() { super("Sanmoku Narabe");
int i;
setSize(200, 200);
Panel P = new Panel(new GridLayout(10, 10));
add(P, BorderLayout.CENTER);
for (i = 0, B = new Button[100]; i < 100; i ++) {
B[i] = new Button();
B[i].addActionListener(this);
B[i].setActionCommand(Integer.toString(i));
P.add(B[i]);
};
ML = new Label();
add(ML, BorderLayout.SOUTH);
F = true;
};
synchronized boolean SetF(boolean nf) {
boolean of = F;
F = nf;
return(of);
};
public void actionPerformed(ActionEvent ae) {
int n, i;
if (!SetF(false)) return;
try {
n = Integer.parseInt(ae.getActionCommand());
if ((n>=0) && (n<100)) if (B[n].getLabel().length()==0) {
B[n].setLabel("o");
if (WinCheck(n, "o")) {
ML.setText("You Win");
return;
}
else {
n=(int)(Math.random()*100.0);
for (i=0;i<100;i++,n++) if (B[++n>=100?n=0:n].getLabel().length()==0) break;
if (i==100) {
ML.setText("Even");
return;
};
B[n].setLabel("x");
if (WinCheck(n, "x")) {
ML.setText("I Win");
return;
};
};
};
} catch (Exception e) {};
SetF(true);
};
private static final int CI[][] = {{-2,-1,1,2},{-40,-20,20,40},{-42,-21,21,42},{-38,-19,19,38}};
private boolean WinCheck(int n, String s) {
int i, j, k, l;
for (l=0;l<4;l++) for (k=0;k<3;k++) {
for (i=k;i<k+2;i++) {
j=n/10*20+n%10+CI[l][i];
if ((j<0) || (j>=200) || (((j/10)%2) != 0)) break;
if (s.compareTo(B[j/20*10+j%10].getLabel()) != 0) break;
};
if (i==(k+2)) return(true);
};
return(false);
};
public static void main(String args[]) {
sanmoku S = new sanmoku();
S.setVisible(true);
};
}
No.1
- 回答日時:
TicTacToeは、sunの開発キット(sdk)中に
「アプレット・デモ」
として付属してますよ。
sunのサイトでも公開されてます。
http://java.sun.com/j2se/1.4/ja/docs/ja/relnotes …
参考URL:http://java.sun.com/j2se/1.4/ja/docs/ja/relnotes …
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
このQ&Aを見た人はこんなQ&Aも見ています
-
ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
高校生はアルバイトするべきだろうか?賛成だったら「賛」、否定だったら「否」を文頭においてあなたの意見を教えてください。
-
フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
あなたが普段思っている「これまだ誰も言ってなかったけど共感されるだろうな」というあるあるを教えてください
-
映画のエンドロール観る派?観ない派?
映画が終わった後、すぐに席を立って帰る方もちらほら見かけます。皆さんはエンドロールの最後まで観ていきますか?
-
海外旅行から帰ってきたら、まず何を食べる?
帰国して1番食べたくなるもの、食べたくなるだろうなと思うもの、皆さんはありますか?
-
天使と悪魔選手権
悪魔がこんなささやきをしていたら、天使のあなたはなんと言って止めますか?
-
Javaでの三目並べのソースコード
Java
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
- ・ゆるやかでぃべーと タイムマシンを破壊すべきか。
- ・歩いた自慢大会
- ・許せない心理テスト
- ・字面がカッコいい英単語
- ・これ何て呼びますか Part2
- ・人生で一番思い出に残ってる靴
- ・ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
- ・初めて自分の家と他人の家が違う、と意識した時
- ・単二電池
- ・チョコミントアイス
このQ&Aを見た人がよく見るQ&A
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
C++からC#のdllを参照する際、...
-
DataSet(DataTable)の使い方
-
「配列定数は、イニシャライザ...
-
【C#】フォームをなめらかに移動
-
javaでcsvファイル読込時の改行...
-
JUnit4のアノテーションについて
-
intが負の時に投げる例外はあり...
-
式の型は配列型で int に解決済...
-
c# デリゲート関連の命名について
-
Java画像表示など
-
JTableのセルの背景色について
-
[c++]メンバ配列での要素数省略
-
SwingでJtableのヘッダ行が表示...
-
javaのプログラムで、forの文が...
-
6桁の数字を重複なしでランダム...
-
書式で分からないところがある...
-
Path型をString型へ変換する(Java)
-
JSPやサーブレットでSystem.out...
-
Java配列でNullPointerExceptio...
-
System.err. printlnとSystem.o...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
「配列定数は、イニシャライザ...
-
java spring でエラーが出て困...
-
Java 初心者 int型の取り扱い方
-
式の型は配列型で int に解決済...
-
DataSet(DataTable)の使い方
-
C#で、デリゲートからその関数...
-
6桁の数字を重複なしでランダム...
-
C#で実行時にメソッドの返り値...
-
JUnit4のアノテーションについて
-
行の途中から読み込む方法
-
Javaで電卓を作りたい
-
SwingでJtableのヘッダ行が表示...
-
javaでcsvファイル読込時の改行...
-
javaでカレンダー作成
-
ビープ音をなめらかに鳴らしたい
-
c# デリゲート関連の命名について
-
intが負の時に投げる例外はあり...
-
java 長さの異なる配列の代入
-
デスクトップのアイコンの位置...
-
【C#】フォームをなめらかに移動
おすすめ情報