Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Okay so here is the deal The follwing progrman needs to be done in C# and in visual studio and it is due by May

Okay so here is the deal The follwing progrman needs to be done in C# and in visual studio and it is due by May 12th. Game Logic There are three possible outcomes to the game. 1. The player wins. a. When the player wins, the computer should not be able to play. Whether the computer can play or not is tracked by the GoodMove Boolean variable. This variable tracks the state of the computers ability to play. b. All labels should be disabled so the player cant play. c. The only option is to click New Game. 2. The computer wins. a. All labels should be disabled so the player cant play. b. The computer should not be able to play. c. The only option is to click New Game. 3. There is a tie. a. A tie is tracked by the PlayerClicks variable. After the player has clicked 5xs without winning, the computer shouldnt be able to play, and all labels should be disabled so the player cant play. b. The only option is to click New Game. 4. New Game a. Allow the computer to play. Set the GoodMove variable to false. b. Allow the user to play, clear the labels and the gameBoard. Requirements Create a global variable named PlayerClicks to keep track of how many times the Player has clicked. The game is a tie if the Player clicks 5xs without winning. Create a CheckWinner() method that checks first to see if the player won, then checks to see if the computer won. o Test the gameBoard array for each possible combination of winning: 012, 345, 678, 036, 147, 258, 048, 246 for X, then O. o Determine the winner of X or O. o Display the result of the game. o If the winner is X (player), use the global goodMove Boolean variable to determine that the computer cant keep playing after the player wins. goodMove = true; stops computer play. o Use the global PlayerClicks variable to track how many times the player plays until a tie. Tic Tac Toe 3 Page 2 of 2 Revised: 5/4/2017 o Disable all the labels when either player wins or there is a tie. o Display the game results. o Call the CheckWinner() method at the beginning and the end of the GameBoard_Click method. This tests first if the player won, then at the end it tests to see if the computer won. The new game button resets the PlayerClicks variable. Add a MenuStrip. Add a File menu, then a New Game, and Exit command. Add a Help menu with an About command. The About command can call a form that your built, or a messagedialogbox with an OK button.

Here is what i have so far:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace Tic_Tac_Toe { public partial class ticticatoeFrm : Form { // Global level varaibles. int Rounds; // To hold the number of rounds played.

public ticticatoeFrm() { InitializeComponent(); } // Form level constants. const int SIZE = 9; // The size of the array const int MIN = 0; // Set the minimum range of the random numbers, inclusive. const int MAX = 9; // Set the maximum range of ther random numbers, exclusive.

// Form level variables. char[] gameboard = new char[SIZE]; // An array to store the xs and os Label[] _labels = new Label[SIZE]; // some label objects to access the labels. Random rand = new Random(); // A new random number generator object. Label lblLabel; // To track which lable the player clicks.

// Create a method to check who wins and loses.

private void Newgamebtn_Click(object sender, EventArgs e) { for (int x = 0; x

} // Create a method to display the results to the labels and have them set to disable if used. private void displayGameLabels() { // Display the labels and set labels to displayed if they have been played. // Go through the entire array. for (int x = 0; x

private void exitbtn_Click(object sender, EventArgs e) { // Close the form this.Close(); }

private void ticticatoeFrm_Load(object sender, EventArgs e) { _labels[0] = this.label1; _labels[1] = this.label2; _labels[2] = this.label3; _labels[3] = this.label4; _labels[4] = this.label5; _labels[5] = this.label6; _labels[6] = this.label7; _labels[7] = this.label8; _labels[8] = this.label9; }

private void GameBoard_Click(object sender, EventArgs e) { // If the user has clicked any label. string labelName; // Store the label name. int labelNumber; // Store the label number. int randomLabel; // Random number for computer choice. lblLabel = (Label)sender; // use the label object variable to hold the label that was just clicked lblLabel.Text = "X"; // Mark the players label choice. labelName = lblLabel.Name; // Pull the name of the label that was clicked. labelNumber = int.Parse(labelName.Substring(5, 1)); // Pull the number out of the clicked lablel. gameboard[labelNumber - 1] = 'X'; // Put an x in the label that was clicked by the player. lblLabel.Enabled = false; // Display the label that was clicked by the player. Boolean goodMove = false; // Set a flag for played lable.

// Computer moves. while (goodMove == false) { randomLabel = rand.Next(MIN, MAX); // PIck a random label for the computers move. // Check to see if the player has already chosen that label if (gameboard[randomLabel].ToString() == "X" || gameboard[randomLabel].ToString() == "O") { goodMove = false; // Already been played, try another label } // COmputer plays label as it has not been used. else { goodMove = true; // The lable has not been played, mark as good play. gameboard[randomLabel] = 'O'; // Set O for the computer move. } } displayGameLabels(); } } }

Also here is the form i have so far:image text in transcribed

Also the code I have so far needs to stay the same if possible. Also the Tiles are actually labels, and it needs to stay that way. So thanks for your help:)

Tic tac toe New Game Exit X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions