ITnetwork summer 2020 ITnetwork summer 2020
Avatar

TicTacToe went Zalgo


Nahoru
6.10.2017 19:31
Avatar
Avatar
Jaroslav Dubánek

Inu, tak moc jsem se snažil o naprogramování hry piškvorek v C++, že jsem se naboural do matrice časoprostoru.

6.10.2017 19:33
Avatar
Avatar
Jaroslav Dubánek

Tady je na důkaz mých nadpřirozených neschopností:

#include <iostream>
#include <cstdlib>
using namespace std;



int main()
{
    char pole[11][17];
    for (int k = 0; k < 11; k++)
    {
        for (int j = 0; j < 17; j++)
        {
            if (j == 5 || j == 11)
            {
                pole[k][j] = '|';
            }
            if (k == 3 || k == 7)
            {
                pole[k][j] = '-';
                if (j == 5 || j == 11)
                {
                    pole[k][j] = '+';
                }
            }
            cout << pole[k][j];
        }
        cout << endl;
    }

}
6.10.2017 20:47
Avatar
#include <iostream>
using namespace std;

int main()
{
    cout << "Give me secret number 1 to 100 "
        << "and I will guess it in 7 tries. Go!\n";
    int y;
    char ch;
    cin >> y;
    int tries = 1;
    int x = 50;
    int xl = 0;
    int xh = 101;
    cout << "How about " << x << "?\n";
    if (x != y)
    {
        cout << "Was it too high a) or too low b)?\n";
        cin >> ch;
        if (ch == 'a')
        {
            xh = x;
            x = 25;
        }
        else if (ch == 'b')
        {
            xl = x;
            x = 75;
        }
        cout << "How about now? " << x << endl;
        tries++;
    }
    while (x != y)
    {
        cout << "Was it too high a) or too low b)?\n";
        cin >> ch;
        if (ch == 'a')
        {
            xh = x;
            x -= (xh - (xl - 1)) / 2;
        }
        else if (ch == 'b')
        {
            xl = x;
            x += ((1 + xh) - xl) / 2;
        }
        cout << "How about now? " << x << endl;
        tries++;
    }
    if (x == y)
    {
        cout << "Congratulations. It is " << x << endl
        << " after " << tries << ". try. \"Good job!\"";
    }
    return 0;
}
Nahoru
5.10.2017 19:53