var select = 0
var delay = 1
var menuclass:Array = new Array();
var mesound:selsound = new selsound();
menuclass = ["attack","act","item","mercy"]
var menu1 = true;
var menu2 = false;
var selectsd:menusd2 = new menusd2()
var knifesd:knifesound = new knifesound()
var atksd:attacksound = new attacksound()
attack.gotoAndStop(2);
act.stop()
item.stop()
mercy.stop()
menuheart.x = 39
menuheart.y = 453
출력문1.x = 48.35
출력문1.y = 281.85
var Leftkey = false;
var Rightkey = false;
var Upkey = false;
var Downkey = false;
var charspeed = 3.0

stage.addEventListener(KeyboardEvent.KEY_DOWN,menukey);
stage.addEventListener(KeyboardEvent.KEY_DOWN,selmenu);

import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.TimerEvent;

function rdmonpt(min:Number, max:Number){
 return Math.floor(Math.random()*(max - min+1) + min);
}

var attackdmg = (Math.floor(choice.choice2.x + (Math.random()*30)+ 90));
var damage금칙어nt:String = attackdmg


function damageclear(e:Event){
 for(var i:int = 10; i < 35; i++){
  this["attack"+i].y = 1000
 }
}

var youratk = 0

var dmg_a
var dmg_b
var dmg_c = damage금칙어nt.slice(0,1)

function attackturn(){
 choice.gotoAndPlay(1)
 choice.x = -10
 choice.y = 320
 target.x = 320
 target.y = 320
}

function iceattacked(e:KeyboardEvent){
 if(e.keyCode == 90){
  if(choice.choice2.x > 46 && choice.choice2.x < 320){
   attackdmg = (Math.floor(choice.choice2.x + (Math.random()*10)+ 90));
   damageoption()
  }
  if(choice.choice2.x > 320 && choice.choice2.x < 599){
   attackdmg = (Math.floor((640- choice.choice2.x) + (Math.random()*10)+ 90));
   damageoption()
  }
 }
}

function damageoption(){
   var damage금칙어nt:String = attackdmg
      dmg_a = damage금칙어nt.slice(2,3)
      dmg_b = damage금칙어nt.slice(1,2)
      dmg_c = damage금칙어nt.slice(0,1)
      choice.stop()
      choice.choice2.gotoAndPlay(2)
      youratk = damage금칙어nt
      trace(damage금칙어nt)
   knifesd.play()
      knifeeffect.gotoAndPlay(2)
      stage.addEventListener(Event.ENTER_FRAME,icehurt);
      stage.removeEventListener(KeyboardEvent.KEY_DOWN,iceattacked);
}

function plend(e:Event){
 if(attack21.currentFrame == 51 || miss.currentFrame == 1){
  greenhp.y = 1000
  grayhp.y = 1000
  stage.removeEventListener(Event.ENTER_FRAME,plend);
  battlebox.gotoAndPlay(2);
  target.gotoAndPlay(2)
     choice.y = 1000
  stage.addEventListener(Event.ENTER_FRAME,Heartmove);
  heart.x = 320
  heart.y = 320
 }
}

function icehurt(e:Event){
 if(knifeeffect.currentFrame == 50){
  for(var i:int = 10; i < 35; i++){
   this["attack"+i].gotoAndPlay(1)
   attackedhp();
  }
  아이스바디.gotoAndPlay(83)
  atksd.play()
  greenhp.x = 269.5
  greenhp.y = 90
  grayhp.x = 268.5
  grayhp.y = 90
  stage.removeEventListener(Event.ENTER_FRAME,icehurt);
  stage.addEventListener(Event.ENTER_FRAME,damageint);
  stage.addEventListener(Event.ENTER_FRAME,plend);
 }
}


var icehomehp = 1400

greenhp.width = 101 * icehomehp/1400


function attackedhp(){
 var delaytimer:Timer = new Timer(50,10);
 delaytimer.addEventListener(TimerEvent.TIMER,onTick);
 delaytimer.start();
 function onTick(event:TimerEvent):void{
  icehomehp = icehomehp - (youratk/250)
  trace(icehomehp)
  greenhp.width = 101 * icehomehp/1400
 }
}

function damageint(e:Event){
  if(damage금칙어nt.slice(2,3) == damage금칙어nt.slice(2,3)){
   if(attack21.x == 320 && attack21.y == 65){
       this["attack1"+dmg_a].x = 335
       this["attack1"+dmg_a].y = 65
   }
   else{
    this["attack1"+dmg_a].x = 338
       this["attack1"+dmg_a].y = 65
   }
  }
  if(damage금칙어nt.slice(1,2) == damage금칙어nt.slice(1,2)){
   this["attack2"+dmg_b].x = 320
   this["attack2"+dmg_b].y = 65
  }
  if(damage금칙어nt.slice(0,1) == damage금칙어nt.slice(0,1)){
   if(attack21.x == 320 && attack21.y == 65){
    this["attack3"+dmg_c].x = 305
       this["attack3"+dmg_c].y = 65
   }
   else{
    this["attack3"+dmg_c].x = 302
       this["attack3"+dmg_c].y = 65
   }
  }
 stage.removeEventListener(Event.ENTER_FRAME,damageclear)
}

function selmenu(e:KeyboardEvent){
 if(e.keyCode == 90){
  if(menuheart.x == 39){
   menuheart.x = 64
   menuheart.y = 285
   출력문2.x = 88.35
            출력문2.y = 281.85
  }
  if(menuheart.x == 192){
   menuheart.x = 64
   menuheart.y = 285
   출력문2.x = 88.35
            출력문2.y = 281.85
  }
  if(menuheart.x == 352){
   menuheart.x = 64
   menuheart.y = 285
  }
  if(menuheart.x == 507){
   menuheart.x = 64
   menuheart.y = 285
   출력문3.x = 88.35
            출력문3.y = 281.85
  }
  menu1 = false;
  menu2 = true;
  출력문1.gotoAndStop(21)
  출력문1.y = 1000
  selectsd.play()
  stage.addEventListener(KeyboardEvent.KEY_DOWN,delmenu);
  stage.addEventListener(KeyboardEvent.KEY_DOWN,selmenu2);
  stage.removeEventListener(KeyboardEvent.KEY_DOWN,selmenu);
  stage.removeEventListener(KeyboardEvent.KEY_DOWN,menukey);
 }
}

function atkmiss(e:Event){
 if(choice.currentFrame == 50){
  stage.removeEventListener(KeyboardEvent.KEY_DOWN,iceattacked);
  stage.removeEventListener(Event.ENTER_FRAME,icehurt);
  stage.addEventListener(Event.ENTER_FRAME,plend);
  stage.removeEventListener(Event.ENTER_FRAME,atkmiss)
  miss.gotoAndPlay(1)
  miss.x = 320
  miss.y = 65
 }
}

function selmenu2(e:KeyboardEvent){
 if(e.keyCode == 90){
  if(attack.currentFrame == 2 && menu2 == true){
   attackturn();
   menuheart.x = 1000
   stage.addEventListener(KeyboardEvent.KEY_DOWN,iceattacked);
   stage.addEventListener(Event.ENTER_FRAME,atkmiss);
   stage.removeEventListener(KeyboardEvent.KEY_DOWN,delmenu);
   selectsd.play()
   출력문2.x = 1000
   attack.gotoAndStop(1)
  }
  if(act.currentFrame == 2 && menu2 == true){
  }
  if(item.currentFrame == 2 && menu2 == true){
  }
  if(mercy.currentFrame == 2 && menu2 == true){
   if(menuheart.y == 285){
    menuheart.x = 1000
    출력문3.x = 1000
    mercy.gotoAndStop(1)
    아이스바디.gotoAndPlay(62);
    stage.removeEventListener(KeyboardEvent.KEY_DOWN,delmenu);
   }
  }
  stage.removeEventListener(KeyboardEvent.KEY_DOWN,selmenu2);
 }
}


function delmenu(e:KeyboardEvent){
 if(e.keyCode == 88){
  if(attack.currentFrame == 2){
   menuheart.x = 39
  }
  if(act.currentFrame == 2){
   menuheart.x = 192
  }
  if(item.currentFrame == 2){
   menuheart.x = 352
  }
  if(mercy.currentFrame == 2){
   menuheart.x = 507
  }
  menu1 = true;
  menu2 = false;
  menuheart.y = 453
  출력문1.gotoAndPlay(1)
  for(var i:int = 2; i<4; i++){
   this["출력문"+i].x = 1000
  }
  출력문1.x = 48.35
  출력문1.y = 281.85
  stage.removeEventListener(KeyboardEvent.KEY_DOWN,selmenu2);
  stage.removeEventListener(KeyboardEvent.KEY_DOWN,delmenu);
  stage.addEventListener(KeyboardEvent.KEY_DOWN,selmenu);
  stage.addEventListener(KeyboardEvent.KEY_DOWN,menukey)
 }
}

function menukey(e:KeyboardEvent){
 if(e.keyCode == 39 && menu1 == true && select<4 && delay == 1){
  select ++
  if(select ==4){
   select= 0
  }
  if(menuclass[select] == "attack"){
   attack.gotoAndStop(2)
   mercy.gotoAndStop(1)
   act.gotoAndStop(1)
   mesound.play()
   menuheart.x = 39
  }
  if(menuclass[select] == "act"){
   item.gotoAndStop(1)
   act.gotoAndStop(2)
   attack.gotoAndStop(1)
   mesound.play()
   menuheart.x = 192
  }
  if(menuclass[select] == "item"){
   mercy.gotoAndStop(1)
   item.gotoAndStop(2)
   act.gotoAndStop(1)
   mesound.play()
   menuheart.x = 352
  }
  if(menuclass[select] == "mercy"){
   attack.gotoAndStop(1)
   mercy.gotoAndStop(2)
   item.gotoAndStop(1)
   mesound.play()
   menuheart.x = 507
  }
  delay = 0
  menutime();
 }
 if(e.keyCode == 37 && menu1 == true && select>-2 && delay == 1){
  select --
  if(select==-1){
   select = 3
  }
  if(menuclass[select] == "attack"){
   mercy.gotoAndStop(1)
   attack.gotoAndStop(2)
   act.gotoAndStop(1)
   mesound.play()
   menuheart.x = 39
  }
  if(menuclass[select] == "act"){
   attack.gotoAndStop(1)
   act.gotoAndStop(2)
   item.gotoAndStop(1)
   mesound.play()
   menuheart.x = 192
  }
  if(menuclass[select] == "item"){
   act.gotoAndStop(1)
   item.gotoAndStop(2)
   mercy.gotoAndStop(1)
   mesound.play()
   menuheart.x = 352
  }
  if(menuclass[select] == "mercy"){
   item.gotoAndStop(1)
   mercy.gotoAndStop(2)
   attack.gotoAndStop(1)
   mesound.play()
   menuheart.x = 507
  }
  delay = 0
  menutime();
 }
}

function menutime(){
 var metimer:Timer = new Timer(100,1);
 metimer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
 metimer.start();
 function onTimerComplete(event:TimerEvent):void{
  delay = 1;
 }
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,presskey);
function presskey(e:KeyboardEvent)
{
 if(e.keyCode == 37)
 {
  Leftkey = true;
 }
 if(e.keyCode == 38)
 {
  Upkey = true;
 }
 if(e.keyCode == 40)
 {
  Downkey = true;
 }
 if(e.keyCode == 39)
 {
  Rightkey = true;
 }
 
}
stage.addEventListener(KeyboardEvent.KEY_UP,pullkey);
function pullkey(e:KeyboardEvent)
{
 if(e.keyCode == 37)
 {
  Leftkey = false;
 }
 if(e.keyCode == 38)
 {
  Upkey = false;
 }
 if(e.keyCode == 40)
 {
  Downkey = false;
 }
 if(e.keyCode == 39)
 {
  Rightkey = false;
 }
}

function Heartmove(e:Event)
{
 if(Leftkey == true && heart.x > 251)
 {
  heart.x -= charspeed;
 }
 if(Upkey == true && heart.y > 265)
 {
  heart.y -= charspeed;
 }
 if(Downkey == true && heart.y < 375)
 {
  heart.y += charspeed;
 }
 if(Rightkey == true && heart.x < 388)
 {
  heart.x += charspeed;
 }
}



415줄의 명복을 액션빔