C
C#2mo ago
Nate

Tic Tac Toe Game

help. creating a tic tac toe game if anyone has the time and knowledge please let me know. C# Desktop
18 Replies
SpReeD
SpReeD2mo ago
$help
MODiX
MODiX2mo ago
How to get the best help :catpog: Make a post in #help or one of the topic channels under Development. Avoid asking :catthinking: Can anybody help me? :catthinking: Has anyone used XYZ? :catthinking: Why doesn't my code work? C# is a big area! No one knows they can help unless you tell them about the small area you're trying to work in. Explain what you are doing, and potentially why for as much context as possible. Avoid screenshots where possible, share code directly in Discord. Type $code into chat to learn how to post code. See https://www.nohello.net and https://dontasktoask.com if you want common help chat room etiquette.
Nate
Nate2mo ago
there are 3 errors Type Form 1 is already defines a member called ComputerMove with the same parameter type. the call is ambigous between the following methods or properties line 125 Form1.ComputerMove() and Form1.ComputerMove() line 46 & 59
Angius
Angius2mo ago
Well, the first error is quite clear You have two methods with the same name And the same parameters There can only be one And the second stems from the first
Nate
Nate2mo ago
ohh the errors are fixed however my game doesn't work i run the game but when clicking on one of the 9 squares, nothing happens
Bailey
Bailey2mo ago
Hi, Just put some breakpoints under the buttons. Follow the code and see if the program does what is expected and if not try to solve it I have a tip about the code. You can also turn the buttons into an array. If you do that you don't have to make long if else constructions, you can do with a loop and 1 if. You can then put these in a method with a return value
Nate
Nate2mo ago
i didn't name the button click. after doing so it works, but the game doesn't keep track of score and the reset button doesn't work i think i have to create a method for the restart button, but im not sure how to make the game keep track of score
Bailey
Bailey2mo ago
In this case is the simplest method to create a global variable or multiple eg. int complayer =0 int realplaye = 0 and by every win you can update also to rset put them on 0 also put them between: public partial class Form1 : Form { public int comp = 0; public int user =0; public Form1()
Nate
Nate2mo ago
can you take a look at what i have so far?
Nate
Nate2mo ago
Nate
Nate2mo ago
3 major problems: the computer doesn't make a move sometimes after the player does. even though the player or computer has won, it doesn't show the messege Game over. player or computer has won. the score is not tracked
SpReeD
SpReeD2mo ago
the score is not tracked That's because your CheckWinner() is unused. the computer doesn't make a move sometimes after the player does. Couldn't replicate, might be a designer error - also you got a copy&paste error, two methods, one named blnClickFOUR & btnClickedFOUR, since they all does almost the same it's kinda hard to spot the error, but btnClickedFOUR checks on blnClickedFIVE in the if condition. even though the player or computer has won, it doesn't show the messege Game over. player or computer has won. Again, hard to spot. For somebody who didn't write that code and is only reading it, named variables/fields like blnClickedONE, which are bool, are a total mystery. I gotta read through ALL that code to get the idea behind it. Also, in a month or few, you'll be facing the same problem. Just name your properties, fields, variables and methods accordingly, for instance, if it's a bool, try naming it like a question IsButtonOneClicked or something. This way you tell the intention behind that field. --- As wrote before, you have nine almost identical methods, for each button one, try to make only one method. Controls, like Button, in WinForms can be identified by using the Tag property (only one method to identify a Control), make use of it so you only need one method. Imagine you wanna change something in the sequence, you gotta copy&paste it to every other method, this is 100% error-prone. TicTacToe is a good beginner UI project, once you get it working, you start to improve the code, the logic, the designer code, etc. etc. so you get hours and hours of fun. Here's another clue, the board is actually just a ternary-matrix of states 0, 1 & -1 or on other terms, cross, circle & unset. Try to figure out a way to represent a matrix in code, you're using arrays, try to add another dimension to an array so it becomes a 2D-Array, next, figure out how to restrict the content of one object of that 2D-Array to only have these three states, maybe try out something like enum. I guess that a lot of confusion comes from the current chaotic structure of the code, once you improve the structure you'll find the bugs.
Nate
Nate2mo ago
Nate
Nate2mo ago
here is my updated version shows no errors but the game is not functioning properly
SpReeD
SpReeD2mo ago
Well, you've mostly ignored my comments and made it even worse by adding a while true loop. As before, try to restructure the code in the first place, so you make it actually debuggable by stepping through.
Nate
Nate2mo ago
here is my final changes
Nate
Nate2mo ago
Nate
Nate2mo ago
still some problems but the basics are there i tried