このブログを検索

2019年9月7日土曜日

Java入門教室

「Java入門教室」

 やっと、この本 最後まで読みました。
 「入門教室」なんて 言っているのに、
 すごく難しい内容です。
 ただ、繰り返し学習しよう。
 
 そしていつか 楽しいゲームを作ろう。

 最後に この作者のメッセージを読んで、
 グッときた。

 


 とにかく、自分の作りたいものを つくろう。
 完成させよう。

息子がMiniRPGを ゲラゲラ笑いながら 遊んでた。


今日の教訓
 著者様、ありがとうございます。
 無断掲載 ごめんなさい。

2019年9月6日金曜日

Java入門教室 Lesson14-10「ミニゲームを作る」(出来た)③

「Java入門教室」

 この本の一番最後のサンプルプログラム。
 「Javaの技術の集大成 ミニゲームを作る」

 無事に動いた。



 はっきり言って、全く意味の解らない、
 プログラムを黙々と PCに打ち込んでいるのは、
 退屈な作業。

 この本には プログラムの構成を 解りやすく
 説明をしているんだけど、
 まだ、よく解らないまま。

 ただ、「今はまだ」なんだ。

 もっと、手を動かして学習すれば、
 読める様lになるんだろう。

 繰り返して、勉強しよう。

今日の教訓
 整数の乱数を返すメソッドが あった
 早速、パクってみよう。

2019年9月5日木曜日

Java入門教室 Lesson14-10「ミニゲームを作る」②

「Java入門教室」

 この本の一番最後のサンプルプログラム。
 何と 230行!!
 全て、打ち込んでみた。

 んでもって、コンパイル!!



  ウヒョー エラー 15個
 (o´・ω-)b
 

今日の教訓
 想像していた 個数より少なかったぞ〜!!

2019年9月4日水曜日

Java入門教室 Lesson14-10「ミニゲームを作る」①

「Java入門教室」

 この本の一番最後のサンプルプログラム。
 何と 230行!!
 とりあえず、自分で打ち込んでみよう。
 (ダウンロードは出来るけどさっ)

 この感覚、
 
 遥か昔、中学生だった頃、
 ベーシックマガジン(略して ベーマガ)を見ながら、
 ポチポチ おもちゃの様な マイコン(パソコンという言い方は当時なかった)に
 BASICを打ち込んでいた自分をふと 思い出した。

 そーいえば、自分でゲームを作ったな。

 ふと、感傷的になりました。

 とりあえず、全部 打ち込んでみるのだ
 (まだ、48行目)

今日の教訓
 つまり、昔の自分のまんまなんだな。。。

2019年9月3日火曜日

アホ男子に 割り算プログラムを やらせてみた。

アホ男子 の為の 割り算学習プログラム。
 
 実際に 我が家のアホ男子に 割り算をさせてみた。





 結構 無反応! (字は きたないし・・・)


今日の教訓
 ( ノ゚∀゚)ノ

2019年9月2日月曜日

アホ男子のための 割り算 問題 学習プログラム(とりあえず完成)

アホ男子 の為の 割り算学習プログラム。
 
 5問の 割り算問題を出題して、
 ◯ ×で 答える プログラム。
 正解数を表示出来る様になった。
 とりあえず これで完成。


 今後、少しずつ 改良させよう。

 改良点とは
  問題作成部と 判断部分を 他のクラスにする(他の教科でも使いやすくする)
  正解数によってコメントを変えてみる。
  「正解数は◯問です」ではなく、⭐︎にて表示を行う。
  間違いの出題数の調整。
  コマンドライン引数で 出題レベルの入力を行う。
  スレッドで タイマーをかける。

 改良点のうち 調整のレベルのものもあれば、
 どうして良いものか解らない ものもある。
 頑張ろう!!
 
⭐️ とりま 完成。

//◯新しくLabelを作る。
//◯Buttonの反応部を // にする。
//◯Labelを反応させる。
//◯Lavelに正解数を表示させる。
//問題作成部と 判断部分を 他のクラスにする(他の教科でも使いやすくする)
//正解数によってコメントを変えてみる。
// 「正解数は◯問です」ではなく、⭐︎にて表示を行う。
//間違いの出題数の調整。
//コマンドライン引数で レベルの入力を行う。
//スレッドで タイマーをかける。
import java.awt.*;
import java.awt.event.*;
class Count2{
    public static void main(String[] args){
        MyWindow mw = new MyWindow();
    }
}

class MyWindow extends Frame implements ActionListener{
    Label la1, la2;
    Button btn1, btn2;
    int moto; //割られる数値です。
    int waru; //割る数値です。
    int ans; //答え
    int amari; //答え(あまり)
    static int count = 1; //出題数
    static int Correct_answer; //正解数
    MyWindow(){
        setTitle("問題集");
        setSize(640, 400);
        setLayout(null); //レイアウトの解除
        btn1 = new Button("◯");
        btn2 = new Button("×");
        btn1.setBounds(100, 300, 150, 80);
        btn2.setBounds(400, 300, 150, 80);
        btn1.addActionListener(this);
        btn2.addActionListener(this);
        add(btn1);
        add(btn2);
        la1 = new Label( questions() );
        la1.setFont(new Font("Serif", Font.PLAIN, 34));
        la1.setAlignment(Label.CENTER);
        la1.setBackground(Color.LIGHT_GRAY); //Label 1 背景色
        la1.setForeground(Color.BLACK);  //Label 文字色
        la1.setBounds(100, 100, 450, 50);
        add(la1);
        la2 = new Label("割 り 算 の テ ス ト");
        //la2 = setFont(new Font("Serif", Font.BOLD, 24));
        la2.setAlignment(Label.CENTER);
        la2.setBackground(Color.LIGHT_GRAY); //Label 2 背景色
        la2.setForeground(Color.darkGray);  //Label 2 文字色
        la2.setBounds(150, 180, 350, 50);
        add(la2);
        setVisible(true);
        addWindowListener( new WinListener() );
    }
    
    public String questions(){
        waru = (int)(Math.random()*29)+2; //割る数値(2〜30)
        ans = (int)(Math.random()*9)+1; //答え(1〜9)
        amari = (int)(Math.random()*(waru-1))+1; //あまりの数値(1〜割る数値−1)
        moto = waru * ans + amari; //割られる数値
        System.out.println(moto + " ÷ " + waru + " = " + ans + " ... " + amari);//験算用
        btn1.setLabel("◯");
        btn2.setLabel("×");
        int ran1 = (int)(Math.random()*2); //間違いの発生 確率50% ただし 変数に0を加算する事もある。
        if(ran1 == 0){
            int ran2 = (int)(Math.random()*3);
            if(ran2 == 0){
                int falseAmari = (int)(Math.random()*3);
                falseAmari -= 1;
                amari = amari + falseAmari; // あまりに -1,0,1 を加算
            }
            else{
                int falsewaru = (int)(Math.random()*2);
                ans = ans + falsewaru; // 商に 0,1 を加算
            }
        }
            
        return moto + " ÷ " + waru + " = " + ans + " ... " + amari;
    }
    
    public boolean judgment(){
        return moto/waru==ans && moto%waru==amari; //答えと 余りの判定。booleanにて返す。
    }
    
    
    public void actionPerformed(ActionEvent e){
        if(e.getSource() == btn1) {
            if(judgment() == true){
                //btn1.setLabel("正解 !");
                la2.setText("正解だよ !");
                Correct_answer++;
                countCalculation();
            }
            else{
                //btn1.setLabel("違っているよ !");
                la2.setText("違っているよ !");
                countCalculation();
            }
        }
        if(e.getSource() == btn2) {
            if(judgment() == false){
                //btn2.setLabel("正解 !");
                la2.setText("正解だよ !");
                Correct_answer++;
                countCalculation();
            }
            else{
                //btn2.setLabel("違っているよ !");
                la2.setText("違っているよ !");
                countCalculation();
            }
        }
    }
    
    public void countCalculation(){
        try { Thread.sleep(2000); } catch (InterruptedException e) {} // 2秒間だけ処理を止める
        System.out.println(count + "回目"); //試験用
        count++;
        if(count <= 5){  //5回で終了。
            la1.setText( questions() ); //ラベルの表示の書き換え questions() メソッドへ
        }
        else{
            la1.setText("よく 頑張ったね !!");
            la2.setText("正解数は" + Correct_answer + "問です。");
            //System.out.println("お疲れ様でした。");
            //System.out.println("正解数は" + Correct_answer + "問です。");
        }
    }
}

class WinListener extends WindowAdapter{
    public void windowClosing(WindowEvent e){System.exit(0);}

}


今日の教訓
 とりあえず 完成。
 (人゚∀゚*) 

2019年9月1日日曜日

アホ男子のための 割り算 問題 学習プログラム(作成中)⑨

アホ男子 の為の 割り算学習プログラム。
 
 新たに作った Label に 合っているのか、間違っているのか 表示 。


 
⭐️ Label に 正誤の表示。

//◯5回出題させてみよう
//×表示の不具合を治す。
//◯新しくLabelを作る。
//◯Buttonの反応部を // にする。
//◯Labelを反応させる。
import java.awt.*;
import java.awt.event.*;
class Display3{
    public static void main(String[] args){
        MyWindow mw = new MyWindow();
    }
}

class MyWindow extends Frame implements ActionListener{
    Label la1, la2;
    Button btn1, btn2;
    int moto; //割られる数値です。
    int waru; //割る数値です。
    int ans; //答え
    int amari; //答え(あまり)
    static int count = 1;
    static int seikai;
    MyWindow(){
        setTitle("問題集");
        setSize(640, 400);
        setLayout(null); //レイアウトの解除
        btn1 = new Button("◯");
        btn2 = new Button("×");
        btn1.setBounds(100, 300, 150, 80);
        btn2.setBounds(400, 300, 150, 80);
        btn1.addActionListener(this);
        btn2.addActionListener(this);
        add(btn1);
        add(btn2);
        la1 = new Label( questions() );
        la1.setFont(new Font("Serif", Font.PLAIN, 34));
        la1.setAlignment(Label.CENTER);
        la1.setBackground(Color.LIGHT_GRAY); //Label 1 背景色
        la1.setForeground(Color.BLACK);  //Label 文字色
        la1.setBounds(100, 100, 450, 50);
        add(la1);
        la2 = new Label("割 り 算 の テ ス ト");
        //la2 = setFont(new Font("Serif", Font.BOLD, 24));
        la2.setAlignment(Label.CENTER);
        la2.setBackground(Color.LIGHT_GRAY); //Label 2 背景色
        la2.setForeground(Color.darkGray);  //Label 2 文字色
        la2.setBounds(150, 180, 350, 50);
        add(la2);
        setVisible(true);
        addWindowListener( new WinListener() );
    }
    
    public String questions(){
        waru = (int)(Math.random()*29)+2; //割る数値(2〜30)
        ans = (int)(Math.random()*9)+1; //答え(1〜9)
        amari = (int)(Math.random()*(waru-1))+1; //あまりの数値(1〜割る数値−1)
        moto = waru * ans + amari; //割られる数値
        System.out.println(moto + " ÷ " + waru + " = " + ans + " ... " + amari);//験算用
        btn1.setLabel("◯");
        btn2.setLabel("×");
        int ran1 = (int)(Math.random()*2); //間違いの発生 確率50% ただし 変数に0を加算する事もある。
        if(ran1 == 0){
            int ran2 = (int)(Math.random()*3);
            if(ran2 == 0){
                int falseAmari = (int)(Math.random()*3);
                falseAmari -= 1;
                amari = amari + falseAmari; // あまりに -1,0,1 を加算
            }
            else{
                int falsewaru = (int)(Math.random()*2);
                ans = ans + falsewaru; // 商に 0,1 を加算
            }
        }
            
        return moto + " ÷ " + waru + " = " + ans + " ... " + amari;
    }
    
    public boolean judgment(){
        return moto/waru==ans && moto%waru==amari; //答えと 余りの判定。booleanにて返す。
    }
    
    
    public void actionPerformed(ActionEvent e){
        if(e.getSource() == btn1) {
            if(judgment() == true){
                //btn1.setLabel("正解 !");
                la2.setText("正解だよ !");
                countCalculation();
            }
            else{
                //btn1.setLabel("違っているよ !");
                la2.setText("違っているよ !");
                countCalculation();
            }
        }
        if(e.getSource() == btn2) {
            if(judgment() == false){
                //btn2.setLabel("正解 !");
                la2.setText("正解だよ !");
                countCalculation();
            }
            else{
                //btn2.setLabel("違っているよ !");
                la2.setText("違っているよ !");
                countCalculation();
            }
        }
    }
    
    public void countCalculation(){
        try { Thread.sleep(2000); } catch (InterruptedException e) {} // 2秒間だけ処理を止める
        System.out.println(count + "回目"); //試験用
        count++;
        if(count <= 5){  //5回で終了。
            la1.setText( questions() ); //ラベルの表示の書き換え questions() メソッドへ
        }
        else{
            System.out.println("お疲れ様でした。");
        }
    }
}

class WinListener extends WindowAdapter{
    public void windowClosing(WindowEvent e){System.exit(0);}

}


次は正解数を表示するのだ。


今日の教訓

 以外にスムーズに でけた。