Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi my question pretains to Java programing, What I am creating is a multi lab pa

ID: 3790730 • Letter: H

Question

Hi my question pretains to Java programing, What I am creating is a multi lab pacman type game.

This part 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 and i think use a construtor to pass the movement through the player classe.

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
      
   }

This is the overall goal for the project for this part of the lab I basically just neeed to have two player movemet across the Jpanel so I believe I just need to use a consturer to make two instances of the player class that uses different movement

Explanation / Answer

This recreation developed out of a final task in CS1 (First programming course in Java) for which I constructed a simple Pacman implementation with the maze, a % man and dots for the % guy to eat. For this, I created a complete of 8 Pacman pix, one in every of that's displayed relying on route with alternating open/closed mouth. The Pacman movements round criminal positions randomly and eats the dots. My professor (Dennis Higgins, SUNY Oneonta) was interested in this project and i persisted running on it in a Modeling path. I next added a blue ghost and whilst he changed into correctly navigating the maze with random actions, I introduced several extra ghosts of different colorations. With checking to see if the sport has ended (ghost catches Pacman or Pacman eats all the dots) this 2d increment become completed. The very last model helps "clever" ghosts, which use shortest route length checking to attempt to capture the Pacman. We also desire to add a joystick for interactivity. despite the fact that the maximum important function of the game is the images illustration, the implementation includes multi-threading the use of synchronized strategies and algorithms from CS2 (information systems)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote