import dk.brics.jwig.runtime.*; import java.util.*; public class BuggyGuess extends Service { int plays = 0; int record = 0; String holder; private static final XML wrap = [[
<[body]> ]]; XML guessdoc = [[ Please guess a number between 0 and 99: ]]; XML again = [[ That is not correct. Try a <[correction]> number: ]]; XML done = [[ You got it, using <[trys]> guesses. ]]; XML recorddoc = [[ That makes you the new record holder! <[old]> Please enter your name for the hi-score list: ]]; XML hiscore = wrap<[body= [[ In <[plays]> plays of this game, the record holder is <[holder]> with <[record]> guesses. ]] ]; public class Play extends Session { public void main() { int number, guesses, guess, r; number = (new Random()).nextInt(100); plays++; show wrap<[body=guessdoc]; guess = Integer.parseInt(receive guess); guesses = 1; while (guess != number) { if (guess > number) { show wrap<[body=again<[correction="lower"]]; guess = Integer.parseInt(receive guess); } if (guess < number) { guess = Integer.parseInt(receive guess); } guesses++; } r = record; if (r == 0 || r >= guesses) { XML x = wrap<[body=recorddoc]; if (holder!=null) { x = x<[old = [[The old record holder was <[name]> with <[record]> guesses.]]] <[holder=holder, record=record]; } show x; holder = receive name; record = guesses; } exit wrap<[body = [[Thank you for playing this exciting game!]] ]; } } }