I know I need to use an if statement in order to determine if "x" or "o" is the winner or if there is a tie. At one point I was able to get the screen that shows up to say TIE, but it did it even if x or o went. I really have no idea what could improve the code. Any help is greatly appreciated.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Winner here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Winner extends World
{
private int clicks;
/**
* Constructor for objects of class Winner.
*
*/
public Winner(String letter)
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
GreenfootImage bg = getBackground(); //getting the background image
bg.setColor(Color.magenta);
if(Greenfoot.mouseClicked("o"))
{
bg.drawString("Congratulations, O is the WINNER!", 300, 200);
}
else
if(Greenfoot.mouseClicked("x"))
{
bg.drawString("Congratulations, X is the WINNER!", 300, 200);
}
else
if(clicks >= 9)
{
bg.drawString("TIE", 300, 200);
}
}
