じゃんけんシミュ
♥0 |
Line 305 |
Modified 2010-08-10 23:53:37 |
MIT License
archived:2017-03-20 15:54:35
ActionScript3 source code
/**
* Copyright YAZUMA ( http://wonderfl.net/user/YAZUMA )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hoj4
*/
package
{
import flash.display.*;
import flash.text.*;
import flash.net.URLRequest;
import flash.events.*;
import flash.utils.Timer;
[SWF(backgroundColor=0x0,width=400,height=400,frameRate=60)]
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
public class janken extends Sprite
{
public var NPC:int = 0;
public var PC:int = 0;
public var guu:int = 0;
public var choki:int = 0;
public var paa:int = 0;
public var counter:int = 0;
public var super_counter:int = 0;
public var double:int = 0;
public var beforehand:int = 0;
public var beforehand2:int = 0;
public var beforehandPC:int = 0;
public var beforehandPC2:int = 0;
public var jadgement:int;
public var win:int;
public var lose:int;
public var drow:int;
public var time:int = 0;
public var jann:int = 0;
public var s:Sprite = new Sprite;
public var s2:Sprite = new Sprite;
public var uRLRequest:URLRequest;
public var loader:Loader = new Loader();
public var loader2:Loader = new Loader();
public var loader3:Loader = new Loader();
public var loader4:Loader = new Loader();
public var textbox:TextField = new TextField();
public var outputBox:TextField = new TextField();
public var nowtime:TextField = new TextField();
public var jadgebox:TextField = new TextField();
public var parcentage:TextField = new TextField();
public var mode:TextField = new TextField();
public var lebel:TextField = new TextField();
public var jadgeformat:TextFormat = new TextFormat("HGS創英角ゴシックUB", 20);
public var text:String = "ココに試行回数を入力";
public var myTimer:Timer;
public function janken():void {
addChild(s);
textbox.type = TextFieldType.INPUT;
textbox.maxChars = 3;
textbox.restrict = "0-9";
textbox.background = true;
textbox.width = 150;
textbox.height = 30;
textbox.x = 10;
textbox.y = 10;
textbox.textColor = 0x6A5ACD;
addChild(textbox);
textbox.text = text;
textbox.addEventListener(Event.CHANGE, textInputCapture);
textbox.addEventListener(MouseEvent.CLICK, click_text);
outputBox.background = true;
//outputBox.text = textbox.text+"回ジャンケンします";
outputBox.x = 10;
outputBox.y = 25;
outputBox.width = 150;
outputBox.height = 30;
nowtime.background = true;
nowtime.x = 10;
nowtime.y = 40;
nowtime.height = 30;
jadgebox.background = true;
jadgebox.x = 380;
jadgebox.y = 10;
jadgebox.height = 45;
jadgebox.width = 100;
jadgebox.textColor = 0x0f0f00;
jadgebox.defaultTextFormat = jadgeformat;
jadgebox.antiAliasType = "flash.text.AntiAliasType.ADVANCED";
parcentage.background = true;
parcentage.x = 383;
parcentage.y = 35;
parcentage.width = 75;
parcentage.height = 30;
mode.background = true;
mode.x = 190;
mode.y = 10;
mode.height = 18;
mode.width = 70;
mode.text = "Manual mode";
mode.textColor = 0x9ACD32;
mode.addEventListener(MouseEvent.CLICK, change_mode);
addChild(mode);
lebel.background = true;
lebel.x = 205;
lebel.y = 35;
lebel.height = 18;
lebel.width = 70;
lebel.text = "Easy";
lebel.textColor = 0x1E90FF;
lebel.addEventListener(MouseEvent.CLICK, change_lebel);
addChild(lebel);
}
//画像表示
public function handmaker():void{
jann++;
NPC = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
NPC = NPC % 3;
if(lebel.text == "Hard" && jann > time / 10)hard_lebel();
if (NPC==0){
uRLRequest = new URLRequest("http://trt.up.seesaa.net/image/goo-02.gif");
}else if(NPC ==1){
uRLRequest = new URLRequest("http://trt.up.seesaa.net/image/cyoki-02.gif");
}else{
uRLRequest = new URLRequest("http://trt.up.seesaa.net/image/paa-02.gif");
}
if(jann > 0)beforehand2 = beforehand;
beforehand = NPC;
configureListeners(loader.contentLoaderInfo);
loader.load(uRLRequest);
nowtime.text = jann + "/" + time;
//if (jann == time)myTimer.stop();
}
public function configureListeners(dispatcher:IEventDispatcher):void{
//縮小表示
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
}
public function completeHandler(evt:Event):void{
loader.width = 200;
loader.height = 200;
loader.x = 130;
loader.y = 100;
s.graphics.clear();
s.addChild(loader);
addChild(s);
}
public function handmaker2(request:URLRequest,request2:URLRequest,request3:URLRequest):void{
configureListeners2(loader2.contentLoaderInfo);
loader2.load(request);
configureListeners2(loader3.contentLoaderInfo);
loader3.load(request2);
configureListeners2(loader4.contentLoaderInfo);
loader4.load(request3);
loader2.addEventListener(MouseEvent.CLICK, loader2_click);
loader3.addEventListener(MouseEvent.CLICK, loader3_click);
loader4.addEventListener(MouseEvent.CLICK, loader4_click);
}
public function loader2_click(evt:MouseEvent):void{
if(jann < time){
handmaker();
PC = 0;
guu++;
jadge();
}
}
public function loader3_click(evt:MouseEvent):void{
if(jann < time){
handmaker();
PC = 1;
choki++;
jadge();
}
}
public function loader4_click(evt:MouseEvent):void{
if(jann < time){
handmaker();
PC = 2;
paa++;
jadge();
}
}
public function configureListeners2(dispatcher:IEventDispatcher):void{
//縮小表示
dispatcher.addEventListener(Event.COMPLETE, completeHandler2);
}
public function completeHandler2(evt:Event):void{
loader2.width = 100;
loader2.height = 100;
loader2.x = 30;
loader2.y = 340;
addChild(loader2);
loader3.width = 100;
loader3.height = 100;
loader3.x = 180;
loader3.y = 340;
addChild(loader3);
loader4.width = 100;
loader4.height = 100;
loader4.x = 330;
loader4.y = 340;
addChild(loader4);
}
//以下試行回数入力テキストボックス用
public function textInputCapture(event:Event):void{
var str:String = textbox.text;
createOutBox(str);
jann = 0;
win = 0;
lose = 0;
drow = 0;
guu = 0;choki = 0;paa = 0;double = 0;
removeChild(s);
jadgebox.text = "";
if(mode.text == "Auto mode")auto_mode();
}
public function click_text(event:MouseEvent):void{
textbox.text = "";
jann = 0;
time = 0;
parcentage.text = "勝率:0%";
}
public function change_mode(event:MouseEvent):void{
if(mode.text == "Manual mode"){
mode.textColor = 0xF4A460;
mode.text = "Auto mode";
auto_mode();
}else{
mode.textColor = 0x9ACD32;
mode.text = "Manual mode";
}
}
public function change_lebel(event:MouseEvent):void{
if(lebel.text == "Easy"){
lebel.textColor = 0xDC143C;
lebel.text = "Hard";
}else{
lebel.textColor = 0x1E90FF;
lebel.text = "Easy";
}
}
public function createOutBox(str:String):void{
outputBox.text = textbox.text+"回ジャンケンします";
time = int(textbox.text);
addChild(outputBox);
nowtime.text = jann+"/"+time;
addChild(nowtime);
addChild(jadgebox);
addChild(parcentage);
var uRLRequest1:URLRequest = new URLRequest("http://trt.up.seesaa.net/image/goo-02.gif");
var uRLRequest2:URLRequest = new URLRequest("http://trt.up.seesaa.net/image/cyoki-02.gif");
var uRLRequest3:URLRequest = new URLRequest("http://trt.up.seesaa.net/image/paa-02.gif");
handmaker2(uRLRequest1,uRLRequest2,uRLRequest3);
}
//審判
public function jadge():void{
jadgement = (PC - NPC + 3) % 3;
if(jann > 0)beforehandPC2 = beforehandPC;
beforehandPC = PC;
if(jadgement == 0){
//あいこ
jadgebox.textColor = 0x008000;
jadgebox.text = "あいこ";
drow++;
parcentage.text = "勝率:" + Math.floor((win/(jann-drow))*100) + "%";
if(jann == drow)parcentage.text = "勝率:0%";
}else if(jadgement == 1){
//負け
jadgebox.textColor = 0x00008B;
jadgebox.text = "負け";
lose++;
parcentage.text = "勝率:" + Math.floor((win/(jann-drow))*100) + "%";
}else if(jadgement == 2){
//勝ち
jadgebox.textColor = 0xFF0000;
jadgebox.text = "勝ち!";
win++;
parcentage.text = "勝率:" + Math.floor((win/(jann-drow))*100) + "%";
}
}
//Auto mode
public function auto_mode():void{
for(var i:int = jann; jann < time; i++){
PC = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
PC = PC % 3;
handmaker();
jadge();
}
}
public function hard_lebel():void{
var guu_par:int = 100 * guu / jann;
var choki_par:int = 100 * choki / jann;
var paa_par:int = 100 * paa / jann;
var num:int = Math.floor(Math.random()* (2 - 0 +1 ) )+0;
choki_par += guu_par;
paa_par += choki_par;
var parce:int = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
//if(num == 0){
if(0 <= parce && parce < guu_par){
NPC = 0;
//else if(paa_par-choki_par > choki_par-guu_par)NPC = 1;
if(num == 0) NPC = 2;
}
if(guu_par <= parce&& parce < choki_par){
NPC = 1;
//else if(paa_par-choki_par > guu_par)NPC = 2;
if(num == 0) NPC = 0;
}
if(choki_par <= parce){
NPC = 2;
//else if(choki_par-guu_par > guu_par)NPC = 2;
if(num == 0) NPC = 1;
}
/*}else{
NPC = PC + 1;
if(NPC == 3)NPC = 0;
if(num != 1)NPC = PC;
if(NPC == -1)NPC = 2;
} */
if(beforehandPC2 == PC){
if(num != 0){
NPC = PC + 1;
if(NPC == 3)NPC = 0;
}else NPC = PC - 1;
if(NPC == - 1)NPC = 2;
}
/*if(super_counter > 1){
NPC = PC - 1;
if(NPC == -1)NPC = 2;
}*/
if(NPC == beforehand)counter++;
if(PC != beforehandPC2)super_counter = 0;
if(PC == beforehandPC2){
super_counter++;
double++;
}
}
}
}