Escolar Documentos
Profissional Documentos
Cultura Documentos
h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define TOP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
int checkwin();
void board();
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
&& square[4] != '4' && square[5] != '5' && square[6] != '6'
&& square[7] != '7' && square[8] != '8' && square[9] != '9')
return 0;
else
return -1;
}
/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/
void board()
{
clrscr();
cout << "\n\n\tTic Tac Toe\n\n";
cout << "Player 1 (X) - Player 2 (O)" << endl << endl;
cout << endl;
cout << " " << square[4] << " | " << square[5] << " | " << square[6] <<
endl;
cout << " " << square[7] << " | " << square[8] << " | " << square[9] <<
endl;
/* Take a one character guess and the secret word, and fill in the
unfinished guessword. Returns number of characters matched.
Also, returns zero if the character is already guessed. */
int letterFill (char guess, char secretword[], char guessword[])
{
int i;
int matches=0;
for (i = 0; secretword[i]!='\0'; i++)
{
// Did we already match this letter in a previous guess?
if (guess == guessword[i])
return 0;
// Is the guess in the secret word?
if (guess == secretword[i])
{
guessword[i] = guess;
matches++;
}
}
return matches;
}
score();
sz++;
switch(d)
{
case RIGHT : snkx[sz-1]+=2;
snky[sz-1]=snky[sz-2];
break;
case LEFT : snkx[sz-1]-=2;
snky[sz-1]=snky[sz-2];
break;
case TOP : snky[sz-1]-=1;
snkx[sz-1]=snkx[sz-2];
break;
case DOWN : snky[sz-1]+=1;
snkx[sz-1]=snkx[sz-2];
}
}
int sflag=0;
for(i=0;i<sz-1;i++)
if(snkx[sz-1]==snkx[i] && snky[sz-1]==snky[i])
{
sflag=1;
break;
}
if(snkx[0]<5 || snkx[0]>76 || snky[0]<3 || snky[0]>19)
sflag=1;
if(sflag)
{
textcolor(LIGHTRED);
for(i=1;i<sz;i++)
{
window(snkx[i],snky[i],snkx[i]+1,snky[i]+1);
cprintf("#");
}
status("Stopped",LIGHTRED);
score(0);
restart=1;
break;
}
}
char ch=getch();
switch(tolower(ch))
{
case 'x' : return;
case 'p' :
status("Paused");
getch();
break;
case 0 : {
char chh=getch();
switch(chh)
{
case 72 :{
if(d==LEFT || d== RIGHT)
d=TOP;
} break;
case 80 :{
if(d==LEFT || d== RIGHT)
d=DOWN;
} break;
case 75 :{
if(d==TOP || d==DOWN)
d=LEFT;
} break;
case 77 :{
if(d==TOP || d==DOWN)
d=RIGHT;
}
}
} break;
}
}
else if(x==2)
{
int main()
{
int player = 1,i,choice;
char mark;
do
{
board();
player=(player%2)?1:2; //This line of code will set player to 1 if
player originally was odd,
and to 2 if it was even.
cout << "Player " << player << ", enter a number: ";
cin >> choice;
mark=(player == 1) ? 'X' : 'O';
/*boolean expression ? a : b;
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')
square[3] = mark;
else if (choice == 4 && square[4] == '4')
square[4] = mark;
else if (choice == 5 && square[5] == '5')
square[5] = mark;
else if (choice == 6 && square[6] == '6')
square[6] = mark;
else if (choice == 7 && square[7] == '7')
square[7] = mark;
else if (choice == 8 && square[8] == '8')
square[8] = mark;
else if (choice == 9 && square[9] == '9')
square[9] = mark;
else
{
cout<<"Invalid move ";
player--;
cin.ignore();
cin.get();
}
i=checkwin();
player++;
}while(i==-1);
board();
if(i==1)
cin.ignore();
cin.get();
return 0;
}
}
else if(x==3)
{
int main ()
{ clrscr();
cout<<"HINT:The countries are india, pakistan, nepal, indonesia, ethopia,
phillipines,malaysia,australia,iran, oman" ;
char unknown [MAXLENGTH];
char letter;
int num_of_wrong_guesses=0;
char word[MAXLENGTH];
char words[][MAXLENGTH] =
{
"india",
"pakistan",
"nepal",
"malaysia",
"philippines",
"australia",
"iran",
"ethiopia",
"oman",
"indonesia"
};
/* Take a one character guess and the secret word, and fill in the
unfinished guessword. Returns number of characters matched.
Also, returns zero if the character is already guessed. */
else
cout<<"incorrect choice";
getch();
}