JARUJARU

12/01

前回の記事でピンポンパンポンピンクラスを
作ったのだが、今度はジャルジャルクラスも
作ってみた。

若干ピンポンパンポンピンクラスの
メソッドの位置を変更している。

class PingPongPangPongPing {
	constructor(){
		this.relative=null;
		this.value=null;
		this.pingtime=0;
		this.previouscalled=null;
	}

	answer(relative){
		if(relative=="lookssmart"
			&&this.previouscalled=="ping"){
			this.pingtime++;
			if(this.pingtime>3){
				relative="looksgreat";
				this.pingtime=0;
			}
		}else{ 
			this.pingtime=0; 
		}
		eval("this."+relative+"()");
		this.previouscalled=this.relative;
		return this.value; 
	}
	
	looksgreat(){
		//is it correct?
		this.relative=null;
		this.value="背筋伸び切ってるやん";
		return this.value; 
	} 

	remaining(){
		this.relative="pingpongpangpongping";
		this.value="一個多いな";
		return this.value; 
	} 

	shortening(){
		this.relative="pingpongpang";
		this.value="一個少ないな"; 
		return this.value; 
	}

	breadorrice(){
		this.relative="pingpongpangrice";
		this.value="いやファミレス行って~聞かれてるやん";
		return this.value; 
	} 
	
	lookssmart(){
		this.relative="ping"; 
		this.value="背筋伸びてるやん";
		return this.value;
	} 

	whoisit(){
		this.relative="pingpong";
		this.value="誰か来ましたよー";
		return this.value; 
	} 

	somebodyscomingwho(){
		this.relative="pongping";
		this.value="来ましたよー誰かー";
		return this.value; 
	}
	
	pingpongpangpongping(){
		this.relative="remaining";
		this.value="ピンポンパンポンピーン";
		return this.value; 
	} 

	pingpongpang(){
		this.relative="shortening";
		this.value="ピンポンパーン";
		return this.value; 
	} 

	pingpongpangrice(){
		this.relative="breadorrice";
		this.value="ピンポンパーンライス";
		return this.value;
	} 

	pingpong(){ 
		this.relative="whoisit"; 
		this.value="ピーンポーン";
		return this.value;
	} 

	pongping(){
		this.relative="somebodyscomingwho"; 
		this.value="ポーンピーン"; 
		return this.value; 
	} 

	ping(){
		this.relative="lookssmart"; 
		this.value="ピーン"; 
		return this.value; 
	} 
}

前回のを若干修正。
そして今回新たにジャルジャルクラスを作った。

class JARUJARU extends PingPongPangPongPing {

	constructor(){
		super();
		this.methods=Object.getOwnPropertyNames(PingPongPangPongPing.prototype);
		this.methods.shift();
		this.methods.shift();
		this.methods.shift();
	}

	boke(){
		let rand=Math.round(Math.random()*(this.methods.length-1));
		let ret=eval("super."+this.methods[rand]+"();");
		return ret;
	}
	
	tsukkomi(boke){
		return super.answer(boke);
	}
}

これの使い方は前回よりも簡単。

var fukutoku=new JARUJARU;
var gotoh=new JARUJARU;
  
console.log(fukutoku.boke());
console.log(gotoh.tsukkomi(fukutoku.relative));

これでボケがランダムになったので
ジャルジャルワールドがこれでもかと
堪能できる仕組み。
名前も足して大量に出力してみた。

福徳:一個少ないな
後藤:ピンポンパーン
福徳:一個少ないな
後藤:ピンポンパーン
福徳:いやファミレス行って~聞かれてるやん
後藤:ピンポンパーンライス
福徳:背筋伸びてるやん
後藤:ピーン
福徳:ピンポンパーンライス
後藤:いやファミレス行って~聞かれてるやん
福徳:誰か来ましたよー
後藤:ピーンポーン
福徳:ピーンポーン
後藤:誰か来ましたよー
福徳:ピンポンパーンライス
後藤:いやファミレス行って~聞かれてるやん
福徳:ピーンポーン
後藤:誰か来ましたよー
福徳:ピーン
後藤:背筋伸びてるやん
福徳:いやファミレス行って~聞かれてるやん
後藤:ピンポンパーンライス
福徳:ピンポンパーン
後藤:一個少ないな
福徳:来ましたよー誰かー
後藤:ポーンピーン
福徳:背筋伸びてるやん
後藤:ピーン
福徳:来ましたよー誰かー
後藤:ポーンピーン
福徳:誰か来ましたよー
後藤:ピーンポーン 

後藤が優秀(笑)


コメント: