• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

TicTacToe Game

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,
I trying to make a tic tac toe game without buttons. It checks if the user clicked on any of the x, y postions in any of the squared. Now actually making the game, how would I differentiate each single square?

Heres the code


 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without looking at your wall of code, you differentiate between squares by the coordinates of the square. You should have an array that represents the squares, a regular array will do. A certain range of X and Y values represents a square, and thus a position in the array.
 
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I'm trying to write a tic tac toe game using arrays, very simple not pretty but functioning tictactoe. Can anyone help me as to how I'd go about beginning this? This is the idea:


_1_|_2_|_3_
_4_|_5_|_6_
7 | 8 | 9

And then I prompt the user to input a number for the space he/she wants to move.

Ex: 5


_1_|_2_|_3_
_4_| X |_6_
7 | 8 | 9


Of course I need to write it in a way that someone can win, and the computer will understand the legal moves.

Any ideas?
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's some very basic (and very messy) tictactoe code. Please don't take it as a finished project, it was just thrown together as an exercise. Basic idea is that you're array for square values can also be used to indicate to the user the number for each square. This gets a little confusing though since the "O" looks like a "0". As you can see, I'm just checking all possible win conditions and printing out each square manually. Obviously this wouldn't work for something like Connect4 where you'd actually have to come up with an algorithm.



edit: weird, but the underscore isn't copying over correctly in the forum post. None of the print methods in printBoard() use empty spaces in my code its all underscores.
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic