Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 1st, 2005, 11:18 PM   #1
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 572
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
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--;
        }
    }
       
    }
}
crawforddavid2006 is offline   Reply With Quote
Old Oct 1st, 2005, 11:23 PM   #2
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Old Oct 2nd, 2005, 10:51 AM   #3
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 572
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Where would i put that?
crawforddavid2006 is offline   Reply With Quote
Old Oct 2nd, 2005, 11:47 AM   #4
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 3 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by crawforddavid2006
Where would i put that?
where you want to clear the screen

if the code doesn't work, you can also print 30 newlines, that will also clear the screen.
Polyphemus_ is offline   Reply With Quote
Old Oct 2nd, 2005, 12:30 PM   #5
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Old Oct 2nd, 2005, 6:48 PM   #6
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 572
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
I need it to clear the screen if
again == y
crawforddavid2006 is offline   Reply With Quote
Old Oct 3rd, 2005, 4:20 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Then stick it in a while loop:
while (again == 'y')
{
    ...
}
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Oct 4th, 2005, 5:40 PM   #8
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 572
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
That did not work
crawforddavid2006 is offline   Reply With Quote
Old Oct 4th, 2005, 5:48 PM   #9
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Show us what you tried...
__________________

tempest is offline   Reply With Quote
Old Oct 4th, 2005, 5:48 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Did you set again first?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC