Pokemon

This is a very simple version of pokemon. All of them have the same type, because I simply haven't added the others yet
but the system has already been implemented. Also, the pokemon are "invisible" because I haven't added graphics for each
of the pokemon yet.

import java.util.Scanner;
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;

public class World extends JPanel{
    
    Timer timer;
    int pWidth = 20;
    int pHeight = 20;
    
    int[][] worldArray;
    int worldX = 100;
    int worldY = 100;
    
    int oSize = 20;
    
    boolean lPress;
    int state = 0;
    
    Pokemon pokemon;
    Pokemon[] invPokemon;
    
    int mouseX = 0;
    int mouseY = 0;
    
    int turn = 0;
    
    int invSlot = 0;
    
    int score = 0;
    
    /*
    Move Types:
    -0: Normal
    -1: Fire
    -2: Water
    -3: Grass
    -4: Rock
    
    Move Attributes:
    -0: Attack Enemy
    -1: Speed
    -2: Damage
    -3: Defence  
    */
    
    /*
    States:
    -0: Movement
    -1: Transition to fight
    -2: Redrawing of the fight
    -3: Fight
    */
    
    //Moves(double magnitude, double attribute, double type, String name, int num, boolean onSelf)
    Player p;
    public static Move[] moves = {new Move(10, 0, 0, "Tackle", 35, false),
                    new Move(15, 0, 0, "Punch", 30, false),
                    new Move(20, 0, 0, "Super Kick", 10, false),
                    new Move(5, 2, 0, "Agility", 15, true),
                    new Move(5, 2, 0, "Tar Toss", 15, false),
                    new Move(5, 1, 0, "Work Out!", 15, true),
                    new Move(5, 1, 0, "Weaken", 15, false),
                    new Move(10, 0, 1, "Fireball", 30, false),
                    new Move(15, 0, 1, "Fire Punch", 20, false),
                    new Move(25, 0, 1, "Flamethrower", 7, false),
                    new Move(10, 0, 1, "Flame Up!", 10, true)                   
        };
    
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        if(state == 0){
            for(int x = 0; x < worldX; x++){
                for(int y = 0; y < worldY; y++){

                    int tileType = worldArray[x][y];

                    if(tileType == 1){
                        g.setColor(new Color(107, 75, 34));
                        g.fillRect(x*oSize - oSize/2 - (int)Math.round(p.getWX()*20) + 320, y*oSize - oSize/2 - (int)Math.round(p.getWY()*20) + 240, oSize, oSize);
                        //System.out.println( "x: " + x + " y: " + y + " " + tileType);
                    }
                    else if(tileType == 2){
                        g.setColor(new Color(40, 172, 26));
                        g.fillRect(x*oSize - oSize/2 - (int)Math.round(p.getWX()*20) + 320, y*oSize - oSize/2 - (int)Math.round(p.getWY()*20) + 240, oSize, oSize);
                    }
                }
            }
            
            g.setColor(new Color(34, 20, 46));
            g.fillRect(320 - pWidth/2, 240 - pHeight/2, pWidth, pHeight);
        }
        else if(state == 3){
            
            g.setColor(new Color(204, 173, 129));
            g.fillOval(400, 150, 200, 30);
            g.fillOval(100, 300, 250, 40);
            g.setColor(new Color(102, 79, 47));
            g.drawOval(400, 150, 200, 30);
            g.drawOval(100, 300, 250, 40);
            
            drawTextBox(410, 400, 200, 50, invPokemon[0].getMove(0).getName() + "      " + invPokemon[0].getMove(0).getMovesLeft() + "/" + invPokemon[0].getMove(0).getNum(), new Color(255, 255, 255), g);
            drawTextBox(210, 400, 200, 50, invPokemon[0].getMove(1).getName() + "      " + invPokemon[0].getMove(1).getMovesLeft() + "/" + invPokemon[0].getMove(1).getNum(), new Color(255, 255, 255), g);
            drawTextBox(410, 350, 200, 50, invPokemon[0].getMove(2).getName() + "      " + invPokemon[0].getMove(2).getMovesLeft() + "/" + invPokemon[0].getMove(2).getNum(), new Color(255, 255, 255), g);
            drawTextBox(210, 350, 200, 50, invPokemon[0].getMove(3).getName() + "      " + invPokemon[0].getMove(3).getMovesLeft() + "/" + invPokemon[0].getMove(3).getNum(), new Color(255, 255, 255), g);
            
            drawTextBox(0, 350, 70, 30, "Run", new Color(255, 255, 255), g);
            
            drawTextBox(364, 280, 100, 30, invPokemon[invSlot].getName(), new Color(255, 255, 255), g);
            drawTextBox(288, 113, 100, 30, pokemon.getName(), new Color(255, 255, 255), g);
            
            drawTextBox(0, 0, 175, 30, pokemon.getName() + " uses " + pokemon.getLastMove().getName(), new Color(255, 255, 255), g);
            drawTextBox(0, 30, 175, 30, invPokemon[invSlot].getName() + " uses " + invPokemon[invSlot].getLastMove().getName(), new Color(255, 255, 255), g);
            
            drawHpBar(364, 317, 100, 4, invPokemon[invSlot].getHp(), invPokemon[invSlot].getTotalHp(), Color.RED, g);
            drawHpBar(288, 150, 100, 4, pokemon.getHp(), pokemon.getTotalHp(), Color.RED, g);
        }
        else if(state == 4){
            drawTextBox(210, 233, 210, 30, "You Lose! Your score was " + score, new Color(255, 255, 255), g); 
        }
        
    }
    
    public void setupFight(){
        pokemon = new Pokemon(0, 100, "Box");
    }
    
    public void drawTextBox(int x, int y, int width, int height, String text, Color color, Graphics g){
        g.setColor(color);
        g.fillRect(x, y, width, height);
        g.setColor(new Color(0, 0, 0));
        g.drawRect(x, y, width, height);
        g.drawString(text, x + 20, y + 20);
    }
    
    public void drawHpBar(int x, int y, int width, int height, double hp, double totalHp, Color color, Graphics g){
        
        g.setColor(new Color(170, 170, 170));
        g.fillRect(x - 3, y - 15, width + 6, height + 18);
        g.setColor(new Color(0, 0, 0));
        g.drawRect(x - 3, y - 15, width + 6, height + 18);
        g.setColor(new Color(255, 255, 255));
        g.fillRect(x, y, width, height);
        g.setColor(color);
        g.fillRect(x, y, (int)(Math.round( (hp/totalHp) * width )), height);
        g.setColor(new Color(0, 0, 0));
        g.drawRect(x, y, width, height);
        g.drawString(hp + "/" + totalHp, x - 1, y - 1);
        
    }
    
    public boolean getOver(int x, int y, int width, int height){
        if(mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height){
            return true;
        }
        else{
            return false;
        }
    }
    
    public static void main(String[] args){
        
        World world = new World();
        
        world.setLayout(new BorderLayout());
        world.setBackground(Color.GREEN);
        JFrame window = new JFrame("World");
        window.setContentPane(world);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setSize(640, 480);
        window.setLocation(100, 100);
        window.setVisible(true);
        
        world.setFocusable(true);
        world.requestFocusInWindow();
        //snakeJ.requestFocus();
        System.out.println("Focus requested");
        
    }
    
    public class mouseListener implements MouseListener{
        
        public void mouseClicked(MouseEvent e){
            mouseX = e.getX();
            mouseY = e.getY();
            
            if(state == 3){
                //Move 1
                if(getOver(410, 400, 200, 50)){
                    invPokemon[invSlot].useMove(0, pokemon);
                    invPokemon[invSlot].setLastMove(invPokemon[invSlot].getMove(0));
                    turn = 2;
                }
                //Move 2
                else if(getOver(210, 400, 200, 50)){
                    invPokemon[invSlot].useMove(1, pokemon);
                    invPokemon[invSlot].setLastMove(invPokemon[invSlot].getMove(1));
                    turn = 2;
                }
                //Move 3
                else if(getOver(410, 350, 200, 50)){
                    invPokemon[invSlot].useMove(2, pokemon);
                    invPokemon[invSlot].setLastMove(invPokemon[invSlot].getMove(2));
                    turn = 2;
                }
                //Move 4
                else if(getOver(210, 350, 200, 50)){
                    invPokemon[invSlot].useMove(3, pokemon);
                    invPokemon[invSlot].setLastMove(invPokemon[invSlot].getMove(3));
                    turn = 2;
                }
                //Run
                else if(getOver(0, 350, 70, 30)){
                    state = 0;
                    System.out.println("Run");
                    repaint();
                }
                repaint();
            }
            
        }
        public void mouseEntered(MouseEvent e){
        
        }
        public void mouseExited(MouseEvent e){
        
        }
        public void mousePressed(MouseEvent e){
        
        }
        public void mouseReleased(MouseEvent e){
        
        }
        
    }
    
    public class keyListener implements KeyListener, FocusListener {
        
        public void focusGained(FocusEvent e){
            System.out.println("Focus Gained");
            repaint();
        }
        
        public void focusLost(FocusEvent e){
            repaint();
            System.out.println("Focus Lost");
        }
        
        public void keyPressed(KeyEvent e){
        
            int key = e.getKeyCode();
            double mag = .01;
            //System.out.println("Key Pressed");
            
            if(key == KeyEvent.VK_RIGHT) {
                repaint();
                p.startMoving(mag, 0, key);
            }
            if(key == KeyEvent.VK_LEFT) {
                repaint();
                p.startMoving(-mag, 0, key);
            }
            if(key == KeyEvent.VK_UP) {
                repaint();
                p.startMoving(0, -mag, key);
            }
            if(key == KeyEvent.VK_DOWN) {
                repaint();
                p.startMoving(0, mag, key);
            }
        
        }
        public void keyReleased(KeyEvent e){
            int key = e.getKeyCode();
            
            if(key == p.getKey()){
                p.stopMoving();
            }
        }
        public void keyTyped(KeyEvent e){
            
        }
    
    }
    
    public World(){
        
        worldArray = new int[worldX][worldY];
        generateWorld();
        keyListener listener = new keyListener();
        mouseListener mouseLis = new mouseListener();
        
        addKeyListener(listener);
        addFocusListener(listener);
        addMouseListener(mouseLis);
        
        p = new Player(10, 10);
        System.out.println("Player created");
        invPokemon = new Pokemon[6];
        Pokemon poke = new Pokemon(0, 100, "Red Box");
        invPokemon[0] = poke;
        
        System.out.println("Pokemon created");
        
        timer = new Timer();
        timer.schedule(new Task(), 0, 1);
        
        System.out.println("Timer scheduled");
    }
    
    class Task extends TimerTask{
    
        public void run(){
            
            if(p.getIsMoving() == true){
                if(state == 0){
                    p.move();
                    repaint();
                    int pX = (int)Math.round(p.getWX());
                    int pY = (int)Math.round(p.getWY());
                    
                    double random = Math.random();
                    
                    if(worldArray[pX][pY] == 2 && random < .001){
                        state = 3;
                        turn = 1;
                        setupFight();
                    }
                }
            }
            if(state == 1){
                int rectCount = 10;
                for(int i = 0; i < rectCount; i++){
                    if(i % 2 == 0){
                    
                    }
                    else{
                    
                    }
                }
            }
            if(state == 3){
                if(pokemon.getHp() <= 0){
                    score++;
                    state = 0;
                }
                else if(invPokemon[invSlot].getHp() <= 0){
                    state = 4;
                    repaint();
                }
                if(turn == 2){
                    int moveNum = (int)(Math.round(Math.random() * 3));
                    pokemon.useMove(moveNum, invPokemon[invSlot]);
                    pokemon.setLastMove(pokemon.getMove(moveNum));
                    turn = 1;
                    repaint();
                }
            }
            
        }
    
    }
    
    public static Move getMoves(int mNum){
        
        if(mNum < moves.length){
            return moves[mNum];
        }
        else{
            return null;
        }
    }
    
    public static int getMoveCount(){
        return moves.length;
    }
    
    public void generateWorld(){
        
        for(int x = 0; x < worldX; x++){
            for(int y = 0; y < worldY; y++){
                
                //Generates a fence that surrounds the world
                if(x == worldX - 1 || y == worldY - 1 || x == 0 || y == 0){
                    worldArray[x][y] = 1;
                }
                
                //Generates a random patch of grass
                double random = Math.random();
                if(random < .01){
                    int patchSize = 10;
                    for(int x1 = x; x1 < constrainX(x + patchSize, worldX - 1); x1++){
                        for(int y1 = y; y1 < constrainY(y + patchSize, worldY - 1); y1++){
                            worldArray[x1][y1] = 2;
                        }
                    }
                }
                
            }
        }
    }
    
    public int constrainX(int tx, int con){
        if(tx >= con){
            tx = con - 1;
        }
        else if(tx < 0){
            tx = 0;
        }
        return tx;
    }
    
    public int constrainY(int ty, int con){
        if(ty >= con){
            ty = con - 1;
        }
        else if(ty < 0){
            ty = 0;
        }
        return ty;
    }
    
}

