@Override
	public void windowClosed(WindowEvent arg0)
	{

		// This checks territories and based on that, it calculates the score.
		processTerritories();
		for (Territory t : territories)
		{
			switch (t.team())
			{
				case 0:
					continue;
				case 1:
					blackScore += t.squares.size();
					break;
				case 2:
					whiteScore += t.squares.size();

			}
		}
		// This takes the score of black and the score of white, compares them and displays the
		// appropriate message
		if (whiteScore > blackScore)
			JOptionPane.showMessageDialog(null, "WHITE WINS!!! \nWhite scored " + whiteScore + " points, and Black scored " + blackScore + " points");
		else if (blackScore > whiteScore)
			JOptionPane.showMessageDialog(null, "BLACK WINS!!! \nWhite scored " + whiteScore + " points, and Black scored " + blackScore + " points");
		else
			JOptionPane.showMessageDialog(null, "ITS A TIE!!! \nWhite scored " + whiteScore + " points, and Black scored " + blackScore + " points");

		// This saves the game(if the user wants to) to a file named saves as a png, then exits the
		// program.
		name = JOptionPane.showInputDialog("What is the name of this game?");
		if (name != null)
			try
			{
				new File("Saves").mkdir();
				ImageIO.write(image, "png", new File("Saves/" + name + ".png"));
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		System.exit(0);
	}