#include iostream
#include time.h
#include stdlib.h
#include windows.h
#include conio.h
void one();
void two();
void three();
void four();
void five();
void six();
int main()
{
short unsigned int score = 0;
short unsigned int compScore = 0;
short unsigned int num = 0;
short unsigned int num2 = 0;
short unsigned int compNum = 0;
short unsigned int compNum2 = 0;
short unsigned int sum = 0;
short unsigned int compSum = 0;
char letter;
srand(time(NULL));
system("title Je Dice Game");
while (letter != 'q')
{
    cout << "Your Score: " << score << "\n";
    cout << "computer's Score: " << compScore << "\n\n";
    cout << "Press r to roll or q to quit: ";
    cin >> letter;
    num = 1 + rand() % (6 - 1 + 1);
    num2 = 1 + rand() % (6 - 1 + 1);
    compNum = 1 + rand() % (6 - 1 + 1);
    compNum2 = 1 + rand() % (6 - 1 + 1);
    sum = num + num2;
    compSum = compNum + compNum2;
    if (letter == 'q')
        break;
    if (letter != 'r')
    {
        system("cls");
        continue;
    }
    switch (num)
    {
        case 1:
                one();
                break;
        case 2:
                two();
                break;
        case 3:
                three();
                break;
        case 4:
                four();
                break;
        case 5:
                five();
                break;
        case 6:
                six();
                break;
        default:
                cout << "Error...";
                break;
    }
    switch (num2)
    {
        case 1:
                one();
                break;
        case 2:
                two();
                break;
        case 3:
                three();
                break;
        case 4:
                four();
                break;
        case 5:
                five();
                break;
        case 6:
                six();
                break;
        default:
                cout << "Error...";
                break;
    }
    cout << "\nYours: " << num << ", " << num2 << "\n";
    cout << "Computer's: " << compNum << ", " << compNum2 << "\n\n";
    if (sum > compSum)
    {
        cout << "You won!!\n\n";
        score++;
    }
    else
    {
        compScore++;
        cout << "you lost...\n\n";
    }
    system("pause");
    system("cls");
    if (score == 12)
    {
        MessageBox(0, "You Won!!!", "Results:", MB_ICONEXCLAMATION);
        break;
    }
    if (compScore == 12)
    {
        MessageBox(0, "You lost...", "Results:", MB_ICONEXCLAMATION);
        break;
    }
}
getche();
}
void one()
{
cout << "-----\n";
cout << "|       |\n";
cout << "|  O  |\n";
cout << "|       |\n";
cout << "-----\n";
}
void two()
{
cout << "-----\n";
cout << "|    O|\n";
cout << "|       |\n";
cout << "|O    |\n";
cout <<  "-----\n";
}
void three()
{
cout << " -----\n";
cout << "|    O|\n";
cout << "|  O  |\n";
cout << "|O    |\n";
cout <<  " -----\n";
}
void four()
{
cout << " -----\n";
cout << "|O   O|\n";
cout << "|         |\n";
cout << "|O   O|\n";
cout <<  " -----\n";
}
void five()
{
cout << " -----\n";
cout << "|O   O|\n";
cout << "|  O    |\n";
cout << "|O   O|\n";
cout <<  " -----\n";
}
void six()
{
cout << " -----\n";
cout << "|O   O|\n";
cout << "|O   O|\n";
cout << "|O   O|\n";
cout <<  " -----\n";
}
Mengenai Saya
 
- J3 ScRipT
- Kediri, java_script, Indonesia
- Selamat datang di dalam situs q,postingan tentang c++, java dan html script serta masih banyak lagi akan nimbrung semua disini
Langganan:
Posting Komentar (Atom)
 
Tidak ada komentar:
Posting Komentar