• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a point with a certain coordinates  RSS feed

 
Vladimir Glushko
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, guys.

I have a symbol '*' and its coordinates: x = 1, y = 3.

How can I print above symbol on the screen with mentioned coordinates? As far as I know in C# there's a method SetCursorPosition(x,y), but i couldn't find same in Java. Presently i've made class Point with description of point and its coordinates, and main class, which assigns values. Listing is below:



But now i need set cursor position (1, 3) and print '*' in this position. Is this possible?

Thank you in advance for help!

P.S. Not sure, if it's important, but I'm not using IDE, just command line.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the command line, it's probably easiest to print the entire playing field on every game turn.

Make a class called something like Game, which has a toString() method in which you print the entire playing field, line by line. Then, in your main game loop, you just call System.out.println(game) before every turn.
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:When you use the command line, it's probably easiest to print the entire playing field on every game turn.

Make a class called something like Game, which has a toString() method in which you print the entire playing field, line by line. Then, in your main game loop, you just call System.out.println(game) before every turn.


how will he clear the screen in his game loop ?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't. You either adjust the height of the console to the game, or you first print a bunch of empty lines to clear the previous turn.
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:You don't. You either adjust the height of the console to the game, or you first print a bunch of empty lines to clear the previous turn.


Sounds like a bad idea.

Vladimir Glushko, I think you can look into swing, your game can be ported into graphics instead of a Character User Interface
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. Swing is probably the way to go.

When the game of Snake was popular terminals supported ANSI escape sequences (https://en.wikipedia.org/wiki/ANSI_escape_code) for moving the cursor around. IF your terminal/console supports ANSI, it is certainly not a platform independent solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!