Click here to Skip to main content
15,903,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Java Applets (jar) in MFC resources application Pin
Crercio O. Silva20-Oct-03 14:18
Crercio O. Silva20-Oct-03 14:18 
GeneralRe: Java Applets (jar) in MFC resources application Pin
antlers20-Oct-03 12:03
antlers20-Oct-03 12:03 
GeneralRe: Java Applets (jar) in MFC resources application Pin
Crercio O. Silva20-Oct-03 14:25
Crercio O. Silva20-Oct-03 14:25 
GeneralRe: Java Applets (jar) in MFC resources application Pin
antlers21-Oct-03 8:57
antlers21-Oct-03 8:57 
Generalprecise time measuring Pin
tguzella19-Oct-03 6:55
tguzella19-Oct-03 6:55 
GeneralRe: precise time measuring Pin
David Crow20-Oct-03 2:50
David Crow20-Oct-03 2:50 
GeneralRe: precise time measuring Pin
PremL20-Oct-03 5:49
PremL20-Oct-03 5:49 
GeneralNeed opinion + help, can anyone just comment anything, suggestion, websites would be good, I would be forever Thankful Pin
Snyp19-Oct-03 6:37
Snyp19-Oct-03 6:37 
#include <iostream>
#include <fstream>
using namespace std;

char matrix [3][3]; //Tic Tac Toe Matrix

char check();
void init_matrix();
void get_player_move();
void get_computer_move();
void disp_matrix();

int main()
{
char done = ' ';

init_matrix();

ofstream examplefile("example.txt");
do
{
disp_matrix();
get_player_move();
done = check(); //See if any winner
if(done != ' ') break; //Winner!!!
get_computer_move();
done = check(); //See if any winner again
if(done != ' ') break;
} while(done == ' ');

if(done == 'X')
{
if (examplefile.is_open())
{
examplefile << "Winner: X\n";
examplefile.close();
}
cout << "You won!!!\n";
}
if(done == 'O')
{
if (examplefile.is_open())
{
examplefile << "Winner: O\n";
examplefile.close();
}
cout << "I won!!!\n";
}
else
{
if (examplefile.is_open())
{
examplefile << "Winner: Draw\n";
examplefile.close();
}
cout << "Draw!!!\n";
}

disp_matrix(); //Display final matrix

return 0;
}

//Initialize the matrix
void init_matrix()
{
int i, j;

for(i=0; i<3; i++)
for(j=0; j<3; j++)
matrix[i][j] = ' ';
}

//Get the player's move
void get_player_move()
{
int x, y;

cout << "Enter X,Y coordinates for your move: ";
cin >> x;
cin >> y;

x--; y--;

if(matrix[x][y]!= ' ')
{
cout << "Invalid move, try again.\n";
get_player_move();
}
else matrix[x][y] = 'X';
}

//Get a move from the computer
void get_computer_move()
{
/*
int i, j;



if(matrix[i][j] !=' ')

if(i*j==9)
{
cout << "draw\n";
system("pause");
}
else
matrix[i][j] = 'O';
*/
}

//Display the matrix
void disp_matrix()
{
int t;

for(t=0; t<3; t++) {
cout << matrix[t][0] << " | " << matrix[t][1] << " | " << matrix[t][2];
if(t != 2)
cout << "\n---|---|---\n";
}
cout << "\n";
}

//See if any winner
char check()
{
// New checking system
int i;

for(i=0; i<3; i++) // Check rows
if(matrix[i][0]==matrix[i][1] && matrix[i][0]==matrix[i][2])
{
return matrix[i][0];
}

for(i=0; i<3; i++) // Check columns
if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i])
{
return matrix[0][i];
}

//Test diagonals for winner
// Left to right
if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
return matrix[0][0];
}

// Right to left
if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])
{
return matrix[0][2];
}

/*
// Old checking system
// Check rows
if(matrix[0][0] == matrix[0][1] && matrix[0][0] == matrix[0][2])
{
return matrix[0][0];
}
if(matrix[1][0] == matrix[1][1] && matrix[1][0] == matrix[1][2])
{
return matrix[1][0];
}
if(matrix[2][0] == matrix[2][1] && matrix[2][0] == matrix[2][2])
{
return matrix[2][0];
}
// Check columns
if(matrix[0][0] == matrix[1][0] && matrix[0][0] == matrix[2][0])
{
return matrix[0][0];
}
if(matrix[0][1] == matrix[1][1] && matrix[0][1] == matrix[2][1])
{
return matrix[0][1];
}
if(matrix[0][2] == matrix[1][2] && matrix[0][2] == matrix[2][2])
{
return matrix[0][2];
}
// Check diagonal (left to right)
if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
return matrix[0][0];
}
// Check diagonal (right to left)
if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0])
{
return matrix[0][2];
}
*/

return ' ';
}

<marquee>Universal Project... Soon to be a .net
GeneralMRU problem Pin
YaronNir19-Oct-03 6:26
YaronNir19-Oct-03 6:26 
GeneralInteresting Interview with Bjarne Stroustrup Pin
Kevin McFarlane19-Oct-03 6:16
Kevin McFarlane19-Oct-03 6:16 
GeneralDatabase Implementation, Please!!! Pin
Chopper19-Oct-03 4:39
Chopper19-Oct-03 4:39 
GeneralSetAtGrow problem Pin
YaronNir19-Oct-03 2:42
YaronNir19-Oct-03 2:42 
GeneralRe: SetAtGrow problem Pin
BadJerry19-Oct-03 7:11
BadJerry19-Oct-03 7:11 
GeneralRe: SetAtGrow problem Pin
YaronNir19-Oct-03 7:12
YaronNir19-Oct-03 7:12 
GeneralSwitchnig beetween views Pin
Chernobog119-Oct-03 0:38
Chernobog119-Oct-03 0:38 
GeneralMCI prob Pin
AI_Warrior19-Oct-03 0:30
AI_Warrior19-Oct-03 0:30 
GeneralRe: MCI prob Pin
Alexander M.,19-Oct-03 4:00
Alexander M.,19-Oct-03 4:00 
GeneralSending a "Click". Help please is urgent. Pin
Rafael Fernández López18-Oct-03 23:54
Rafael Fernández López18-Oct-03 23:54 
GeneralRe: Sending a &quot;Click&quot; Pin
User 665819-Oct-03 1:00
User 665819-Oct-03 1:00 
GeneralRe: Sending a "Click". Help Please, is Urgent Pin
Rafael Fernández López19-Oct-03 1:01
Rafael Fernández López19-Oct-03 1:01 
GeneralRe: Sending a &quot;Click&quot;. Help please is urgent. Pin
Michael Dunn19-Oct-03 5:35
sitebuilderMichael Dunn19-Oct-03 5:35 
GeneralRe: Sending a &quot;Click&quot;. Help please is urgent. Pin
Rafael Fernández López19-Oct-03 5:51
Rafael Fernández López19-Oct-03 5:51 
GeneralRe: Sending a &quot;Click&quot;. Help please is urgent. Pin
Michael Dunn19-Oct-03 8:28
sitebuilderMichael Dunn19-Oct-03 8:28 
GeneralRe: Sending a &quot;Click&quot;. Help please is urgent. Pin
Rafael Fernández López19-Oct-03 10:19
Rafael Fernández López19-Oct-03 10:19 
GeneralRe: Sending a &quot;Click&quot;. Help please is urgent. Pin
Jonas Larsson20-Oct-03 1:08
Jonas Larsson20-Oct-03 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.