+ 2

Getting My Text-Based Display to Not Repeat

Hi Guys, i am working on a text-based version of tic tac toe for learning purposes. I'e made it a double array that displays 9 pieces in a grid like this. To keep the display simple, I chose to create a an array to display as a table. how do i get it to update each piece without the entire board repeatedly being displayed. This is the original display 1 2 3 4 5 6 7 8 9 Each user picks a number and the board updates. the only problem is that every time the board is updated to an X or an O in the selected numeral, the entire board is duplicated. the whole board is duplicated like this: Original 1 2 3 4 5 6 7 8 9 Player One Makes a Moe 1 X 3 4 5 6 7 8 9 I was hoping to create a text-based game without using java libraries like AWT, but any suggestions would be very helpful. I'm stuck. Thank you My Code: public void playGame() { disPlay(); while(won=='L') { turns(); disPlay(); if(turnsCompleted>4) {checkRow_Column_Diagonal_For_Match();} if(turnsCompleted==9&&NoMatchesFound==8) {won='l';} } input.close(); winner(); } public void sampleDisplay() { int count=0; for(row=0;row<3;row++) { for(col=0;col<3;col++) { if(count==selection.length) {break;} display[row][col]=selection[count]; System.out.print(display[row][col]+" "); count++; } System.out.println(); }

18th Jan 2020, 12:21 AM
Mich
Mich - avatar
12 Answers
+ 2
I have done a complete console version of a go board where you enter moves by typing coordinates. I also found no real solution, because it seems to depend on the functionality your operating system's console is offering. Some seem to allow screen clearing and cursor back movement, but others don't, so eventually I accepted it as 'console flavor'. Excited to hear what others will say.
18th Jan 2020, 12:36 AM
HonFu
HonFu - avatar
+ 2
you could look at "ncurses" c/c++ library wich provide terminal (text based) helpful handler: I hadn't try some in java, but tried the python bind livrary... not very easy to use, but easiest than reinvent the wheel ;) http://rememberjava.com/cli/2017/01/22/ncurses_terminal_libs.html
18th Jan 2020, 10:48 AM
visph
visph - avatar
+ 2
ncurses advantage is that it already give support for large terminal/os compatibility... but if your purpose is just to support only one terminal/os combination, it's possible to write your own: you need to use "ansi csi escape codes" ( https://en.m.wikipedia.org/wiki/ANSI_escape_code )... and adapt / find wich command are working / suitable for your specific target ^^
18th Jan 2020, 2:31 PM
visph
visph - avatar
+ 2
support of different ansi escape codes mostly depend on terminal used (and so, it's very related to os running terminal)... that's where the old and robust ncurses c/c++ library will save lot of development/debug time (and that's why this library is bound to many other languages).
18th Jan 2020, 3:52 PM
visph
visph - avatar
+ 1
I have a mac. Thank you HonFu. Happy coding!
18th Jan 2020, 1:01 AM
Mich
Mich - avatar
+ 1
I'll check it out, thank you
18th Jan 2020, 2:15 PM
Mich
Mich - avatar
+ 1
But that's the whole problem I was talking about above: As soon as you want to use special functions of console, you might lose compatibility. Have you thought about making a tkinter app instead? What you want to do doesn't need a lot of knowledge, you'll be able to do that much quickly.
18th Jan 2020, 3:50 PM
HonFu
HonFu - avatar
+ 1
HonFu what is a tkinter app? I've never heard of it. My goal with tic tac to was to get over the hurdle of creating a first project. Does creating this other app mean I'm starting over again? I was hoping to have a project completed just to create momentum and gain more of the skill of programming.
18th Jan 2020, 4:13 PM
Mich
Mich - avatar
0
Visph, I was hoping that users of different OS could play the game. I wanted to keep the actual display simple where you see the 1 board and separate place where the user inputs a number. Could you clarify your answer a bit more? Thank you
18th Jan 2020, 3:45 PM
Mich
Mich - avatar
0
Mich, tkinter is a module that comes with Python's basic installation and allows you to make programs with a graphical interface (windows etc). If you want to just go for a project to get going, I wouldn't worry about the output now so much. Who cares if the field is output over and over? The main thing is that the program does what it's supposed to do! And later, after you get a bit of experience and confidence, you make a tkinter version of it.
18th Jan 2020, 4:21 PM
HonFu
HonFu - avatar
0
Ok thank you. I dont know python, but it's worth checking out. I'm happy with the logic of my program in java -- I got it to work without errors. That part is complete. I didnt paste it here. I thought my project was not good enough because the array I used to create a display would repeatedly display every time the game state was updated. Ive finished the game aspect of it. but I've been very frustrated with the display. I really appreciate the help and support.
18th Jan 2020, 4:27 PM
Mich
Mich - avatar
0
Thank you both for your help and support. I'm really grateful
18th Jan 2020, 4:32 PM
Mich
Mich - avatar