Write a Tic-Tac-Toe game in C language.
Your project must contain at least one header file, two C source
files.
It is MANDATORY to save the file names as mentioned:
Save this file as tictactoe.c
#include <stdio.h> #include <conio.h> #include "tic.h" int start(); int main() { printf("****Tic Tac Toe - Dual Player Game****\n\n"); start(); return 0; }
Save this file as tic.h
#include <stdio.h> #include <conio.h> char box[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; int check(); void setBoard(); extern int start() { int pl = 1, i, ch; char mark; do { setBoard(); pl = (pl % 2) ? 1 : 2; printf("Player %d, enter your spot: ", pl); scanf("%d", &ch); mark = (pl == 1) ? 'X' : 'O'; if (ch == 1 && box[1] == '1') box[1] = mark; else if (ch == 2 && box[2] == '2') box[2] = mark; else if (ch == 3 && box[3] == '3') box[3] = mark; else if (ch == 4 && box[4] == '4') box[4] = mark; else if (ch == 5 && box[5] == '5') box[5] = mark; else if (ch == 6 && box[6] == '6') box[6] = mark; else if (ch == 7 && box[7] == '7') box[7] = mark; else if (ch == 8 && box[8] == '8') box[8] = mark; else if (ch == 9 && box[9] == '9') box[9] = mark; else { printf("Invalid move "); pl--; getch(); } i = check(); pl++; }while (i == - 1); setBoard(); if (i == 1) printf("==>\aPlayer %d wins ", --pl); else printf("==>\aThe Game ends in a Draw state. Better luck next time!"); getch(); return 0; } int check() { if (box[1] == box[2] && box[2] == box[3]) return 1; else if (box[4] == box[5] && box[5] == box[6]) return 1; else if (box[7] == box[8] && box[8] == box[9]) return 1; else if (box[1] == box[4] && box[4] == box[7]) return 1; else if (box[2] == box[5] && box[5] == box[8]) return 1; else if (box[3] == box[6] && box[6] == box[9]) return 1; else if (box[1] == box[5] && box[5] == box[9]) return 1; else if (box[3] == box[5] && box[5] == box[7]) return 1; else if (box[1] != '1' && box[2] != '2' && box[3] != '3' && box[4] != '4' && box[5] != '5' && box[6] != '6' && box[7] != '7' && box[8] != '8' && box[9] != '9') return 0; else return - 1; } void setBoard() { printf("\n\n\tGood Luck\n\n"); printf("Player 1 (X) - Player 2 (O)\n\n\n"); printf(" | | \n"); printf(" %c | %c | %c \n", box[1], box[2], box[3]); printf("_____|_____|_____\n"); printf(" | | \n"); printf(" %c | %c | %c \n", box[4], box[5], box[6]); printf("_____|_____|_____\n"); printf(" | | \n"); printf(" %c | %c | %c \n", box[7], box[8], box[9]); printf(" | | \n\n"); }
Write a Tic-Tac-Toe game in C language. Your project must contain at least one header file,...
Please write a tic tac toe game using c++ language and 1D arrays, thank you!
Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1) ...
(Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enumeration to represent the value in each cell of the array. The enumeration’s constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X...
(Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an available cell in a grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has achieved a win. Create...
1. Use Turtle Graphics to create a tic tac toe game in Python. Write a Python program that allows for one player vs computer to play tic tac toe game, without using turtle.turtle
Create a batch file tic tac toe game written in C code. This code should be able to run through an emulator.
Please make this into one class. JAVA Please: Tic Tac Toe class - Write a fifth game program that can play Tic Tac Toe. This game displays the lines of the Tic Tac Toe game and prompts the player to choose a move. The move is recorded on the screen and the computer picks his move from those that are left. The player then picks his next move. The program should allow only legal moves. The program should indicate when...
use python to do it implement the tic-tac-toe game. What to submit: 1. Your source code 2. Two runs, one user wins and one user loses.
PYTHON Exercise 2. Tic-Tac-Toe In this exercise we are going to create a Tic-Tac-Toe game. 1. Create the data structure – Nine slots that can each contain an X, an O, or a blank. – To represent the board with a dictionary, you can assign each slot a string-value key. – String values in the key-value pair to represent what’s in each slot on the board: ■ 'X' ■ 'O' ■ ‘ ‘ 2. Create a function to print the...
Tic tac toe game C++ programing using classes, objects, arays