1 Replies - 3682 Views - Last Post: 21 July 2013 - 12:48 PM Rate Topic: -----

#1 coldbro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-June 13

Question: setMessage repaint

Posted 02 June 2013 - 06:26 PM


In my program, I am trying to make it when ever pacman eats a bit the score changes in the message board. In my pacman class I have it set up where everytime pacman eats a bit it adds one to the score.i use
to get the score.

any help would be much appreciated

import info.gridworld.gui.*;
import info.gridworld.grid.Location;
import info.gridworld.grid.Grid;
import info.gridworld.grid.*;
import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.PacMan;
import info.gridworld.actor.Blinky;
import info.gridworld.actor.Inky;
import info.gridworld.actor.Clyde;
import info.gridworld.actor.Pinky;
import info.gridworld.actor.Black;
import info.gridworld.actor.Bit;

import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.Actor;

import java.awt.Color;
import java.awt.event.KeyEvent;

public class PacManGame
  private static ActorWorld world = new ActorWorld();
  private static PacMan pac = new PacMan();
  private static Pinky pink = new Pinky();
  private static Blinky blink = new Blinky();
  private static Inky ink = new Inky();
  private static Clyde clyde = new Clyde();
  Black border = new Black();
  public static void main(String[] args)
    System.setProperty("info.gridworld.gui.selection", "hide");
    System.setProperty("info.gridworld.gui.tooltips", "hide");
    world.add(new Location(8,8), pac);
    world.add(new Location(6,9), pink);
    world.add(new Location(6,8), blink);
    world.add(new Location(5,8), ink);
    world.add(new Location(5,9), clyde);
    world.setMessage("Score: " + pac.getScore());
      .addKeyEventDispatcher(new java.awt.KeyEventDispatcher() {
      public boolean dispatchKeyEvent(KeyEvent e) { 
        String key = javax.swing.KeyStroke.getKeyStrokeForEvent(e).toString(); 
        Location loc = pac.getLocation();
        if(key.equals("pressed UP"))
        if(key.equals("pressed DOWN"))
        if(key.equals("pressed LEFT"))
        if(key.equals("pressed RIGHT"))
        return true; 
//rest doesn't matter 

Is This A Good Question/Topic? 0
  • +

Replies To: Question: setMessage repaint

#2 lego freak17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-July 13

Re: Question: setMessage repaint

Posted 21 July 2013 - 12:48 PM

You need to set the message and recall the show() method every time PacMan eats a bit in order for it to repaint the new message.
setMessage("Score: "+pac.getScore());

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1