12 Replies - 761 Views - Last Post: 10 October 2012 - 09:20 PM
#1
where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 03:25 AM
this is the challenge, i dont want the answer but i need hints enough to know how to study for it or approach the problem, i know i need an array in a loop to display the board, do i do this by writing lines and endlines or is there some kinda board function?
Make a two player tic tac toe game.
★ Modify the program so that it will announce when a player has won the game (and which player won, x or o)
★★ Modify the program so that it is a one player game against the computer (with the computer making its moves randomly)
★★★★ Modify the program so that anytime the player is about to win (aka, they have 2 of 3 x's in a row, the computer will block w/ an o)
Replies To: where t start studying to learn how to go about this practice chalenge
#2
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 03:49 AM
char board = [3][3]
Ie: Then just check based on:
The positions of Xs, Os and clears within the array.
Like this:
if (board[3][3] == 'X' && ) \\etc
{
cout << "X wins!"
}
And so on for that. I don't know too much about painting and drawing things, just the logic stuff.
This post has been edited by DimitriV: 09 October 2012 - 03:50 AM
#3
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 04:16 AM
#4
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 04:22 AM
You could just have it running and clearing the screen:
http://www.cplusplus.../beginner/3304/
This link advises not to use System calls and instead use cout.
Urrgh: how are you going to get it to place the tiles in the right space?
This post has been edited by DimitriV: 09 October 2012 - 04:26 AM
#5
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 08:11 AM
trying to understand why it wont update the characters in "getboard"
#include <iostream>
#include <string>
using namespace std;
char a,b,c,d,e,f,g,h,i,j;// so these represent the empty spaces in getbrd
char x = 'X';
char o = 'O';// these are what i want to replace the empty spaces with
string name;
string name2;
char brdlog [3] [3];// im not using this yet
void getbrdstart ();//this is just the display to start with
void getbrd ();
int input;
void plyr1 ();//the function that usees a switch statment to replace spaces in \\getbrd
int main ()
{
getbrdstart ();
cout << "TIC TAC TOE BY DEVONREVENGE\n"<<endl;
cout << "player 1 enter your name..."<<endl;
cin >> name;
cout << "player 2 enter your name..."<<endl;
cin >>name2;
plyr1 ();
getbrd ();
return 0;
}
void getbrd ()
{
cout << a << "|" << b << "|" << c<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << d<<"|"<<e<<"|"<< f <<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << g<<"|"<<h<<"|"<< i <<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"<< endl;
}
void getbrdstart ()
{
cout << "1" << "|" << "2" << "|" << "3"<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << "4"<<"|"<<"5"<<"|"<< "6" <<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << "7"<<"|"<<"8"<<"|"<< "9\n \n" <<endl;
}
void plyr1 ()
{
cout << name << "input number to place your O"<<endl;
cin >> input;
switch (input)
{
case '1':
a=o;
break;
case '2':
b=o;
break;
case '3':
c=o;
break;
case '4':
d=o;
break;
case '5':
e=o;
break;
case '6':
f=o;
break;
case '7':
g=o;
break;
case '8':
h=o;
break;
case '9':
i=o;
break;
}
}
wait this is the wrong place i will put it somwhere else in the main help bit
This post has been edited by devonrevenge: 09 October 2012 - 08:19 AM
Reason for edit:: Fixed Code tags.
#6
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 08:34 AM
no ones gonna bloody see it here too and now i cant talk about it to anyone else theyve kind of made my subject taboo
This post has been edited by devonrevenge: 09 October 2012 - 08:41 AM
#7
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 09:17 AM
Quote
No, we just do not need to have 2 -> n possible threads about the same topic of yours.
#8
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 09:18 AM
People will respond when and if they so desire. You can really help yourself to get more help by finding an indentation style you like and use it consistently, using meaningful variable names, avoiding global variables.
Jim
This post has been edited by jimblumberg: 09 October 2012 - 09:18 AM
Reason for edit:: Added Missing link.
#9
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 09:55 AM
Anyway, you are inputting an integer input, yet in your switch statement you are comparing against characters.
#10
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 10:08 AM
#11
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 11:15 AM
DimitriV, on 09 October 2012 - 03:49 AM, said:
char board = [3][3]
Ie: Then just check based on:
The positions of Xs, Os and clears within the array.
Like this:
if (board[3][3] == 'X' && ) \\etc
{
cout << "X wins!"
}
And so on for that. I don't know too much about painting and drawing things, just the logic stuff.
Beware: The code above overruns the buffer because C/C++ arrays are zero based.
#12
Re: where t start studying to learn how to go about this practice chalenge
Posted 09 October 2012 - 11:27 AM
#13
Re: where t start studying to learn how to go about this practice chalenge
Posted 10 October 2012 - 09:20 PM
For eg.
char tictac[]={'_','_','_','_','_','_','_','_','_'}/*I am not sure if this can be done but you can try it*/
.
.
.
switch(input)
{
case 1: tictac[0]=o;
break;
case 2: tictac[1]=o;
.
.
.
.
case 9: tictac[8]=o;
}
And remember to change the variable values to array values in your getbrd function.
Hope the idea I have provided helps you.
regards,
Raghav
This post has been edited by raghav.naganathan: 10 October 2012 - 09:22 PM
|
|

New Topic/Question
Reply




MultiQuote






|