making a tic tac toe game C++
Hey,
I'm having trouble getting a simple tic tac toe game to work with visual studio C++ 2010 express and dev-c++. Can anyone get it working and let me know the steps?
I tried the code on this website for the game in both compilers with no success.
http://www.cppgameprogramming.com/cg...page=tictactoe
Any ideas?
Thanks,
Joe
Re: making a tic tac toe game C++
Quote:
First of all, you will need to download and install Allegro...
Did you?
Re: making a tic tac toe game C++
and why do you need dev-c++ and visual c++?
Re: making a tic tac toe game C++
hey,
I have allegro downloaded
~
Joe
Re: making a tic tac toe game C++
I was just trying in either compiler since they work a bit differently, sorry for the dev C++ and express 2010 confusion.
Any help would be appreciated if anyone has gotten a game like this working.
~
Joe
Re: making a tic tac toe game C++
Quote:
Originally Posted by
coder85
I was just trying in either compiler since they work a bit differently, sorry for the dev C++ and express 2010 confusion.
Any help would be appreciated if anyone has gotten a game like this working.
~
Joe
So far, you have not said what doesn't work. Is it a compiler error? Linker error? Runtime error?
If you told us in more detail what exactly doesn't work, then maybe no one needs to download all of these libraries to help you.
Regards,
Paul McKenzie
Re: making a tic tac toe game C++
hey,
Right now It says that visual studio 2010 can't find the file lesson9/debug/ConsoleLesson9.exe.
I tried saving the main.cpp file as that though and it's still not finding it. very odd.
~
Joe
Re: making a tic tac toe game C++
Quote:
Originally Posted by
coder85
Hey,
I'm having trouble getting a simple tic tac toe game to work with visual studio C++ 2010 express and dev-c++. Can anyone get it working and let me know the steps?
I tried the code on this website for the game in both compilers with no success.
http://www.cppgameprogramming.com/cg...page=tictactoe
Any ideas?
Thanks,
Joe
hey ! I've made my own tic tac toe game didn't take long !
here's the code so you can check on it if you feel like it
#include <iostream>
#include "conio.h"
using namespace std;
void main()
{
char csquare1('1');
char csquare2('2');
char csquare3('3');
char csquare4('4');
char csquare5('5');
char csquare6('6');
char csquare7('7');
char csquare8('8');
char csquare9('9');
int iplayer1 = 1;
bool bvalid;
bool bgameover(true);
do{
cout << csquare1 << "|" << csquare2 << "|" << csquare3 << endl;
cout << "-+-+-" << endl;
cout << csquare4 << "|" << csquare5 << "|" << csquare6 << endl;
cout << "-+-+-" << endl;
cout << csquare7 << "|" << csquare8 << "|" << csquare9 << endl;
char cchoice;
char cmark;
if(iplayer1 == 1){
cmark = 'X';
}else{
cmark = 'O';
}
do{
cout << "it is player" << iplayer1 << "'s turn" << endl;
bvalid = true;
cin >> cchoice;
if(cchoice == csquare1) {
csquare1 = cmark;
} else if(cchoice == csquare2){
csquare2 = cmark;
} else if(cchoice == csquare3){
csquare3 = cmark;
} else if(cchoice == csquare4){
csquare4 = cmark;
} else if(cchoice == csquare5){
csquare5 = cmark;
} else if(cchoice == csquare6){
csquare6 = cmark;
} else if(cchoice == csquare7){
csquare7 = cmark;
} else if(cchoice == csquare8){
csquare8 = cmark;
} else if(cchoice == csquare9){
csquare9 = cmark;
}else{
cout << "invalid move , please play again" << endl;
bvalid = false;
}
}
while(!bvalid);
bool bwin(true);
bgameover = false;
if(csquare1 == csquare2 && csquare2 == csquare3){
bgameover = true;
} if(csquare1 == csquare4 && csquare4 == csquare7){
bgameover = true;
} if(csquare7 == csquare8 && csquare8 == csquare9){
bgameover = true;
} if(csquare1 == csquare5 && csquare5 == csquare9){
bgameover = true;
} if(csquare7 == csquare5 && csquare5 == csquare3){
bgameover = true;
} if(csquare3 == csquare6 && csquare6 == csquare9){
bgameover = true;
} if(csquare2 == csquare5 && csquare5 == csquare8){
bgameover = true;
} if(csquare4 == csquare5 && csquare5 == csquare6){
bgameover = true;
}
if(csquare1 != '1' && csquare2 != '2' && csquare3 != '3' &&
csquare4 != '4' && csquare5 != '5' && csquare6 != '6' &&
csquare7 != '7' && csquare8 != '8' && csquare9 != '9' && !bgameover){
bgameover = true;
bwin = false;
}
if(bgameover){
if(bwin){
cout << "congratulations player " << iplayer1 << " you won the game!" << endl;
}
cout << csquare1 << "|" << csquare2 << "|" << csquare3 << endl;
cout << "-+-+-" << endl;
cout << csquare4 << "|" << csquare5 << "|" << csquare6 << endl;
cout << "-+-+-" << endl;
cout << csquare7 << "|" << csquare8 << "|" << csquare9 << endl;
cout << "the game is over, would you like to play again? y/n" << endl;
char ckeepplaying;
cin >> ckeepplaying;
if(ckeepplaying == 'y'){
csquare1 = '1';
csquare2 = '2';
csquare3 = '3';
csquare4 = '4';
csquare5 = '5';
csquare6 = '6';
csquare7 = '7';
csquare8 = '8';
csquare9 = '9';
iplayer1 = 1;
bgameover = false;
}
}
else{
if(iplayer1 == 1){
iplayer1 = 2;
}else{
iplayer1 = 1;
}
}
}
while (!bgameover);
}