1 Replies - 3542 Views - Last Post: 04 June 2010 - 02:48 PM Rate Topic: -----

#1 Guest_Cody Oltman*


Reputation:

Gridworld Word Search Issue!

Posted 04 June 2010 - 01:33 PM

Okay, so I'm writing a gridworld word search, and the program is no where near done.. But I can show you guys what I have and see why on my grid, it's just printing "wordtile" on one of the grid spaces. 0,1 to be exact. I'll post my code below. I commented stuff out because I used my instructor's sudoku program to work from. I want to just click on the letters for the word, each letter, and it will change color...
import java.util.Random;
import java.awt.Color;

public class WordTile {

    private Boolean start = true;
    private char myLetter;
    private Color myColor;
char randomChar;
Random random = new Random();
    public WordTile(character)
    {
    myLetter = character;
    }

 public char randomCharacter()
 {
 	char[] chars = new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',};
 int r = random.nextInt(chars.length);
 return myLetter = chars[r];
 }


protected WordTile changeColor(){
        myColor = Color.MAGENTA;
        return this;
    }

    //public void setValue(int x){
       // if(((myColor == Color.magenta)&&(x>0))&&(x<10))
//            myLetter = x;
   // }

  //  public String getText()
    {
//        return ""+myValue;
  //  }

   // protected int getValue()
    {
   //     return myLetter;
   // }

   // public Color getColor()
    ///{
       // return myColor;
    //}
}


import info.gridworld.grid.BoundedGrid;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;
import info.gridworld.world.World;
import java.awt.Color;
import javax.swing.*;
import java.lang.Math;
import java.util.*;

public class WordGrid extends World<WordTile>
{

  Grid<WordTile> grid;
   Location loc = new Location(0,0);
Location loc1 = new Location(0,1);
Location loc2 = new Location(0,2);
Location loc3 = new Location(0,3);
Location loc4 = new Location(0,4);
Location loc5 = new Location(0,5);
Location loc6 = new Location(0,6);
Location loc7 = new Location(0,7);
Location loc8 = new Location(0,8);
Location loc9 = new Location(0,9);
Location loc10 = new Location(0,10);
   public WordGrid ()
   {

       grid=getGrid();

    }

   public void setDefaultGrid()
   {
 WordTile tile = new WordTile(WordTile.randomCharacter());


}

   public boolean locationclicked(Location loc)
   {


return true;
    }




}


import info.gridworld.world.World;


public class Main
{
    public static void main(String[] args)
        {
            WordGrid world = new WordGrid();
            world.setDefaultGrid();
            world.setMessage("Find the Words!");
            world.show();
        }
}


Is This A Good Question/Topic? 0

Replies To: Gridworld Word Search Issue!

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: Gridworld Word Search Issue!

Posted 04 June 2010 - 02:48 PM

Since GridWorld already has the Actor class with a setColor() method, the easiest thing to do would be to subclass Actor and override the act() method so that it changes the color between two options. Then you can select the tile, and click act(). This is the easy way to do things. By doing things the way you are describing, you'd probably have to dig down into the lower-levels of GridWorld that require more advanced knowledge of Swing and AWT GUIs, like Listeners.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1