X and 0 Steemit

in #utopian-io5 years ago

download.jpg
Hello, today i made my own game named X and 0. It's not a big achivement but, it's a beggining. I hope you will enjoy the game.The game was made in C++ because that is the language i learn to school. If you like what i made just please up-vote. Thank you.

The code
=---------------------------------------------------------------------------------------------------------------------------------=

#include <> //iostream
using namespace std;
void afisare()
{
cout<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------"<<endl<<endl;
cout<<" "<<"Welcome!"<<endl;
cout<<" "<<"This game is named X & 0.I will show you the options!"<<endl<<endl;
cout<<"------------------------------------------------------------------------------------------------------------------------"<<endl<<endl;
}

void optiuni()
{
cout<<endl;
cout<<" 1. Start game."<<endl;
cout<<" 2. Rules."<<endl;
cout<<" 3. How to play?"<<endl;
cout<<" 4. Turn off the game."<<endl;
}

void a4()
{
cout<<endl<<endl;
cout<<"========================================================================================================================"<<endl;
cout<<" "<<"You close the game."<<endl;
cout<<" "<<"Press any key to close the window."<<endl<<endl;
cout<<"========================================================================================================================"<<endl;
}

char square[10] = {'o','1','2','3','4','5','6','7','8','9'};

int checkwin();
void board();

int a1()
{
int player = 1,i,choice;

char mark;
do
{
    board();
    player=(player%2)?1:2;

    cout << " *Player " << player << ", press number:  ";
    cin >> choice;

    mark=(player == 1) ? 'X' : 'O';

    if (choice == 1 && square[1] == '1')

        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, your opponent already took that square. Choose again: ";

        player--;
        cin.ignore();
        cin.get();
    }
    i=checkwin();

    player++;
}while(i==-1);
board();
if(i==1)

    cout<<"==>\aPlayer "<<--player<<" won.";
else
    cout<<"==>\aDraw!";

cin.ignore();
cin.get();
return 0;

}

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;

}

void board()
{
cout<<endl;
cout << endl<<endl<<endl;

cout <<"                                                 "<< "     |     |     " << endl;
cout << "                                                   "<< square[1] << "  |  " << square[2] << "  |  " << square[3] << endl;

cout <<"                                                 "<< "_____|_____|_____" << endl;
cout <<"                                                 "<< "     |     |     " << endl;

cout<<"                                                 "<< "  " << square[4] << "  |  " << square[5] << "  |  " << square[6] << endl;

cout <<"                                                 "<< "_____|_____|_____" << endl;
cout <<"                                                 "<< "     |     |     " << endl;

cout <<"                                                 "<< "  " << square[7] << "  |  " << square[8] << "  |  " << square[9] << endl;

cout <<"                                                 "<< "     |     |     " << endl << endl;

}

void a2()
{
cout<<endl<<endl;
cout<<"========================================================================================================================"<<endl<<endl;
cout<<" 1.Don't try to close the window if your opponent wins!"<<endl<<endl;
cout<<" 2.The first player has 5 picks and the second player has 4 picks on the board."<<endl<<endl;
cout<<" 3.You can't choose opponent's square."<<endl<<endl;
cout<<" 4.To win, you must have X X X or O O O diagonally / vertically / horizontally."<<endl<<endl;
cout<<"========================================================================================================================"<<endl<<endl;
}

void a3 ()
{
cout<<endl<<endl;
cout<<"========================================================================================================================"<<endl<<endl;
cout<<" *The board will be marked as (1.9)."<<endl<<endl;
cout<<" *Start by choosing which of the checkboxes you want to pick."<<endl<<endl;
cout<<" *Continue the moves until one of you gets to win the win."<<endl<<endl;
cout<<" *CHARGING CONDITION: To win, you must have X X X or O O O diagonally / vertically / horizontally."<<endl<<endl;
cout<<" *If this can not be done, the draw will be reached."<<endl<<endl;
cout<<" *Good luck, and it's best to win."<<endl<<endl;
cout<<"========================================================================================================================"<<endl<<endl;
}

int main()
{
int start;
afisare();
optiuni();
cout<<endl;
cout<<"The number is: "; cin>>start;
if (start==4)
a4();
if (start==1)
{
cout<<endl<<endl<<endl;
cout<<"========================================================================================================================"<<endl;
cout<<" "<< "Good luck, and it's best to win.!"<<endl<<endl;
cout << " *Player 1 uses (X)."<<endl<<endl;
cout<<" *Player 2 uses (O)."<< endl;
a1();
}
if (start==2)
a2();
if (start==3)
a3();

}

=---------------------------------------------------------------------------------------------------------------------------------=

Sort:  

Congratulations @speologul! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!