![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
How do I clear the screen?
How do I clear the screen when I restart the "game" with a loop?
import cs1.Keyboard;
import java.util.*;
public class HiLo
{
public static void main (String[] args)
{
int play = 1;
while(play > 0)
{
Random generator = new Random();
int answer = generator.nextInt(100)+1;
System.out.println("The computer is thinking of a number \nbetween 1 and 100. What is it?");
int escape = 0;
while(escape < 1)
{
int guess = Keyboard.readInt();
if(guess == answer)
{
System.out.println("That's it");
escape = 1;
}
else if(guess > answer)
{
System.out.println("Too High");
}
else if(guess < answer)
{
System.out.println("Too Low");
}
}
System.out.println("Would you like to play again (y/n)");
char again = Keyboard.readChar();
if(again == 'y')
{
play = 1;
}
else if(again == 'n')
{
play--;
}
}
}
} |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 730
Rep Power: 4
![]() |
Could try the escape code for clearing the screen
System.out.print ("\033c");http://vt100.net/docs/vt102-ug/chapter5.html Your mileage may vary.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Where would i put that?
|
|
|
|
|
|
#4 | |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 3
![]() |
Quote:
![]() if the code doesn't work, you can also print 30 newlines, that will also clear the screen. |
|
|
|
|
|
|
#5 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 730
Rep Power: 4
![]() |
The code I gave you is an standard terminal escape code. It should work beautifully on everything *but* Windows. Microsoft's cmd is a terminal wannabe.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#6 |
|
Expert Programmer
|
I need it to clear the screen if
again == y |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Then stick it in a while loop:
while (again == 'y')
{
...
} |
|
|
|
|
|
#8 |
|
Expert Programmer
|
That did not work
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() |
Show us what you tried...
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|