class Player{
    
    int x = 0;
    int y = 0;
    
    double wX;
    double wY;
    
    double xD;
    double yD;
    
    int keyCode;
    
    boolean isMoving = false;
    
    public Player(int x, int y){
        this.x = x;
        this.y = y;
        
        wX = x;
        wY = y;
    }
    
    public void move(){
        wX = wX + xD;
        wY = wY + yD; 
    }
    
    public void setPosition(int x, int y){
        this.x = x;
        this.y = y;
    }
    
    public double getWX(){
        return wX;
    }
    public double getWY(){
        return wY;
    }
    
    public boolean getIsMoving(){
        return isMoving;
    }
    
    public void stopMoving(){
        isMoving = false;
    }
    
    public void startMoving(double xd, double yd, int keyC){
        isMoving = true;
        xD = xd;
        yD = yd;
        keyCode = keyC;
    }
    
    public int getKey(){
        return keyCode;
    }
}

class Pokemon{
    
    Move[] moves = new Move[4];
    int type;
    double hp;
    double totalHp;
    String name;
    Random r;
    int slotNum;
    double multiplier = 1;
    Move lastMove;
    
    public Pokemon(int type, double hp, String name){
        r = new Random();
        this.type = type;
        this.hp = hp;
        totalHp = hp;
        this.name = name;
        createMoves();
    }
    
    public void createMoves(){
        for(int i = 0; i < 4; i++){
            while(true){
                Move testMove = World.getMoves(r.nextInt(World.getMoveCount()));
                //System.out.println(testMove.getName());
                if(testMove.getType() == type){
                    moves[i] = (Move) testMove.cloneMove();
                    break;
                }
            }
        }
    }
    
    public void setSlotNum(int slotNum){
        this.slotNum = slotNum;
    }
    
    public int getSlotNum(){
        return this.slotNum;
    }
    
    public Move getMove(int moveNum){
        if(moveNum < moves.length){
            return moves[moveNum];
        }
        else{
            return null;
        }
    }
    
    public void useMove(int moveNum, Pokemon pokemon){
        Move move = moves[moveNum];
        moves[moveNum].use();
        if(move.getAtt() == 0){
            pokemon.damage((int)(Math.round(move.getMag() * multiplier)));
        }
        else if(move.getAtt() == 1){
            multiplier = multiplier * move.getMag();
        }
        else if(move.getAtt() == 2){
            pokemon.changeMultiplier(move.getMag());
        }
    }
    
    public void damage(int damageNum){
        hp = hp - damageNum;
    }
    
    public double getTotalHp(){
        return totalHp;
    }
    
    public double getHp(){
        return hp;
    }
    
    public Move getLastMove(){
        if(lastMove == null){
            return new Move(0, 0, 0, "nothing yet.", 0, false);
        }
        else            
            return lastMove;
        
    }
    
    public String getName(){
        return name;
    }
    
    public void setLastMove(Move setmove){
        lastMove = setmove;
    }
    
    public void changeMultiplier(double mag){
        multiplier = multiplier * (1 - (double)(mag/10));
    }
    
}

class Move implements Cloneable{
    
    double magnitude;
    int attribute;
    int type;
    String name;
    int num;
    boolean onSelf;
    int movesLeft;
    
    public Move(double magnitude, int attribute, int type, String name, int num, boolean onSelf){
        this.magnitude = magnitude;
        this.attribute = attribute;
        this.type = type;
        this.name = name;
        this.num = num;
        movesLeft = num;
        this.onSelf = onSelf;
    }
    
    public double getMag(){
        return magnitude;
    }   
    public double getAtt(){
        return attribute;
    }
    public String getName(){
        return name;
    }
    public int getType(){
        return type;
    }
    public boolean onSelf(){
        return onSelf;
    }
    public int getNum(){
        return num;
    }
    public int getMovesLeft(){
        return movesLeft;
    }
    
    public void use(){
        movesLeft = movesLeft - 1;
    }
    
    public Move cloneMove(){
        try{          
            return (Move) this.clone();
        }
        catch(CloneNotSupportedException e){
            return null;
        }
    }
}