• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Printing a point with a certain coordinates

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 14488
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 14488
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 9712
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic