Can anyone help me with my program? I am making Tic-Tac-Toe and I am stuck. Here is all of my code that I have done so far....
.
.
.
This is called design_of_board.h
#include <iostream>
#include <string>
#include <Windows.h>
#include <conio.h>
#include <ctime>
#include <vector>
#include <algorithm>
using namespace std;
void gotoxy(int x, int y)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD point;
point.X = x-1;
point.Y = y-1;
SetConsoleCursorPosition(hConsole, point);
return;
}
void delay(long seconds)
{
clock_t time1 = clock(); // use clock time
clock_t time2 = time1 + seconds;
while(time1 < time2)
time1 = clock();
return;
}
void continue_() { char whatever; cout << "Press any key to continue: "; whatever = _getch(); }
void the_board()
{
gotoxy(28,7); printf("%c",201);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",203);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",203);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",187);
gotoxy(28,8); printf("%c",186); gotoxy(37,8); printf("%c",186); gotoxy(46,8); printf("%c",186); gotoxy(55,8); printf("%c",186);
gotoxy(28,9); printf("%c",186); gotoxy(37,9); printf("%c",186); gotoxy(46,9); printf("%c",186); gotoxy(55,9); printf("%c",186);
gotoxy(28,10); printf("%c",186); gotoxy(37,10); printf("%c",186); gotoxy(46,10); printf("%c",186); gotoxy(55,10); printf("%c",186);
gotoxy(28,11); printf("%c",186); gotoxy(37,11); printf("%c",186); gotoxy(46,11); printf("%c",186); gotoxy(55,11); printf("%c",186);
gotoxy(28,12); printf("%c",186); gotoxy(37,12); printf("%c",186); gotoxy(46,12); printf("%c",186); gotoxy(55,12); printf("%c",186);
gotoxy(28,13); printf("%c",204); printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",185);
gotoxy(28,14); printf("%c",186); gotoxy(37,14); printf("%c",186); gotoxy(46,14); printf("%c",186); gotoxy(55,14); printf("%c",186);
gotoxy(28,15); printf("%c",186); gotoxy(37,15); printf("%c",186); gotoxy(46,15); printf("%c",186); gotoxy(55,15); printf("%c",186);
gotoxy(28,16); printf("%c",186); gotoxy(37,16); printf("%c",186); gotoxy(46,16); printf("%c",186); gotoxy(55,16); printf("%c",186);
gotoxy(28,17); printf("%c",186); gotoxy(37,17); printf("%c",186); gotoxy(46,17); printf("%c",186); gotoxy(55,17); printf("%c",186);
gotoxy(28,18); printf("%c",186); gotoxy(37,18); printf("%c",186); gotoxy(46,18); printf("%c",186); gotoxy(55,18); printf("%c",186);
gotoxy(28,19); printf("%c",204); printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",185);
gotoxy(28,20); printf("%c",186); gotoxy(37,20); printf("%c",186); gotoxy(46,20); printf("%c",186); gotoxy(55,20); printf("%c",186);
gotoxy(28,21); printf("%c",186); gotoxy(37,21); printf("%c",186); gotoxy(46,21); printf("%c",186); gotoxy(55,21); printf("%c",186);
gotoxy(28,22); printf("%c",186); gotoxy(37,22); printf("%c",186); gotoxy(46,22); printf("%c",186); gotoxy(55,22); printf("%c",186);
gotoxy(28,23); printf("%c",186); gotoxy(37,23); printf("%c",186); gotoxy(46,23); printf("%c",186); gotoxy(55,23); printf("%c",186);
gotoxy(28,24); printf("%c",186); gotoxy(37,24); printf("%c",186); gotoxy(46,24); printf("%c",186); gotoxy(55,24); printf("%c",186);
gotoxy(28,25);printf("%c",200); printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",202);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",202);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",188);
}
void Enter_Information_box()
{
gotoxy(7,30); printf("%c",201);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",187);
gotoxy(7,31); printf("%c",186); gotoxy(87,31);printf("%c",186);
gotoxy(7,32); printf("%c",186); gotoxy(87,32);printf("%c",186);
gotoxy(7,33); printf("%c",186); gotoxy(87,33);printf("%c",186);
gotoxy(7,34); printf("%c",186); gotoxy(87,34);printf("%c",186);
gotoxy(7,35); printf("%c",186); gotoxy(87,35);printf("%c",186);
gotoxy(7,36);printf("%c",200); printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",205);printf("%c",188);
}
void placing_the_numbers()
{
gotoxy(33,10); cout << "1" << endl;
gotoxy(42,10); cout << "2" << endl;
gotoxy(51,10); cout << "3" << endl;
gotoxy(33,16); cout << "4" << endl;
gotoxy(42,16); cout << "5" << endl;
gotoxy(51,16); cout << "6" << endl;
gotoxy(33,22); cout << "7" << endl;
gotoxy(42,22); cout << "8" << endl;
gotoxy(51,22); cout << "9" << endl;
}
void get_rid_of_1() { gotoxy(33,10); cout << " " << endl; }
void get_rid_of_2() { gotoxy(42,10); cout << " " << endl; }
void get_rid_of_3() { gotoxy(51,10); cout << " " << endl; }
void get_rid_of_4() { gotoxy(33,16); cout << " " << endl; }
void get_rid_of_5() { gotoxy(42,16); cout << " " << endl; }
void get_rid_of_6() { gotoxy(51,16); cout << " " << endl; }
void get_rid_of_7() { gotoxy(33,22); cout << " " << endl; }
void get_rid_of_8() { gotoxy(42,22); cout << " " << endl; }
void get_rid_of_9() { gotoxy(51,22); cout << " " << endl; }
void clear_line() { gotoxy(10,33); cout << " " << endl; }
void clear_name_turn() { gotoxy(66,5); cout << " " << endl; }
.
.
.
.
.
.
This is called the_pieces_for_playing.h
#include "design_of_board.h"
// Player 1 Piece
void put_a_plus_where_1_is()
{
gotoxy(32,9); printf("%c",186);
gotoxy(30,10); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(32,11); printf("%c",186);
}
void put_a_plus_where_2_is()
{
gotoxy(41,9); printf("%c",186);
gotoxy(39,10); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(41,11); printf("%c",186);
}
void put_a_plus_where_3_is()
{
gotoxy(50,9); printf("%c",186);
gotoxy(48,10); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(50,11); printf("%c",186);
}
void put_a_plus_where_4_is()
{
gotoxy(32,15); printf("%c",186);
gotoxy(30,16); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(32,17); printf("%c",186);
}
void put_a_plus_where_5_is()
{
gotoxy(41,15); printf("%c",186);
gotoxy(39,16); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(41,17); printf("%c",186);
}
void put_a_plus_where_6_is()
{
gotoxy(50,15); printf("%c",186);
gotoxy(48,16); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(50,17); printf("%c",186);
}
void put_a_plus_where_7_is()
{
gotoxy(32,21); printf("%c",186);
gotoxy(30,22); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(32,23); printf("%c",186);
}
void put_a_plus_where_8_is()
{
gotoxy(41,21); printf("%c",186);
gotoxy(39,22); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(41,23); printf("%c",186);
}
void put_a_plus_where_9_is()
{
gotoxy(50,21); printf("%c",186);
gotoxy(48,22); printf("%c",205);printf("%c",205);printf("%c",206);printf("%c",205);printf("%c",205);
gotoxy(50,23); printf("%c",186);
}
// Player 2 Piece / Or Computer Piece
void put_a_square_where_1_is()
{
gotoxy(31,9); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(31,10); printf("%c",186); gotoxy(33,10); printf("%c",186);
gotoxy(31,11); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_2_is()
{
gotoxy(40,9); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(40,10); printf("%c",186); gotoxy(42,10); printf("%c",186);
gotoxy(40,11); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_3_is()
{
gotoxy(49,9); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(49,10); printf("%c",186); gotoxy(51,10); printf("%c",186);
gotoxy(49,11); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_4_is()
{
gotoxy(31,15); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(31,16); printf("%c",186); gotoxy(33,16); printf("%c",186);
gotoxy(31,17); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_5_is()
{
gotoxy(40,15); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(40,16); printf("%c",186); gotoxy(42,16); printf("%c",186);
gotoxy(40,17); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_6_is()
{
gotoxy(49,15); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(49,16); printf("%c",186); gotoxy(51,16); printf("%c",186);
gotoxy(49,17); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_7_is()
{
gotoxy(31,21); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(31,22); printf("%c",186); gotoxy(33,22); printf("%c",186);
gotoxy(31,23); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_8_is()
{
gotoxy(40,21); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(40,22); printf("%c",186); gotoxy(42,22); printf("%c",186);
gotoxy(40,23); printf("%c",200);printf("%c",205);printf("%c",188);
}
void put_a_square_where_9_is()
{
gotoxy(49,21); printf("%c",201);printf("%c",205);printf("%c",187);
gotoxy(49,22); printf("%c",186); gotoxy(51,22); printf("%c",186);
gotoxy(49,23); printf("%c",200);printf("%c",205);printf("%c",188);
}
.
.
.
.
.
.
This is called main_program.cpp
#include "the_pieces_for_playing.h"
int main()
{
system("mode 130,70");
srand(unsigned int(time(0))); // allows for using random numbers (Good for yahtzee)
string name, computers_name, question;
int turn_counter = 1;
int answer, choice, computer_pick;
vector<int> computers_movements; // holder for holding computer's previous movements
vector<int> first_players_moves; // holder for holding player's previous movements
the_board();
Enter_Information_box();
begin: gotoxy(10,33); cout << "How many players are playing this game? [1 or 2] "; cin >> answer;
clear_line();
if(answer == 1)
{
gotoxy(10,33); cout << "Is This A Question? "; getline(cin,question); clear_line(); // <================ I do not know why I need this. [insert puzzled look]
gotoxy(10,33); cout << "What is your name player 1? "; getline(cin,name); clear_line();
gotoxy(10,33); cout << "What is the Computer's name? "; getline(cin,computers_name); clear_line();
gotoxy(67,5); cout << name << "'s Turn" << endl;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
placing_the_numbers();
do // play the game until the number of turns = 9
{
// First Player's Turn
a: gotoxy(10,33); cout << "Where do you want to place your move? (Press Enter After Selecting Number) "; cin >> choice;
clear_line();
for(int i = 0; i < 9; i++) // loop that looks through 9 spots in the holders for previous player and computer movements
{
if(choice == first_players_moves.at(i) || choice == computers_movements.at(i)) // if choice = any previous move any player made then...
{
gotoxy(10,33); cout << "A piece is already there. Try Another Move." << endl; clear_line();
goto a;
}
if(choice != first_players_moves.at(i) && choice != computers_movements.at(i)) // if choice does not equal any previous made move then...
{
goto switch_statement_1;
}
}
switch_statement_1: switch(choice)
{
case 1: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_1(); put_a_plus_where_1_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 2: first_players_moves.push_back(choice);// puts number into the vector of previous human player movements
get_rid_of_2(); put_a_plus_where_2_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 3: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_3(); put_a_plus_where_3_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 4: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_4(); put_a_plus_where_4_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 5: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_5(); put_a_plus_where_5_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 6: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_6(); put_a_plus_where_6_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 7: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_7(); put_a_plus_where_7_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 8: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_8(); put_a_plus_where_8_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
case 9: first_players_moves.push_back(choice); // puts number into the vector of previous human player movements
get_rid_of_9(); put_a_plus_where_9_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
break;
default: gotoxy(10,33); cout << "Not an option. Try Again " << name << ". "; delay(3000); clear_line();
}
// Computer's Turn
b: gotoxy(67,5); cout << computers_name << "'s Turn" << endl;
gotoxy(10,33); cout << "Please Wait For " << computers_name << "...... "; delay(4000); clear_line();
computer_pick = rand() % 9 + 1; // random number from 1 through 9
for(int i = 0; i < 9; i++)
{
if(computer_pick == computers_movements.at(i)) { goto b; }
else if(computer_pick == first_players_moves.at(i)) { goto b; }
else if(computer_pick != first_players_moves.at(i) && computer_pick != computers_movements.at(i))
{
goto computers_if_statements;
}
}
computers_if_statements: if(computer_pick == 1)
{
computers_movements.push_back(computer_pick);
get_rid_of_1(); put_a_square_where_1_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 2)
{
computers_movements.push_back(computer_pick);
get_rid_of_2(); put_a_square_where_2_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 3)
{
computers_movements.push_back(computer_pick);
get_rid_of_3(); put_a_square_where_3_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 4)
{
computers_movements.push_back(computer_pick);
get_rid_of_4(); put_a_square_where_4_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 5)
{
computers_movements.push_back(computer_pick);
get_rid_of_5(); put_a_square_where_5_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 6)
{
computers_movements.push_back(computer_pick);
get_rid_of_6(); put_a_square_where_6_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 7)
{
computers_movements.push_back(computer_pick);
get_rid_of_7(); put_a_square_where_7_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 8)
{
computers_movements.push_back(computer_pick);
get_rid_of_8(); put_a_square_where_8_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
else if(computer_pick == 9)
{
computers_movements.push_back(computer_pick);
get_rid_of_9(); put_a_square_where_9_is();
turn_counter += 1;
gotoxy(16,3); cout << "Turn : " << turn_counter << endl;
clear_name_turn();
gotoxy(67,5); cout << name << "'s Turn" << endl;
}
} while( turn_counter != 9);
} // end of human player vs computer if-statement
if(answer == 2)
{
gotoxy(10,33); cout << "2 player game... "; delay(3000); clear_line();
}
else if(answer != 1 || answer != 2)
{
gotoxy(10,33); cout << "Not a choice. Try Again. "; delay(3000); clear_line();
goto begin;
}
gotoxy(7,40); continue_();
return 0;
}
.
.
.
.
.
I think my problem lies in my main_program.cpp I I think my problem is if(choice == first_players_moves.at(i)) I do not know why it is a problem, but I think it is. Anyway, any help would be appreciated. Thank You all for looking at my code. =)
- Zvjezdan Veselinovic