Free Essay

Tic Tac Toe

In:

Submitted By hudgins84
Words 687
Pages 3
Charles Hudgins
Jaun Hernandez
PT1420
4/29/2014
Let's Start:
Create a New project and select windows application. Give it name and then press enter.(All of us know this step).
After that you see a blank form like that:

Now add 9 buttons on your form using tools.

Select button then delete the text from properties (i.e. button1, button2).Actually we want no text on buttons.

Now, Put a label on your form set back color according to your wish (here I choose sky-blue color from properties), set text align to middle center and set text to "Turn”. Actually we are creating a box for showing the player's Turn.

Add Another Label below above label. Remove text from it, leave it blank. Give it name="display turn”. Now our Application looks something like that.

Now doing the same above method, I have created a Scorecard for player1 and player2.I give name playerscore1 and playerscore2 for the labels as shown in figure.

I am creating this game for 2 person so, I supposed here Player1 symbol="X" and Player2 Symbol="O".Now I want when player1 click it gives "X" symbol on button. After his turn when Player2 click on button then it show "O" on another button. Double click on button1 and add the code given below.

Collapse | Copy Code void Button1Click(object sender, EventArgs e) { if(click1==0) { if(turn%2!=0) { button1.Text="X"; } else { button1.Text="O"; } turn++; click1++; } else { button1.Text=button1.Text; } display(); checkit(); } I have created int turn=1(help us in finding turn),int click1=0(for checking if button is pressed more than one times).

When Player click on button, it checks if condition i.e. click1=0 is true then it checks another condition for finding player turn.Starting value of turn is equal to1, so it checks (1%2!=0) that is True.So, It display "X" on the Button and increase 1 in int turn(turn++) and click1(click++).If condition become False it display "O" on button.If Player again presses the key then condition become false(because click1 become equal to 1) and text on button remain same.

After that I am Calling display() and checkit() method.

display() use for displaying the Player's turn and checkit() checks for winner of game.

Same coding is done for the other buttons instead of button1 write button2 and for click1 write click2;

display() method:

Collapse | Copy Code public void display() { if(turn%2!=0) { displayturn.Text="Player 1"; } else { displayturn.Text="Player 2"; } } It is use for showing the Turn of Player.For example:If turn=2 it shows "Player2" turn in our application.

checkit() method:

Collapse | Copy Code public void checkit()
{
if(button1.Text!="" && button2.Text!="" && button3.Text!="") { if(button1.Text==button2.Text && button1.Text==button3.Text) { button1.BackColor=Color.Green; button1.ForeColor=Color.White; button2.BackColor=Color.Green; button2.ForeColor=Color.White; button3.BackColor=Color.Green; button3.ForeColor=Color.White; if(button1.Text=="X") { MessageBox.Show("Player 1 Wins!"); player1++; player1score.Text=player1.ToString(); } else { MessageBox.Show("Player 2 Wins!"); player2++; player2score.Text=player2.ToString(); }
` cleargame(); } }
}
Firstly checkit() ckecks that button must contain text.After that if It found that Three Buttons have same text than changes the Back and ForeColor. After That it checks the Button Text.If text =="X" then give message that "Player1 Wins!" or If text=="O" then it gives message that ""player 2 Wins!.add +1 to player1 or player2(these are int variables) and display them in labels(player1score,player2score).

cleargame() method clears the data(i.e. BackColor,ForeColor,Buttons text,displayturn,variables value back to starting value)but does not clear the player1score and player2score.

Create two buttons one for reset and other is Play Again(Used in case of Tie Up).In Play Again Button(use if Tie Up Occurs) I pass the cleargame() method.

Game Preview: http://www.codeproject.com/KB/cs/647947/tictactoebyanoop.gif License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Similar Documents

Free Essay

Tic Tac Toe

...EBizPort: Collecting and Analyzing Business Intelligence Information Byron Marshall, Daniel McDonald, Hsinchun Chen, and Wingyan Chung Artificial Intelligence Lab, Management Information Systems Department, University of Arizona, Tucson, AZ 85721. E-mail: {byronm, dmm, hchen, wchung}@eller.arizona.edu To make good decisions, businesses try to gather good intelligence information. Yet managing and processing a large amount of unstructured information and data stand in the way of greater business knowledge. An effective business intelligence tool must be able to access quality information from a variety of sources in a variety of forms, and it must support people as they search for and analyze that information. The EBizPort system was designed to address information needs for the business/IT community. EBizPort’s collection-building process is designed to acquire credible, timely, and relevant information. The user interface provides access to collected and metasearched resources using innovative tools for summarization, categorization, and visualization. The effectiveness, efficiency, usability, and information quality of the EBizPort system were measured. EBizPort significantly outperformed Brint, a business search portal, in search effectiveness, information quality, user satisfaction, and usability. Users particularly liked EBizPort’s clean and user-friendly interface. Results from our evaluation study suggest that the visualization function added value to the search and...

Words: 14368 - Pages: 58

Premium Essay

Tic Tac Toe Programming

...Introduction Tic-Tac-Toe is a popular simple game for two players all over the world. Traditionally one person plays for “X” while another plays for “O”. The game is played on the square board of 3x3 or even more size. The aim of this game for player is to win by filling with “X” or “O” any row, column or diagonal of the main game board. The game sets players thinking because players should reflect a little bit on strategy and predict some moves of the opponent. So it teaches people to make decisions quickly. MATLAB is computer software for technical computing from the MathWorks. Used for a wide variety of scientific and engineering calculations. The functions of the MATLAB are solving equations, plotting 2D, 3D graphs, calculating statistics, etc. The aim of the report is to describe how Tic-Tac-Toe game simulation was made with the help of MATLAB. The report describes how program reads the code and computer strategy for winning/not losing in the game. Theory. The aim the individual coursework was to program 4x4 Tic-Tac-Toe game for player and computer using MATLAB with condition that computer should always win or just not loose. Programming the game basic loops such as “while”, “for”, “if” were used, where “while” means to repeat smth until some particular conditions are holding, “for” means to do smth for particular conditions, and “if” means to do smth if some conditions are true. There also were used “sum” function which helps to count “X”-s or “O”-s in rows, columns...

Words: 3911 - Pages: 16

Premium Essay

Tic Tac Toe Java Code

...OBJECT ORIENTED PROGRAMMING TIC TAC TOE Contents: Page 1. Specifications 3 2. Background 4 3. UML Design i. Use Case Diagram 5 ii. Class Diagram 6 4. Implementation i. How code is working? 7 ii. Conclusion 9 iii. Future Work 10 5. Appendix 10 6. References 15 7. Bibliography 15 1. Specifications: A requirements specification for a software system - is a complete description of the behavior of a system to be developed. It includes a set of use cases that describe all the interactions the users will have with the software. Use cases are also known as functional...

Words: 1071 - Pages: 5

Free Essay

The Ultimate Puzzle

...How to Win and More Specifically How to Not Lose at Tic Tac Toe In order to successfully complete the puzzle you may not enter the outer spaces. The outer left, outer right, center top, center bottom will all cause you to immediately lose. Your opponent will immediately see what is going on and place his marker in the center center position. Once that occurs, you will be forced to choose one of the corners, which will place you in a position to get a tic, tac, toe. However, in blocking your tic, tac, toe, your opponent will select the other corner, which means that your next move must be to block him from getting the tic, tac toe. Upon seeing you block him, your opponent will then chose the alternate corner from where his current center piece and side piece are located. In doing this, your opponent is forcing you to choose to block him in either the center center, or the alternate corner. This puts you in a situation that is impossible to win. You may try to block him in one section however you will not be able to prevent him from winning the game of tic, tac, toe, since he will place his piece in the remaining slot and defeat you. It is critical at the beginning of the game to never select these four positions as it is impossible to defend if your opponent knows what he is doing. Best of luck as you try to conquer this ancient...

Words: 256 - Pages: 2

Free Essay

Tic Tac Oe

...Computer Programming Computer Programming TIC TAC TOE PROJECT TIC TAC TOE PROJECT Flor Garcia FINAL EXAM Flor Garcia FINAL EXAM 2015 2015 DEFINE THE PROBLEM: Write a Tic Tac Toe program that inputs the player’s names and then asks if you want to play again. It displays a score board at the end of the game. OUTLINE THE SOLUTION: INPUT | PROCESSING | OUTPUT | Name of Player 1 | Names of Both players is inputted | Score board of who won, lost or any draws | Name of Player 2 | Player 1 makes the first move by choosing a number in the box then [X] will replace the chosen number | | Numbers on each box | Player 2 makes the second move by choosing a number in the box then [O] will replace the chosen number | | | If either of the players win, they receive a point in the score board | | | If it is a draw, the score board will display it | | DEVELOP AN ALGORITHM: 1. Insert name of player 1 [X] 2. Insert name of player 2 [O] 3. Players choose the number of the box they want to input their letter in. 4. Once then choose the number they inputted their designated letter will replaced the number in the box 5. These steps are repeated as it is each player’s turn 6. The game will end until someone wins or it becomes a draw 7. The Score board will be displayed at the end TEST THE ALGORITHM: 1. Name of Player 1: Flor 2. Name of Player 2: Karla 3. Flor chooses number 3 and is replaced by [X] 4. Karla chooses...

Words: 1048 - Pages: 5

Premium Essay

A Beautiful Mind

...Beautiful Mind A Beautiful Mind is a book written by Sylvia Nasar and is A Touchstone Book published by Simon and Schuster. A Beautiful Mind won the 1998 National Book Critics Award for Biography, a contract for a movie deal, and a nomination for The Pulitzer Prize for Biography. This book is based on a man by the name of John Nash who is a brilliant mathematician and also a paranoid schizophrenic. Even though Nash struggled with paranoid schizophrenia he was still able to revolutionize a concept called game theory. This work that he did with game theory greatly improved what was already established as well as created the Nash equilibrium. Game theory is the mathematical study of strategies used to win games. It began with games like tic-tac-toe and chess since they are easy to analyze because they are known as games of complete information. Complete information is when your opponent’s positions are in clear site. Game theory then went on to analyze card games where player’s cards aren’t seen, which is known as incomplete information. In card games there are elements such as bluffing that can become a variable in the analysis. Mathematicians continued to analyze more critical games such as economics, biology, philosophy, and even which girl to go after. This is around the time that John Nash developed a principle for mutual consistency of player’s strategies which is known as the Nash equilibrium. The Nash equilibrium can be applied to a wider variety of games than the original...

Words: 482 - Pages: 2

Premium Essay

Wajihaider

...|[pic] |Syed Muhammad Waji Haider | |Born 1994 | | | |Address: House no.7, Bastami road, samnabad lahore | | |Contact: 0307-0408091 | | |Email: waji58@gmail.com | | |Site: waji58.wordpress.com | | |Date of birth: February 12, 1994 | | | | |Personal Profile |Reliable and dependable in meeting objectives | | |Hard working, possess strong planning, organizing and monitoring abilities ...

Words: 513 - Pages: 3

Premium Essay

Personal Narrative: Macaroni Grill

...eight, my family and I went to the Macaroni Grill for my cousin’s birthday. This group included my uncle Marvin. Marvin personifies the ‘goofy, old uncle that gives his nieces and nephews enough candy to get cavities’ stereotype. Whenever we ate out with him, he would always sit at the border of the adult’s side of the table and the kid’s. He would make our stomachs ache with his jokes and our brains throb with his riddles. Overall, he kept us entertained through the usually boring meals. The lunch at Macaroni Grill started off like any other: Marvin sat near us kids and we proceeded to find ways to entertain ourselves as the meal dragged on. My younger brother, Tyson, challenged me to a very serious game of tic-tac-toe which would finally decide who had the title of Tic-Tac-Toe World Champion. This game would go on to help define my life. As I surpass Tyson in every way, it soon became clear to him what the outcome of the game would be. Not ready to face defeat he dashed his red crayon across the paper in an attempt to ruin our game and thus not lose his chance at the crown. I could not take such treachery. I quickly shot my arm across the table to put a stop to the double-crossing, but in my effort I accidently displaced a glass of water....

Words: 653 - Pages: 3

Premium Essay

Concept Map

...ACID-BASE DISORDERS MADE SO EASY EVEN A CAVEMAN CAN DO IT Lorraine R Franzi, MS/HSM, RD, LDN, CNSD Nutrition Support Specialist University of Pittsburgh Medical Center Pittsburgh, PA I. LEARNING OBJECTIVES The clinician after participating in the roundtable will be able to: 1) Indicate whether the pH level indicates acidosis or alkalosis. 2) State whether the cause of the pH imbalance is respiratory or metabolic. 3) Identify if there is any compensation for the acid-base imbalance. II. INTRODUCTION Acid-Base balance is an intricate concept which requires an intimate and detailed knowledge of the body’s metabolic pathways used to eliminate the H+ ion. Clinicians may find it daunting to understand when first introduced to the subject. This roundtable session will demonstrate how to analyze blood gas levels in a very elementary manner so as to diagnose any acid-base disorder in a matter of minutes. The body is in a constant state of flux delicately stabilizing the pH so as to maintain its normalcy. In order to prevent untoward effects of alkalosis or acidosis the body has three major buffering systems that it uses to adjust the pH. They are: 1) Plasma protein (Prot-) 2) Plasma hemoglobin (Hb-) 3) Bicarbonate (HCO3-) The Bicarbonate-Carbonic acid system is the most dominate buffering system and controls the majority of the hydrogen ion (H+) equilibrium. Maintaining homeostasis when these acid-base shifts occur is vital to survival. Metabolic and respiratory...

Words: 1735 - Pages: 7

Free Essay

Activites for Small Children

...Resource II - Science| Activity: What's in the air experiment |Age Group: 3 year olds | Goal/Objective : Children learn the dangers of fire | Materials Needed: · plate · candle, & matches · play dough · jar & colored | Process and Teaching Strategies · Use playdough to stand candle up in the middle of the plate, then pour colored water around the candle. Teacher then lights the candle and talks to children about the danger of matches and fire. Put the jar over the candle and watch the flames disappear| How is this activity developmentally appropriate? It teaches children they should only handle with an adult | Resource II - Language and Literacy | Activity: Learning to write your name |Age Group: 3 year olds | Goal/Objective : help child write his/ her name | Materials Needed: · chalk · sidewalk· | Process and Teaching Strategies · Let the child see his/her name. Make marks everywhere. Provide a vertical writing surface. Give fingers a workout. Hunt for letters| How is this activity developmentally appropriate? It gives the child a chance to write and see their name spelled out | Resource II - Creative Arts | Activity: Foot Tracing|Age Group: 3 year olds | Goal/Objective : Team work | Materials Needed: · drawing paper· crayons· markers | Process and Teaching Strategies · Give each child a partner and take turns tracing each others foot | How is this activity developmentally appropriate? Gives the opportunity...

Words: 613 - Pages: 3

Free Essay

Video Games

...A video game is an electronic game that involves human interaction with a user interface to generate visual feedback on a video device. The word video in video game traditionally referred to a raster display device, but it now implies any type of display device that can produce two- or three-dimensional images. The electronic systems used to play video games are known as platforms; examples of these are personal computers and video game consoles. These platforms range from large mainframe computers to small handheld devices. Specialized video games such as arcade games, while previously common, have gradually declined in use. Video games have gone on to become an art form and industry. The input device primarily used to manipulate video games is called a game controller, and varies across platforms. For example, a controller might consist of only a button and a joystick, while another may feature a dozen buttons and one or more joysticks. Early personal computer games often needed a keyboard for gameplay, or more commonly, required the user to buy a separate joystick with at least one button. Many modern computer games allow or require the player to use a keyboard and a mouse simultaneously. A few of the most common game controllers are gamepads, mouses, keyboards, and joysticks. In recent years, additional methods of input have emerged such as camera-based player observation for video game consoles and touch-sensitive screens on mobile devices. Video games typically use...

Words: 854 - Pages: 4

Free Essay

Freemasons Cipher

...Brice Matthews Dr. Linda Harned Communication 1201-240 28 Aug 2015 Learning the Freemason's Cipher Don't be threatened by the name, this is actually one of the most simple ways of writing a secret message, or cipher, that there is. Before we get into the specifics of the certain cipher I am going to be teaching you today, the first thing you need to know is the difference between the terms code and cryptography. Code is the broader term, which most of us are familiar with, simply meaning “a system of rules to convert information”. One of the earliest examples of code being the invention of language itself, because it allowed a form of communication to convert information. Today though, we are mostly going to be focused on cryptography. All cryptography is code but not all code is cryptography; codes can be a code of law, a code of conduct, or a dress code. It is simply a way of giving information in a way that is comprehensible. Cryptography is the use of ciphers and code to protect a message or secret. A cipher is a secret/disguised way of writing code. In order to effectively decode (a term we are all familiar with) a cipher, you need to possess the knowledge of the way it was originally ciphered. Ciphers can be kept solely in your mind and then spread through word of mouth, or written on a piece of paper or even implemented into mechanical device, which is then required to break the cipher, unless you can remember that information and store it. All ciphers can technically...

Words: 1006 - Pages: 5

Free Essay

Asdasdasd

...Step 1: Materials Tools * Arduino * Processing * Wire cutters * Soldering iron * Box cutter Materials * (3) 270k resistors * (3) 10k resistors * Solder * Wire * Aluminum foil * Cardboard Optional: * Tape (e.g.: scotch) * Shielded wire (e.g.: coaxial cable, ~3') * (3) alligator clips * 3-pin header * Zip-tie * Shrink wrap tubing or hot glue Step 2: Make the Plates This sensor will work using simple RC circuits, with each circuit sensing distance in one dimension. I found that the easiest way to arrange three capacitive plates for this purpose is in the corner of a cube. I cut the corner of a cardboard box into an 8.5" cube, and then cut some aluminum foil to fit as slightly smaller squares. Tape on the corners keeps them in place. Don't tape down the entire perimeter, we'll need it later for attaching the alligator clips. Step 3: Make the Connectors To connect the Arduino to the plates we need some shielded wire. If the wire isn't shielded, the wires themselves act more obviously as part of the capacitor. Also, I've found that alligator clips make it really easy to connect things to aluminum -- but there are probably plenty of other ways, too. * Cut three equal lengths of shielded cable. I chose about 12". The shorter the better. Coaxial cable works, but the lighter/more flexible the better. * Strip the last half inch or so to reveal the shielding, and the last quarter inch to reveal...

Words: 1116 - Pages: 5

Free Essay

Prg 410 Week 3 Assignment

...PRG 410 WEEK 3 ASSIGNMENT http://www.coursehomework.com/product/prg-410-week-3-assignment/ Contact us at:  +1 315-750-4434  help@coursehomework.com PRG 410 WEEK 3 ASSIGNMENT C++ Programming I PRG-410 Assignment#3 Problem 1: [marks 20] Write a program that implements simple game scenario. Game has two-player or a three-player MODE. For each MODE you have to choose among four HEROs. These are ALPHA, BRAVO, CHALIE and DELTA. You have to design and implement proper notation for each MODE and implement them accordingly using appropriate conditions e.g., First player is selecting ALPHA then Second Player can’t select ALPHA. Against each MODE ask five values for each player if: • Ask input range is between (1-100) player will win with 10 points for one value. • Ask input range is between (101-200) player will win with 20 points for one value. • Ask input range is between (201-500) player will win with 50 points for one value. Add all five values for HERO/HEROs and printout the winner of the game. Problem 2: Rock, Paper, Scissors Game [marks 20] Write a program that lets the user play the game of Rock, Paper, and Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the...

Words: 933 - Pages: 4

Free Essay

Bank of Activities

...Banks activities No | Activity | Preparation | Rules | Players | Material | Time | 1 | I Spy | Write many words on a blank piece of paper in random order and positioned at all angles. Make copies of the page for each of your students to have one. To play, you read a word to your class. They race to find that word on the page. The first one to find it reads it out loud and then circles it or crosses it out. That person scores one point. Then wait until everyone in class has found the word. Read a second word, and students then search for that one on the page. The first to find it scores a point. As you call out more words, students will be reading many of the words on the page.. Play until someone reaches a certain number of points or until you have called out all the words you want your students to read. | Everyone has a paper with words written on. I will read every single word and you guys have to find that word. The first one to find it has to read it out loud and will score 1 point. Play till the last word and the one with most points wins. | 6-7 | Words paper | 20 mins | 2 | Snake and Ladder | Draw a grid 5x5 (depends on how long you want to play). Each square will have a question/ puzzle/ command/ picture. Depending on the question, who lands on the square will have to answer or do that. Otherwise, some squares will have snakes, which force to go back, and ladders which force them to go up. Play until one team reachs the final square. | We will divide into 2 teams...

Words: 1739 - Pages: 7