Created
April 8, 2014 14:02
-
-
Save firejox/10128921 to your computer and use it in GitHub Desktop.
A6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
public class A6 { | |
public static void main(String[] args) { | |
Hero[] heros; | |
MyPanel[] panels = new MyPanel[3]; | |
MyFrame frame = new MyFrame(); | |
heros = new Hero[3]; | |
heros[0] = new Wizard(); //set Wizard | |
((Wizard)heros[0]).HP_setter(30); | |
((Wizard)heros[0]).MP_setter(30); | |
((Wizard)heros[0]).PP_setter(30); | |
panels[0] = new MyPanel(); | |
frame.newRolePos(heros[0], panels[0], 250, 250); | |
heros[1] = new Swordsman(); //set Swordsman | |
((Swordsman)heros[1]).HP_setter(30); | |
((Swordsman)heros[1]).MP_setter(30); | |
((Swordsman)heros[1]).PP_setter(30); | |
panels[1] = new MyPanel(); | |
frame.newRolePos(heros[1], panels[1], 250, 250); | |
heros[2] = new Knight(); //set Knight | |
((Knight)heros[2]).HP_setter(30); | |
((Knight)heros[2]).MP_setter(30); | |
((Knight)heros[2]).PP_setter(30); | |
panels[2] = new MyPanel(); | |
frame.newRolePos(heros[2], panels[2], 250, 250); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
public class Hero { | |
protected String Name; //Hero's name | |
protected float HP; //Hero's health point | |
protected float MP; //Hero's mana point | |
protected float PP; //Hero's power point | |
public void Name_setter(String _Name) { //set name | |
Name = _Name; | |
} | |
public void HP_setter(float hpp) { //set health point | |
HP = hpp; | |
} | |
public void MP_setter(float mpp) { //set mana point | |
MP = mpp; | |
} | |
public void PP_setter(float ppp) { //set power point | |
PP = ppp; | |
} | |
public String Name_getter() { //get name | |
return Name; | |
} | |
public float HP_getter() { //get health point | |
return HP; | |
} | |
public float MP_getter() { //get mana point | |
return MP; | |
} | |
public float PP_getter() { //get power point | |
return PP; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
public class Knight extends Hero { | |
public Knight () { //construct Knight class | |
Name = "Knight"; | |
} | |
public float HP_getter() { //set HP | |
return HP * 0.8f; | |
} | |
public float MP_getter() { //set MP | |
return MP * 0.1f; | |
} | |
public float PP_getter() { //set PP | |
return PP * 0.1f; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
import javax.swing.*; | |
import java.awt.*; | |
public class MyFrame extends JFrame{ | |
public MyFrame() { | |
setSize(270, 770); //set the size of frame | |
setLayout(new GridLayout(3, 1, 5, 5)); //split the frame into 3x1 blocks | |
setVisible(true); | |
} | |
public void newRolePos(Hero hero, MyPanel panel, int x, int y) { | |
panel.setSize(x,y); //set frame | |
panel.setRoleState(hero); //put the information of hero into panel | |
add(panel); //put panel into frame | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
import javax.swing.*; | |
import java.awt.*; | |
import javax.swing.border.*; | |
public class MyPanel extends JPanel { | |
private JLabel states; | |
private JLabel img; | |
public MyPanel() { | |
setBorder(new LineBorder(Color.BLACK, 2)); | |
} | |
public void setRoleState(Hero hero) { | |
ImageIcon _img = new ImageIcon(hero.Name_getter() + ".jpg"); //get the image | |
states = new JLabel(hero.Name_getter() + " HP: " + hero.HP_getter() + " MP: " + hero.MP_getter() + "PP: " + hero.PP_getter()); //set state | |
img = new JLabel(_img); //set the image | |
add(states); //put the information of state into panel | |
add(img); //put the image into panel | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
public class Swordsman extends Hero { | |
public Swordsman() { //construct Swordsman class | |
Name = "Swordsman"; | |
} | |
public float HP_getter() { //set HP | |
return HP * 0.1f; | |
} | |
public float MP_getter() { //set MP | |
return MP * 0.1f; | |
} | |
public float PP_getter() { //set PP | |
return PP * 0.8f; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ce1002.a6.s101201046; | |
public class Wizard extends Hero { | |
public Wizard() { //construct Wizard class | |
Name = "Wizard"; | |
} | |
public float HP_getter() { //set HP | |
return HP * 0.2f; | |
} | |
public float MP_getter() { //set MP | |
return MP * 0.7f; | |
} | |
public float PP_getter() { //set PP | |
return PP * 0.1f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment