/* Scrabble : An interactive scrabble playing software. Copyright (C) 1999 Amitabh Sinha All Trademarks and Copyrights pertaining to Scrabble, Java, Linux acknowledged. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact Amitabh at */ import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; public class ScoreScreen extends Canvas { Color white = new Color(255,255,255); Color black = new Color(0,0,0); Color blue = new Color(0,0,255); Color red = new Color(255,0,0); String human; String computer; int humanScore = 0; int computerScore = 0; Font font; public ScoreScreen() { font = new Font("Serif", 0, 14); } public void paint (Graphics g) { g.setPaintMode(); g.setFont(font); g.setColor(white); g.fillRect(0,0,299,39); g.setColor(black); g.drawString(human,1,20); g.drawString(computer,1,38); boolean overshoot = (humanScore>400 || computerScore>400); if (!overshoot) { g.setColor(blue); g.drawLine(73,13,(humanScore/2)+73,13); g.setColor(red); g.drawLine(73,31,(computerScore/2)+73,31); g.setColor(black); Integer humanI = new Integer(humanScore); g.drawString(humanI.toString(),(humanScore/2)+76,20); Integer computerI = new Integer(computerScore); g.drawString(computerI.toString(),(computerScore/2)+76,38); } else { int max = (humanScore>computerScore?humanScore:computerScore); g.setColor(blue); g.drawLine(73,13,(200*humanScore/max)+73,13); g.setColor(red); g.drawLine(73,31,(200*computerScore/max)+73,31); g.setColor(black); Integer humanI = new Integer(humanScore); g.drawString(humanI.toString(),(200*humanScore/max)+76,20); Integer computerI = new Integer(computerScore); g.drawString(computerI.toString(),(200*computerScore/max)+76,38); } } public void setHuman(String s) { human = (s.length()>8?s.substring(0,9):s); } public void setComputer(String s) { computer = (s.length()>8?s.substring(0,9):s); } public void addHuman(int x) { humanScore += x; if (humanScore < 0) humanScore = 0; } public void addComputer(int x) { computerScore += x; if (computerScore < 0) computerScore = 0; } public int getScore(String s) { if (s.equals("human")) return humanScore; else return computerScore; } }