I am making a tic-tac-toe game in C#. I have a string variable for each square. I want to make it so the user inputs the square name i.e. (topMiddle). Then I declare the input playerInput. I want to use str.Replace(' ', 'x'); but instead of str I would use the name of the box i.e.(topMiddle). How would I retrieve that variable using the console input?
Here is my code so far:
using System; namespace TicTac_toe { public class CreateVariables { public static void Main (string[] args) { string topRight = " "; string topMiddle = " "; string topLeft = " "; string middleLeft = " "; string center = " "; string middleRight = " "; string bottomLeft = " "; string bottomMiddle = " "; string bottomRight = " "; string line = "|"; string dash = "_ _ _"; string xInput; string oInput; bool player1; System.Console.WriteLine (topLeft + line + topMiddle + line + topRight + "\n" + dash + "\n" + "\n" + middleLeft + line + center + line + middleRight + "\n" + dash + "\n" + "\n" + bottomLeft + line + bottomMiddle + line + bottomRight); System.Console.WriteLine ("Player 1, it is your turn. WHat box will you mark?"); xInput = System.Console.ReadLine (); topRight = xInput.Replace (' ', 'X'); System.Console.Clear (); System.Console.WriteLine (topLeft + line + topMiddle + line + topRight + "\n" + dash + "\n" + "\n" + middleLeft + line + center + line + middleRight + "\n" + dash + "\n" + "\n" + bottomLeft + line + bottomMiddle + line + bottomRight); Sorry if my code is messy and my problem is a simple fix. This is my fourth-day using c# so I still have a lot to learn.