This is Java What I am creating is a multi lab pacman type g

This is Java, What I am creating is a multi lab pacman type game.

This one covers movement. I basically need my code below to meet the labs requiremnts. IE I need this game to allow two players to move.

Thanks for the help

included is some codes

import javax.swing.JFrame;

public class MainFrame {

   public static void main(String[] args)
   {
       // create the frame
       JFrame myFrame = new JFrame(\"Platformer\");
      
       // set up the close operation
       myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       // create panel
       MainPanel myPanel = new MainPanel();
       // add panel
       myFrame.getContentPane().add(myPanel);
       // pack
       myFrame.pack();
       // set visibility to true
       myFrame.setVisible(true);
   }
}

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class MainPanel extends JPanel implements KeyListener{

   int x = 0;
   int y = 0;
   ImageIcon myIcon = new ImageIcon(\"./src/TreasureChest.png\");
   public MainPanel()
   {
       setPreferredSize(new Dimension(1000,1000));
       addKeyListener(this);
       setFocusable(true);
   }

   public void paintComponent(Graphics page)
   {
       super.paintComponent(page);
       page.drawImage(myIcon.getImage(), x, y, null);
   }
     
   @Override
   public void keyPressed(KeyEvent arg0) {
       int keyCode = arg0.getKeyCode();
      
       if (keyCode == KeyEvent.VK_LEFT)
       {

           x -= 100;
       }
       else if (keyCode == KeyEvent.VK_RIGHT)
       {

           x += 100;
       }
       else if (keyCode == KeyEvent.VK_UP)
       {

           y -= 100;
       }
       else if (keyCode == KeyEvent.VK_DOWN)
       {

           y += 100;
       }
       repaint();
      
   }

   @Override
   public void keyReleased(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void keyTyped(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }
  

Requirements for this lab: 1. Choose between two different files that contain two separate players containing their attribute values 2. Parse each line and populate the appropriate classes with the information Print out the object using the classes\' toString method to ensure the object properties are filled 4. You should also be able to create a player at this point. 5. Each player should be able to move at this point as well.

Solution

import javax.swing.JFrame;

public class MainFrame {

   public static void main(String[] args)
   {
       // create the frame
       JFrame myFrame = new JFrame(\"Platformer\");
      
       // set up the close operation
       myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       // create panel
       MainPanel myPanel = new MainPanel();
       // add panel
       myFrame.getContentPane().add(myPanel);
       // pack
       myFrame.pack();
       // set visibility to true
       myFrame.setVisible(true);
   }
}

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class MainPanel extends JPanel implements KeyListener{

   int x = 0;
   int y = 0;
   ImageIcon myIcon = new ImageIcon(\"./src/TreasureChest.png\");
   public MainPanel()
   {
       setPreferredSize(new Dimension(1000,1000));
       addKeyListener(this);
       setFocusable(true);
   }

   public void paintComponent(Graphics page)
   {
       super.paintComponent(page);
       page.drawImage(myIcon.getImage(), x, y, null);
   }
     
   @Override
   public void keyPressed(KeyEvent arg0) {
       int keyCode = arg0.getKeyCode();
      
       if (keyCode == KeyEvent.VK_LEFT)
       {

           x -= 100;
       }
       else if (keyCode == KeyEvent.VK_RIGHT)
       {

           x += 100;
       }
       else if (keyCode == KeyEvent.VK_UP)
       {

           y -= 100;
       }
       else if (keyCode == KeyEvent.VK_DOWN)
       {

           y += 100;
       }
       repaint();
      
   }

   @Override
   public void keyReleased(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void keyTyped(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }

This is Java, What I am creating is a multi lab pacman type game. This one covers movement. I basically need my code below to meet the labs requiremnts. IE I ne
This is Java, What I am creating is a multi lab pacman type game. This one covers movement. I basically need my code below to meet the labs requiremnts. IE I ne
This is Java, What I am creating is a multi lab pacman type game. This one covers movement. I basically need my code below to meet the labs requiremnts. IE I ne
This is Java, What I am creating is a multi lab pacman type game. This one covers movement. I basically need my code below to meet the labs requiremnts. IE I ne

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site