Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.*;
- import java.util.Random;
- import java.util.StringTokenizer;
- import java.lang.String;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- public class Skill {
- String type;
- String name;
- String desc;
- int cool;
- int targets;
- public Skill(int typeNo) {
- // TODO Auto-generated constructor stub
- Random rand;
- int n = 0;
- switch (typeNo) {
- case 0:
- /*
- * GLOBAL
- */
- rand = new Random();
- n = rand.nextInt(10);
- this.setSkill(this.getSkill(n, "skills_global.txt"));
- break;
- case 1:
- /*
- * DAMAGE
- */
- rand = new Random();
- n = rand.nextInt(5);
- this.setSkill(this.getSkill(n, "skills_damage.txt"));
- break;
- case 2:
- /*
- * POSITION
- */
- rand = new Random();
- n = rand.nextInt(6);
- this.setSkill(this.getSkill(n, "skills_position.txt"));
- break;
- case 3:
- /*
- * PASSIVE
- */
- rand = new Random();
- n = rand.nextInt(5);
- this.setSkill(this.getSkill(n, "skills_passive.txt"));
- break;
- }
- }
- public String getSkill(int n, String filename) {
- String str = "";
- try {
- FileInputStream fs = new FileInputStream(filename);
- DataInputStream in = new DataInputStream(fs);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- for (int i = 1; i < n; i++) {
- br.readLine();
- }
- str += br.readLine();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return str;
- }
- public void setSkill(String str) {
- StringTokenizer token = new StringTokenizer(str, ";");
- this.type = token.nextToken();
- this.name = token.nextToken().substring(1);
- this.desc = token.nextToken().substring(1);
- this.cool = Integer.parseInt(token.nextToken().substring(1));
- this.targets = Integer.parseInt(token.nextToken().substring(1));
- /*
- * Cooldown -1 For skill Copy = use once 0 For passive skills = use
- * always >0 For other skills
- */
- }
- public void setCooldown(Sheep s, int cd) {
- // s.cd = cd;
- }
- public void effect(Sheep me, Sheep[] targets, int allActions, Board board) {
- int r;
- int t;
- int cnt;
- int cntr;
- /*
- Sheep targets[] = new Sheep[3];
- targets[0] = targets[0];
- targets[1] = s1;
- targets[2] = s2;
- */
- // Check for extra action to modify;
- System.out.println("Effect ng skill");
- switch (name) {
- case "Decreased Cost":
- // oks na. nakaintegrate na sa pagbabawas.
- break;
- case "Sure Shot":
- // if current tile chance > 0, set chance to 90
- // Could be removed. integrated already in fire();
- if (me.getLocation().getProperty() == 5) // Set the chance tiles!!!
- {
- me.chance = 90;
- }
- break;
- case "Immolate":
- // UHHHHH
- // get current tile and damage any sheep in the surrounding area
- for (cnt = 0; cnt < 3; cnt++) {
- if (me.r < 6 || me.r > 10) {
- if (targets[cnt].r == (me.r + 1)
- && targets[cnt].t == Math.ceil(me.t / 2)) {
- targets[cnt].damage(1);
- } else if (targets[cnt].r == me.r
- && Math.abs(targets[cnt].t - me.t) == 1) {
- targets[cnt].damage(1);
- } else if (targets[cnt].r == (me.r - 1)
- && me.t == (int) Math.ceil(targets[cnt].t / 2)) {
- targets[cnt].damage(1);
- }
- } else {
- if (me.r == (targets[cnt].r + 1)
- && targets[cnt].t == Math.ceil(me.t / 2)) {
- targets[cnt].damage(1);
- } else if (targets[cnt].r == me.r
- && Math.abs(targets[cnt].t - me.t) == 1) {
- targets[cnt].damage(1);
- } else if (me.r == (targets[cnt].r - 1)
- && me.t == (int) Math.ceil(targets[cnt].t / 2)) {
- targets[cnt].damage(1);
- }
- }
- }
- break;
- case "Diagonal Move":
- // ???
- String horizontal;
- String vertical;
- do {
- horizontal = JOptionPane.showInputDialog("Left / Right?");
- } while (!horizontal.toLowerCase().equals("left")
- && !horizontal.toLowerCase().equals("right"));
- me.mover(horizontal);
- do {
- vertical = JOptionPane.showInputDialog("Forward / Backward?");
- } while (!horizontal.toLowerCase().equals("forward")
- && !horizontal.toLowerCase().equals("backward"));
- me.mover(vertical);
- me.move(null, 0);
- break;
- case "Extra Action":
- // implemented sa ibang class
- // activate register[4]
- break;
- case "Tree Cut":
- // set a tree tile to normal, or damage a sheep
- TreeSkill(board,targets); // OK NA. set or damage! check! :)
- break;
- case "Gravity Sphere":
- // move a sheep with damage (10)
- // ???????
- // 1 TARGET ONLY
- targets[0].damage(10);
- String d = "";
- do {
- d = JOptionPane.showInputDialog("Left / Right?");
- } while (!d.toLowerCase().equals("left")
- && !d.toLowerCase().equals("right"));
- targets[0].move(d, 1);
- break;
- case "Volcano":
- // ???????????????
- // set tiles around the sheep to volcano and damage others
- // errorchecking here - add.
- for (cnt = 0; cnt < 3; cnt++) {
- if (me.r < 6 || me.r > 10) {
- board.b[me.r + 1].row[(int) Math.ceil(me.r / 2.0)].setProperty(7);
- board.b[me.r].row[me.t - 1].setProperty(7);
- board.b[me.r].row[me.t + 1].setProperty(7);
- board.b[me.r - 1].row[2 * me.r].setProperty(7);
- board.b[me.r - 1].row[(2 * me.r) - 1].setProperty(7);
- } else {
- board.b[me.r - 1].row[(int) Math.ceil(me.r / 2.0)].setProperty(7);
- board.b[me.r].row[me.t - 1].setProperty(7);
- board.b[me.r].row[me.t + 1].setProperty(7);
- board.b[me.r + 1].row[2 * me.r].setProperty(7);
- board.b[me.r + 1].row[(2 * me.r) - 1].setProperty(7);
- }
- }
- break;
- case "Mana Flare":
- // ALL OTHER PLAYERS = 3
- // if other sheep useSkill(), damage them, divide damage equally
- for (cntr = 0; cntr < 3; cntr++) {
- for (cnt = 0; cnt < allActions; cnt++) {
- if (targets[cntr].actions[cnt] == 9) {
- targets[cntr].damage(1);
- }
- }
- }
- JOptionPane.showMessageDialog(null, "MANA FLAAAAAARE!");
- break;
- case "Mana Burn":
- // 1 TARGET ONLY
- targets[0].lastmp = targets[0].mp;
- targets[0].mp -= 40;
- break;
- case "Silence":
- // 1 TARGET ONLY
- // cannot change an opponents next action; with chances
- break;
- case "Freeze":
- // set other actions to null
- // EDIT: NG LAHAT NG PLAYERS = 4 (including me sa targets)
- for (cntr = 0; cntr < 4; cntr++) {
- for (cnt = 0; cnt < allActions; cnt++) {
- targets[cntr].lastactions[cnt] = targets[cntr].actions[cnt];
- targets[cntr].actions[cnt] = 10;
- }
- }
- break;
- case "Minimize":
- // LAHAT NG PLAYERS = 4 (including me sa targets)
- // set move actions to move 1, skill to null
- for (cnt = 0; cnt < 4; cnt++) {
- for (cntr = 0; cntr < allActions; cntr++) {
- targets[cnt].lastactions[cntr] = targets[cnt].actions[cntr];
- targets[cnt].lastmp = targets[cnt].mp;
- switch (targets[cnt].actions[cntr]) {
- case 5:
- targets[cnt].actions[cntr] = 1;
- targets[cnt].mp -= 20;
- break;
- case 6:
- targets[cnt].actions[cntr] = 2;
- targets[cnt].mp -= 20;
- break;
- case 7:
- targets[cnt].actions[cntr] = 3;
- targets[cnt].mp -= 20;
- break;
- case 8:
- targets[cnt].actions[cntr] = 4;
- targets[cnt].mp -= 20;
- break;
- case 9:
- targets[cnt].actions[cntr] = 10;
- targets[cnt].mp -= 40;
- break;
- }
- }
- }
- JOptionPane.showMessageDialog(null, "MINIMIZE!!!");
- break;
- case "Sleep":
- // LAHAT NG PLAYERS = 4 (including me sa targets)
- for(cnt = 0; cnt < 4; cnt++)
- targets[cnt].sleep = true;
- JOptionPane.showMessageDialog(null, "Matulog kayo. zzzzzzzz");
- break;
- case "Exchange":
- // 1 PLAYER ONLY
- me.lastskill = me.skill;
- targets[0].lastskill = targets[0].skill;
- me.skill = targets[0].skill;
- targets[0].skill.setSkill("Global Spells; Exchange; Exchange this skill for an opponent's skill; 1");
- break;
- case "Copy":
- // 1 PLAYER ONLY
- me.lastskill = me.skill;
- me.skill = targets[0].skill;
- break;
- case "Negate":
- // reverse skill effect on the user
- break;
- case "Undo":
- // LAHAT NG PLAYERS = 4 (including me)
- for (cnt = 0; cnt < 4; cnt++) {
- if (targets[cnt].lastmp == 500
- && targets[cnt].lasthp == 500
- && targets[cnt].lastr == 500
- && targets[cnt].lastt == 500) {
- JOptionPane.showMessageDialog(null,
- "Nothing to undo. This is the first turn.",
- "Undo.", JOptionPane.ERROR_MESSAGE);
- break;
- }
- targets[cnt].mp = targets[cnt].lastmp;
- targets[cnt].hp = targets[cnt].lasthp;
- targets[cnt].r = targets[cnt].lastr;
- targets[cnt].t = targets[cnt].lastt;
- for (cntr = 0; cntr < allActions; cntr++) {
- targets[cnt].actions[cntr] = targets[cnt].lastactions[cntr];
- }
- targets[cnt].move(null, 0);
- JOptionPane.showMessageDialog(null, "Undo~");
- }
- // reverse all actions
- break;
- case "Mirror":
- // reflect damage
- break;
- case "Switch":
- // 1 TARGET ONLY
- // switch actions with an opponent
- int reg;
- do {
- reg = Integer.parseInt(JOptionPane.showInputDialog("Which register do you want to switch?"));
- } while (reg > 3 || reg < 1);
- me.lastactions[reg] = me.actions[reg];
- targets[0].lastactions[reg] = targets[0].actions[reg];
- int temp;
- temp = targets[0].actions[reg];
- targets[0].actions[reg] = me.actions[reg];
- me.actions[reg] = temp;
- break;
- case "Plant Tree":
- // 1 TARGET ONLY (TILE OR SHEEP)
- // turn a tile into a tree
- do {
- r = Integer.parseInt(JOptionPane.showInputDialog("Plant Trees: Row number?"));
- } while (r < 1 || r > 16);
- do {
- t = Integer.parseInt(JOptionPane.showInputDialog("Plant Trees: Tile Number?"));
- } while (t < 1 || t >= board.b[r].size);
- board.b[r].row[t].setProperty(6);
- break;
- case "Set Trap":
- // TILE TARGET
- // turn a tile into a trap
- do {
- r = Integer.parseInt(JOptionPane.showInputDialog("Set Trap: Row number?"));
- } while (r < 1 || r > 16);
- do {
- t = Integer.parseInt(JOptionPane.showInputDialog("Set Trap: Tile Number?"));
- } while (t < 1 || t >= board.b[r].size);
- board.b[r].row[t].setProperty(9);
- break;
- case "Blink":
- // move 2 squares
- // Manhattan distance
- me.lastr = me.r;
- me.lastt = me.t;
- board.b[me.r].row[me.t].leave();
- do {
- r = Integer.parseInt(JOptionPane.showInputDialog("Blink! : Row number?"));
- t = Integer.parseInt(JOptionPane.showInputDialog("Blink! : Tile number?"));
- if (!board.b[r].row[t].occupy()) {
- JOptionPane.showMessageDialog(null, "Occupied!",
- "Error in Blink.", JOptionPane.ERROR_MESSAGE);
- }
- } while (((Math.abs(me.r - r) + Math.abs(me.t - t)) > 2)
- && !board.b[r].row[t].occupy());
- me.move(null, 0);
- break;
- case "Magic Tunnel":
- // 1 TARGET ONLY
- // move a sheep behind you
- targets[0].teleport(me.r);
- break;
- case "Swap":
- // 1 TARGET ONLY
- me.lastr = me.r;
- me.lastt = me.t;
- targets[0].lastr = targets[0].r;
- targets[0].lastt = targets[0].t;
- r = me.r;
- me.r = targets[0].r;
- targets[0].r = r;
- t = me.t;
- me.t = targets[0].t;
- targets[0].t = t;
- me.move(null, 0);
- targets[0].move(null, 0);
- break;
- case "Return to Start":
- // 1 TARGET ONLY
- targets[0].lastr = targets[0].chance;
- targets[0].lastt = targets[0].t;
- targets[0].r = 0;
- targets[0].t = 4;
- targets[0].move(null, 0);
- break;
- }
- }
- public JPanel TreeSkill(final Board board, final Sheep[] targets) {
- JPanel panel = new JPanel();
- JLabel treeCutSkillLabel = new JLabel();
- JButton clearTreeButton = new JButton();
- JButton damageOpponentButton = new JButton();
- panel.setBackground(new Color(204, 255, 204));
- panel.setBounds(0, 0, 285, 150);
- panel.setLayout(null);
- panel.add(treeCutSkillLabel);
- treeCutSkillLabel.setText("Tree Cut Skill");
- treeCutSkillLabel.setBounds(100, 15, 85, 30);
- panel.add(clearTreeButton);
- clearTreeButton.setForeground(new Color(255, 255, 153));
- clearTreeButton.setBackground(new Color(204, 102, 51));
- clearTreeButton.setText("Clear Tree");
- clearTreeButton.setBounds(10, 59, 106, 61);
- panel.add(damageOpponentButton);
- damageOpponentButton.setForeground(new Color(255, 255, 153));
- damageOpponentButton.setBackground(new Color(204, 102, 51));
- damageOpponentButton.setText("Damage");
- damageOpponentButton.setBounds(155, 55, 119, 61);
- clearTreeButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int rownum = Integer.parseInt(JOptionPane.showInputDialog("Row number?"));
- int tilenum = Integer.parseInt(JOptionPane.showInputDialog("Tile Number?"));
- board.b[rownum].row[tilenum].setProperty(0);
- }
- });
- damageOpponentButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int cnt;
- String whoToDamage = JOptionPane.showInputDialog("Who do you want to damage? :>");
- for(cnt = 0; cnt < 4; cnt++) {
- if(targets[cnt].sheepName.toLowerCase().equals(whoToDamage.toLowerCase())) {
- targets[cnt].damage(1);
- }
- }
- }
- });
- return panel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement