Sasuke Kroniken 2

Transcription

Sasuke Kroniken 2
Sasuke Kroniken 2
1
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class sK2{
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
int players=3;//spieler anzahl max 10
Player users=new Player(players);//erzeuge alle spieler
JFrame f = new JFrame("sasuke chronics V2");//erzeuge jframe
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//jframe schliessenfuntkion
f.setResizable(false);
f.add(new MyPanel(users,players));//erzeuge grafikpanel
f.setPreferredSize(new Dimension(1200, 800));//größe jframe
f.pack();
f.setVisible(true);//sichtbarkeit
}
}
class Player{//klasse spieler
public int[][] charas;//alle spieler Array
public int[][] useWeapon;//Array für waffen die gerade benutzt werden
public int[][] weapons;//Array für waffen die gerade benutzt werden
public int[][] guns;//Array für waffen die gerade benutzt werden
public int players; //anzahl Spieler
public int useWeaponsValue;
public void setNull(){
for(int i=0;i<100;i++){for(int o=0;o<useWeaponsValue;o++){useWeapon[i][o]=0;}}
}
public Player(int players){
this.players=players;
int charasValue=18;//anzahl an eigenschaften array charas
int weaponsValue=7;//anzahl an eigenschaften array weapons
int gunsValue=7;//anzahl an eigenschaften array guns
useWeaponsValue=7;//anzahl an eigenschaften array useWeapon
charas=new int[players][charasValue];
useWeapon=new int[100][useWeaponsValue];
weapons=new int[10][weaponsValue];
guns=new int[10][gunsValue];
Random rand=new Random();
for(int i=0;i<players;i++){
for(int o=0;o<charasValue;o++){
charas[i][0]=1;//chara
charas[i][1]=rand.nextInt(1200);//chara X
charas[i][2]=350;//chara Y
charas[i][3]=1;//charaAction
charas[i][4]=0;//charaActionCount
charas[i][5]=0;//charaActionValue
charas[i][6]=1;//charaPosition
charas[i][7]=1;//rand.nextInt(10);//charaSpeedBonus
charas[i][8]=1000;//charaHP
charas[i][9]=100;//charaMP
charas[i][10]=0;//charaWeapon
charas[i][11]=300;//charaWeaponMunition
charas[i][12]=0;//charaGun
charas[i][13]=300;//charaGunMunition
charas[i][14]=0;//charaGegner
charas[i][15]=3000;//charaGold
charas[i][16]=rand.nextInt(50);//charaPower
charas[i][17]=0;//charaStatus
}
}
charas[0][1]=10;
charas[0][2]=380;
charas[0][7]=20;
charas[0][8]=10000;
charas[0][16]=50;
for(int i=0;i<100;i++){
for(int o=0;o<useWeaponsValue;o++){
useWeapon[i][0]=0;//weapon Aktiv? und Count
useWeapon[i][1]=0;//weapon X
useWeapon[i][2]=0;//weapon Y
useWeapon[i][3]=0;//weaponPosition
useWeapon[i][4]=0;//weaponType
useWeapon[i][5]=0;//weaponMunitionType
useWeapon[i][6]=0;//weaponBesitzer
}
}
for(int i=0;i<10;i++){
for(int o=0;o<weaponsValue;o++){weapons[i][o]=0;}
weapons[i][0]=i;//weaponId
weapons[i][1]=(i*10);//weaponPower
weapons[i][2]=(i*10);//weaponMunition
for(int o=0;o<gunsValue;o++){guns[i][o]=0;}
guns[i][0]=i;//weaponId
guns[i][1]=(i*10);//weaponPower
guns[i][2]=(i*10);//weaponMunition
}
}
}
class MyPanel extends JPanel {
public Graphics g;//gfx komponenten
public Player Users;//objekt für klasse spieler
public int players;//anzahl spieler
public int getItem;//gewinn nach kampf
public String sItem="";
public boolean weaponAnimation=true;
public MyPanel(Player users, int players) {
new Timer(200, paintTimer).start();//start timer
setupKeyBinding();//keybindings
Users=users;
this.players=players;
}
protected void paintComponent(Graphics g) {
addMouseListener(new MouseListener() {//mouselistener
@Override
public void mouseReleased(MouseEvent e) {}//mouselistener released
@Override
public void mousePressed(MouseEvent e) {}//mouselistener pressed
@Override
public void mouseExited(MouseEvent e) {}//mouselistener exited
@Override
public void mouseEntered(MouseEvent e) {}//mouselistener entered
@Override
public void mouseClicked(MouseEvent e) {//mouselistener clicked
2
for(int i=0;i<7;i++){
if(((e.getX()>=(3+((100*i)+(20*i))))&&(e.getX()<=(103+((100*i)+(20*i)))))&&((e.getY()>=520)&&(e.getY()<=580))){
Users.charas[0][10]=(i+1);
Users.charas[0][11]=10;
Users.charas[0][15]=Users.charas[0][15]-1;}
if(((e.getX()>3)&&(e.getX()<100))&&((e.getY()>590)&&(e.getY()<610))){
Users.charas[0][12]=(i+1);
Users.charas[0][13]=10;
Users.charas[0][15]=Users.charas[0][15]-1;}
if(((e.getX()>123)&&(e.getX()<223))&&((e.getY()>590)&&(e.getY()<610))){Users.charas[0][11]=30;Users.charas[0][15]=Users.charas[0][15]-2;}
if(((e.getX()>243)&&(e.getX()<343))&&((e.getY()>590)&&(e.getY()<610))){Users.charas[0][11]=30;Users.charas[0][15]=Users.charas[0][15]-3;}
if(((e.getX()>363)&&(e.getX()<463))&&((e.getY()>590)&&(e.getY()<610))){Users.charas[0][11]=30;Users.charas[0][15]=Users.charas[0][15]-4;}
if(((e.getX()>483)&&(e.getX()<583))&&((e.getY()>590)&&(e.getY()<610))){Users.charas[0][11]=30;Users.charas[0][15]=Users.charas[0][15]-8;}
if(((e.getX()>603)&&(e.getX()<703))&&((e.getY()>590)&&(e.getY()<610))){Users.charas[0][11]=30;Users.charas[0][15]=Users.charas[0][15]-12;}
if(((e.getX()>723)&&(e.getX()<823))&&((e.getY()>590)&&(e.getY()<610))){Users.charas[0][11]=30;Users.charas[0][15]=Users.charas[0][15]-40;}
}
}
});
super.paintComponent(g);//gfx komponenten
Image konoha,scroll,scrollEnd,cWeapon;//init images
konoha = Toolkit.getDefaultToolkit().getImage("map/konoha.gif");
g.drawImage(konoha, 0, 0 , null);//make background
String changeWeapon="";
int staticSize=35;
int changeX=0;
drawWeaponClick(g);
for(int i=0;i<players;i++){//controllpanel für jeden spieler
if(i==0){
scroll = Toolkit.getDefaultToolkit().getImage("chara/scroll.gif");
g.drawImage(scroll, 1, 1 , null);
g.setColor(Color.white);
g.fillRect(20,10,220,150);
g.setColor(Color.black);
g.drawRect(20,10,220,150);
changeWeapon="";changeX=0;
if(getItem!=0){
switch(getItem){
case(1):Users.charas[i][8]=Users.charas[i][8]+200;sItem="HP+200";break;
case(2):Users.charas[i][9]=Users.charas[i][9]+50;sItem="MP+50";break;
case(3):Users.charas[i][15]=Users.charas[i][15]+1000;sItem="Gil+1000";break;
case(4):Users.charas[i][7]=Users.charas[i][7]+2;sItem="Speed+2";break;
case(5):Users.charas[i][16]=Users.charas[i][16]+10;sItem="Stärke+10";break;
default:break;}getItem=0;
}
if(Users.charas[i][10]!=0){changeWeapon="weapon/throw"+Users.charas[i][10]+".gif";}
if(Users.charas[i][12]!=0){changeWeapon="weapon/shoot"+Users.charas[i][12]+".gif";changeX=-20;
if((Users.charas[i][12]==7)||(Users.charas[i][12]==4)){changeX=-5;}}
if(changeWeapon!=""){cWeapon = Toolkit.getDefaultToolkit().getImage(changeWeapon);
g.drawImage(cWeapon, (staticSize+changeX),100 , null);}
g.drawString("HP: "+Users.charas[i][8],staticSize,25);
g.drawString("MP: "+Users.charas[i][9],staticSize,37);
g.drawString("Gil: "+Users.charas[i][15],staticSize,49);
g.drawString("Stärke: "+Users.charas[i][16],staticSize,61);
g.drawString("Speed: "+Users.charas[i][7],staticSize,73);
g.drawString("Gewinn: "+sItem,staticSize,85);
g.drawString("Munition: "+Users.charas[i][11],staticSize,97);
scrollEnd = Toolkit.getDefaultToolkit().getImage("chara/scroll_end.gif");
g.drawImage(scrollEnd, 237, 10 , null);
}else{
g.setColor(Color.white);
g.fillRect((170+(100*i)),10,80,80);
g.setColor(Color.black);
g.drawRect((170+(100*i)),10,80,80);
changeWeapon="";changeX=0;
if(Users.charas[i][10]!=0){changeWeapon="weapon/throw"+Users.charas[i][10]+".gif";}
if(Users.charas[i][12]!=0){changeWeapon="weapon/shoot"+Users.charas[i][12]+".gif";changeX=-20;
if((Users.charas[i][12]==7)||(Users.charas[i][12]==4)){changeX=-5;}}
if(changeWeapon!=""){cWeapon = Toolkit.getDefaultToolkit().getImage(changeWeapon);
g.drawImage(cWeapon, (190+(100*i)+changeX),50 , null);}
g.drawString("HP: "+Users.charas[i][8],(180+(100*i)),30);
g.drawString("MP: "+Users.charas[i][9],(180+(100*i)),40);
g.drawString("Gil: "+Users.charas[i][15],(180+(100*i)),50);
g.drawString("Stärke: "+Users.charas[i][16],(180+(100*i)),60);
}
if(Users.charas[i][17]<=0){drawChara(g,i);}
else{Users.charas[i][17]++;deathChara(g,i);if(Users.charas[i][17]>50){Users.charas[i][17]=0;}
}
}
drawWeaponUsed(g);
}
public void drawWeaponUsed(Graphics g){
this.g=g;
for(int i=0;i<100;i++){
if((Users.useWeapon[i][0]>0)&&(Users.useWeapon[i][0]<30)){
Users.useWeapon[i][0]++;
String weaponPosition="right";
String weaponName="throw1";
String sImg="";
int plusX=0;
int plusY=50;
int plusLeftRight=0;
if(Users.useWeapon[i][3]==1){weaponPosition="right";Users.useWeapon[i][1]=Users.useWeapon[i][1]+10;plusLeftRight=60;}
if(Users.useWeapon[i][3]==2){weaponPosition="left";Users.useWeapon[i][1]=Users.useWeapon[i][1]-10;}
if(Users.useWeapon[i][4]==5){weaponName="throw"+Users.useWeapon[i][5]+"";
if(Users.useWeapon[i][5]==2){plusX=0;plusY=60;}
}
if(Users.useWeapon[i][4]==6){weaponName="bullet"+(Users.useWeapon[i][5]-1)+"";
switch(Users.useWeapon[i][5]){
case(1):plusY=63;break;
case(2):plusX=30;plusY=63;break;
case(3):plusX=30;plusY=63;break;
case(4):plusX=30;plusY=63;break;
case(5):plusX=30;plusY=63;break;
case(6):plusX=30;plusY=63;break;
case(7):plusX=30;plusY=42;break;
}
if(Users.useWeapon[i][3]==2){plusX=-10;}
}
sImg="weapon/"+weaponName+"_"+weaponPosition+".gif";
if((Users.useWeapon[i][4]==5)&&((Users.useWeapon[i][5]==3)||(Users.useWeapon[i][5]>4))){
if(weaponAnimation){sImg="weapon/"+weaponName+"_"+weaponPosition+"1.gif";weaponAnimation=false;}
else{sImg="weapon/"+weaponName+"_"+weaponPosition+"2.gif";weaponAnimation=true;}
}
plusX=plusX+plusLeftRight;
Image weapon = Toolkit.getDefaultToolkit().getImage(sImg);
g.drawImage(weapon, (Users.useWeapon[i][1]+plusX), (Users.useWeapon[i][2]+plusY), null);
for(int o=0;o<players;o++){
if(((Users.charas[o][1]>=(Users.useWeapon[i][1]+plusX-80))&&(Users.charas[o][1]<=(Users.useWeapon[i][1]+plusX+10)))&&(Users.charas[0][17]==0)){
if(Users.useWeapon[i][6]!=o){
Users.charas[o][8]=Users.charas[o][8]-Users.charas[0][16];
Users.useWeapon[i][0]=100;
3
if(Users.charas[o][8]<=0){
int getMoneyId=Users.charas[0][14];
Users.charas[0][15]=Users.charas[0][15]+Users.charas[getMoneyId][15];
Users.charas[o][8]=2000;//new chara
Users.charas[o][17]=1;//status tot
}
}
}
}
if(i>97){Users.setNull();}
}
}
}
public void drawChara(Graphics g, int i){
this.g=g;
String position="right";
if(Users.charas[i][17]==0){
String action="stand";
int diffX=Users.charas[i][1]-Users.charas[0][1];
int diffY=Users.charas[i][2]-Users.charas[0][2];
boolean inFight=true;
if(i!=0){//PC spieler
Random rand=new Random();
int fightOption=rand.nextInt(19);
int selectWeapon=rand.nextInt(7);
int shadowAction=0;
int shadowId=Users.charas[0][14];
boolean useWeaponCheck=true;
if(diffY<=-20){shadowAction=3;inFight=false;}
if(diffY>=20){shadowAction=4;inFight=false;}
if(diffX<=-30){shadowAction=1;inFight=false;}
if(diffX>=30){shadowAction=2;inFight=false;}
if((Users.charas[i][4]==0)&&(shadowAction!=0)){Users.charas[i][3]=2;Users.charas[i][4]=4;}//setze counter
if((Users.charas[i][4]==0)&&(inFight)){
Users.charas[0][8]=Users.charas[0][8]-Users.charas[i][16];
Users.charas[0][14]=i;
if(fightOption<7){Users.charas[i][3]=3;Users.charas[i][4]=4;}//punch
if(fightOption>7){Users.charas[i][3]=4;Users.charas[i][4]=5;}//kick
if(fightOption>15){Users.charas[i][3]=5;Users.charas[i][4]=3;Users.charas[i][10]=selectWeapon;Users.charas[i][12]=0;
for(int o=0;o<100;o++){
if(useWeaponCheck){
if(Users.useWeapon[o][0]==0){
useWeaponCheck=false;
Users.useWeapon[o][0]=1;
Users.useWeapon[o][1]=Users.charas[i][1];
Users.useWeapon[o][2]=Users.charas[i][2];
Users.useWeapon[o][3]=Users.charas[i][6];
Users.useWeapon[o][4]=Users.charas[i][3];
Users.useWeapon[o][6]=i;
if(Users.charas[i][3]==5){Users.useWeapon[o][5]=Users.charas[i][10];}}}}
}//throw
//if(fightOption>10){Users.charas[i][3]=7;Users.charas[i][4]=15;}//jump
//if(fightOption>10){Users.charas[i][3]=8;Users.charas[i][4]=15;}//tele
}
if(Users.charas[i][4]!=0){
if(shadowAction==1){Users.charas[i][1]=Users.charas[i][1]+5;Users.charas[i][6]=1;}
if(shadowAction==2){Users.charas[i][1]=Users.charas[i][1]-5;Users.charas[i][6]=2;}
if(shadowAction==3){Users.charas[i][5]=3;}
if(shadowAction==4){Users.charas[i][5]=-3;}
}
else{shadowAction=0;}
}
if(Users.charas[i][6]==2){position="left";}
if(Users.charas[i][4]!=0){
switch(Users.charas[i][3]){
case(1):
action="walk"+(5-Users.charas[i][4])+"";
if(Users.charas[i][6]==1){Users.charas[i][1]=Users.charas[i][1]+Users.charas[i][7];}
if(Users.charas[i][6]==2){Users.charas[i][1]=Users.charas[i][1]-Users.charas[i][7];}
break;
case(2):
action="walk"+(5-Users.charas[i][4])+"";Users.charas[0][14]=0;
if(Users.charas[i][6]==1){Users.charas[i][1]=Users.charas[i][1]+Users.charas[i][7];}
if(Users.charas[i][6]==2){Users.charas[i][1]=Users.charas[i][1]-Users.charas[i][7];}
if((Users.charas[i][2]>320)&&(Users.charas[i][2]<405)){
if(Users.charas[i][5]>0){Users.charas[i][2]=Users.charas[i][2]+Users.charas[i][5];}
if(Users.charas[i][5]<0){Users.charas[i][2]=Users.charas[i][2]+Users.charas[i][5];}}
if(Users.charas[i][2]<=320){if(Users.charas[i][5]>0){Users.charas[i][2]=Users.charas[i][2]+Users.charas[i][7];}}
if(Users.charas[i][2]>=405){if(Users.charas[i][5]<0){Users.charas[i][2]=Users.charas[i][2]-Users.charas[i][7];}}
break;
case(3):action="fightpunch"+(5-Users.charas[i][4])+"";
int enemy=Users.charas[0][14];
if((inFight)&&(i==0)&&(Users.charas[0][14]!=0)){
Users.charas[enemy][8]=Users.charas[enemy][8]-Users.charas[0][16];
if(Users.charas[enemy][8]<0){Users.charas[enemy][17]=1;}
}
break;
case(4):action="fightkick"+(6-Users.charas[i][4])+"";break;
case(5):action="fightthrow"+(4-Users.charas[i][4])+"";if((Users.charas[i][10]==0)||(Users.charas[i][11]==0)){action="stand";}
break;
case(6):action="fightgun"+Users.charas[i][12];if((Users.charas[i][12]==0)||(Users.charas[i][13]==0)){action="stand";}break;
case(7):action="jump"+(15-Users.charas[i][4])+"";
if(Users.charas[i][4]>5){
if(Users.charas[i][6]==1){Users.charas[i][1]=Users.charas[i][1]+Users.charas[i][7];}
if(Users.charas[i][6]==2){Users.charas[i][1]=Users.charas[i][1]-Users.charas[i][7];}}
break;
case(8):if(Users.charas[i][9]>1){action="tele"+(15-Users.charas[i][4])+"";
if(Users.charas[i][4]==7){
if(Users.charas[i][6]==1){Users.charas[i][1]=Users.charas[i][1]+700;}
if(Users.charas[i][6]==2){Users.charas[i][1]=Users.charas[i][1]-700;}}
Users.charas[i][9]=Users.charas[i][9]-1;}else{Users.charas[i][9]=0;}
break;
default:break;}
Users.charas[i][4]--;}//count charaAction runter
Image charaImg = Toolkit.getDefaultToolkit().getImage("chara/sasuke_"+position+"_"+action+".gif");
g.drawImage(charaImg, Users.charas[i][1],Users.charas[i][2] , null);//zeichne chara
}else{
Image charaImg = Toolkit.getDefaultToolkit().getImage("chara/sasuke_"+position+"_lie.gif");
g.drawImage(charaImg, Users.charas[i][1],Users.charas[i][2] , null);//zeichne chara
}
}
public void deathChara(Graphics g, int i){
if(Users.charas[i][17]==3){
if(i==0){Users.charas[0][15]=0;}
else{
Users.charas[0][15]=Users.charas[0][15]+1;
Random rand=new Random();
getItem=(rand.nextInt(4)+1);
}
Users.charas[i][8]=100;
}
4
this.g=g;
Image bannerU = Toolkit.getDefaultToolkit().getImage("map/bannerUchiha.gif");
g.drawImage(bannerU, 100, 320 , null);//zeichne banner
}
public void drawWeaponClick(Graphics g){
Image weapon,gun;//init images
this.g=g;
String sName="";
String wImg="";
int price=0;
for(int i=0;i<7;i++){
g.setColor(Color.white);
g.fillRect((2+(120*i)),520,100,65);
g.setColor(Color.black);
g.drawRect((2+(120*i)),520,100,65);
switch(i){
case(0):sName="BoShurikan";wImg="throw1";break;
case(1):sName="Kunai";wImg="throw2";break;
case(2):sName="kl. Shurikan";wImg="throw3";break;
case(3):sName="gr. Kunai";wImg="throw4";break;
case(4):sName="Shurikan";wImg="throw5";break;
case(5):sName="gr. Shurikan";wImg="throw6";break;
case(6):sName="FeuerShurikan";wImg="throw7";break;
default:break;}
g.drawString(""+sName,(6+(120*i)),537);
weapon = Toolkit.getDefaultToolkit().getImage("weapon/"+wImg+".gif");
g.drawImage(weapon, (6+(120*i)), 543 , null);
}
for(int i=0;i<7;i++){
g.setColor(Color.white);
g.fillRect((2+(120*i)),590,100,20);
g.setColor(Color.black);
g.drawRect((2+(120*i)),590,100,20);
switch(i){
case(0):price=100;break;
case(1):price=200;break;
case(2):price=500;break;
case(3):price=1000;break;
case(4):price=2000;break;
case(5):price=5000;break;
case(6):price=8000;break;
case(7):price=20000;break;
default:break;}
g.drawString("Preis:"+price,(6+(120*i)),603);
}
/*
for(int i=0;i<7;i++){
g.setColor(Color.white);
g.fillRect((2+(120*i)),618,100,65);
g.setColor(Color.black);
g.drawRect((2+(120*i)),618,100,65);
switch(i){
case(0):sName="Maschenpistole";wImg="shoot1";break;
case(1):sName="Shotgun";wImg="shoot2";break;
case(2):sName="Gewehr";wImg="shoot3";break;
case(3):sName="Sniper";wImg="shoot4";break;
case(4):sName="Plasmagun";wImg="shoot5";break;
case(5):sName="Plasmagewehr";wImg="shoot6";break;
case(6):sName="Racketenwerfer";wImg="shoot7";break;
default:break;}
g.drawString(""+sName,(6+(120*i)),640);
gun = Toolkit.getDefaultToolkit().getImage("weapon/"+wImg+".gif");
g.drawImage(gun, (1+(120*i)), 645 , null);
}
*/
}
public void setAction(int modus,int Value1,int Value2){
Users.charas[0][3]=modus;//setze Action
if(Users.charas[0][4]==0){//wenn ActionCount frei
if(modus==1){//horizontal bewegen
Users.charas[0][4]=Value1;
if(Value2>0){Users.charas[0][6]=1;}else{Users.charas[0][6]=2;//setze ActionCountValue
}
}
if(modus==2){//vertikal bewegen
Users.charas[0][4]=Value1;//setze ActionCountValue
Users.charas[0][5]=Value2;//setze charaActionValue
}
if(modus>=3){
Users.charas[0][4]=Value1;//setze ActionCountValue
}
if((modus==5)||(modus==6)){
if(modus==5){Users.charas[0][11]=Users.charas[0][11]-1;}else{Users.charas[0][13]=Users.charas[0][13]-1;}
boolean useWcheck=true;
for(int o=0;o<100;o++){
if(useWcheck){
if(Users.useWeapon[o][0]==0){
useWcheck=false;
Users.useWeapon[o][0]=1;
Users.useWeapon[o][1]=Users.charas[0][1];
Users.useWeapon[o][2]=Users.charas[0][2];
Users.useWeapon[o][3]=Users.charas[0][6];
Users.useWeapon[o][4]=Users.charas[0][3];
Users.useWeapon[o][6]=0;
if(modus==5){Users.useWeapon[o][5]=Users.charas[0][10];}
if(modus==6){Users.useWeapon[o][5]=Users.charas[0][12];}}}
}
}
}
}
private void setupKeyBinding(){
int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
InputMap inMap = getInputMap(condition);
ActionMap actMap = getActionMap();
for (Direction direction : Direction.values()) {
int key = direction.getKey();
String name = direction.name();
inMap.put(KeyStroke.getKeyStroke(key, 0), name);
inMap.put(KeyStroke.getKeyStroke(key, InputEvent.SHIFT_DOWN_MASK), name);
actMap.put(name, new MyKeyAction(this, direction));
}
}
Action paintTimer = new AbstractAction() {public void actionPerformed(ActionEvent e) {repaint();}};
}
enum Direction{
UP(KeyEvent.VK_UP),
DOWN(KeyEvent.VK_DOWN),
LEFT(KeyEvent.VK_LEFT),
RIGHT(KeyEvent.VK_RIGHT),
JUMP(KeyEvent.VK_X),
5
PUNCH(KeyEvent.VK_V),
KICK(KeyEvent.VK_B),
THROW(KeyEvent.VK_N),
SHOOT(KeyEvent.VK_M),
TELE(KeyEvent.VK_C);
private int key;
private Direction(int key){this.key = key;}
public int getKey(){return key;}
}
@SuppressWarnings("serial")
class MyKeyAction extends AbstractAction{
private MyPanel p;
private Direction direction;
public MyKeyAction(MyPanel p,Direction direction){
this.p=p;
this.direction=direction;
}
@Override
public void actionPerformed(ActionEvent e){
switch (direction){
case RIGHT:p.setAction(1,4,3);break;
case LEFT:p.setAction(1,4,-3);break;
case DOWN:p.setAction(2,4,5);break;
case UP:p.setAction(2,4,-5);break;
case PUNCH:p.setAction(3,4,0);break;
case KICK:p.setAction(4,5,0);break;
case THROW:p.setAction(5,3,0);break;
case SHOOT:p.setAction(6,5,0);break;
case JUMP:p.setAction(7,14,0);break;
case TELE:p.setAction(8,14,0);break;
default:break;
}
}
}
6

Similar documents