Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:31:42+00:00 2026-05-26T02:31:42+00:00

For my c++ homework assignment, I have to write a Tic-Tac-Toe Win32 console application.

  • 0

For my c++ homework assignment, I have to write a Tic-Tac-Toe Win32 console application.

I’ve created a grid on the screen using a coordinate system and I use _getch() and SetConsoleCursorPosition(...) to move the cursor around when the user presses the arrow keys and to draw an X or and O when the users presses one of those keys.

Key part of my question

The grid coordinates are are in the format (x,y) and 1,1 represents the top-left and 5,5 represents the bottom-right. Every arrow key press moves the cursor +/- 2. For example, if the cursor is at 1,1 and the user presses the up arrow, the cursor is moved to 1,5, if the up arrow is pressed again the cursor moves to 1,3, etc.

The movement is handled with this arithmetic expression:

switch ( keyPress ) {
 case UP    :
    position.Y = (12 + position.Y - 2) % 6;
    SetConsoleCursorPosition(screen, position);
    break;
 case DOWN  :
    position.Y = (12 + position.Y + 2) % 6;
    SetConsoleCursorPosition(screen, position);
    break;
 case LEFT  :
    position.X = (12 + position.X - 2) % 6;
    SetConsoleCursorPosition(screen, position);
    break;
 case RIGHT :
    position.X = (12 + position.X + 2) % 6;
    SetConsoleCursorPosition(screen, position);
    break;
 }

Question

I am not allowed to use magic numbers for the assignment and therefore, in the 12, 2, and 6 need to be replaced with variable names that make sense. What would be appropriate names for those values?

UPDATE

Based on the comments, here is how the game board is displayed on the screen:
The numbers on the x and y axis are the cursor positions where an X or and O is drawn.

 0123456
0╔═╤═╤═╗
1║X│ │ ║
2╟─┼─┼─╢
3║ │O│ ║
4╟─┼─┼─╢
5║ │ │X║
6╚═╧═╧═╝
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:31:43+00:00Added an answer on May 26, 2026 at 2:31 am

    it’s all relative to your initial settings they could look like:

    const int CELLWIDTH   = 1;  // how big one cell is (space in it)
    const int BORDERWIDTH = 1;  // width of the border
    const int GAMESIZE    = 5;  // size of game field like 5x5
    
    const int CELLSIZE    = CELLWIDTH + BORDERWIDTH;
    const int MAXOFFSET   = GAMESIZE*CELLSIZE + BORDERWIDTH;
    
    
    switch ( keyPress ) {
     case UP    :
        position.Y = (MAXOFFSET+1 + position.Y - CELLSIZE + GAMESIZE + 1) % (GAMESIZE+1);
        SetConsoleCursorPosition(screen, position);
        break;
     case DOWN  :
        position.Y = (MAXOFFSET+1 + position.Y + CELLSIZE + GAMESIZE+1) % (GAMESIZE+1);
        SetConsoleCursorPosition(screen, position);
        break;
     case LEFT  :
        position.X = (MAXOFFSET+1 + position.X - CELLSIZE - (GAMESIZE+1)) % (GAMESIZE+1);
        SetConsoleCursorPosition(screen, position);
        break;
     case RIGHT :
        position.X = (MAXOFFSET+1 + position.X + CELLSIZE - (GAMESIZE+1)) % (GAMESIZE+1);
        SetConsoleCursorPosition(screen, position);
        break;
     }
    

    Please make sure to use even values 😉 it gets complicated if the cell is wider and if you want to jump into the middle of the cell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of a homework assignment, I have to write a C program in
For a homework assignment I have to write a basic shell including redirection. The
This is part of a homework assignment. What we have to do is write
I have a homework assignment to write a multi-threaded sudoku solver, which finds all
For a homework assignment, I have to write a MySQL query to calculate the
(this is indirectly a part of a much larger homework assignment) I have something
I have a homework assignment where I need to take input from a file
My kiddo had a homework assignment to write Blackjack in Java. I helped him
I have three questions regarding a homework assignment for C++. The goal was to
As part of a homework assignment, I have to program a simple chess game

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.