#Help with a game - Black Box

11 messages · Page 1 of 1 (latest)

fathom panther
#

Basically i need to implement a mechanic that allows me to shoot at randomly placed atoms in an array from walls of the array. My shot can be reflected detoured or it can hit an atom, but I have no Idea how to write a function that keeps track of the shot in relation with atoms. Below I post a wiki page where you can see how it works.
https://en.wikipedia.org/wiki/Black_Box_(game)

Black Box is an abstract board game for one or two players, which simulates shooting rays into a black box to deduce the locations of "atoms" hidden inside. It was created by Eric Solomon. The board game was published by Waddingtons from the mid-1970s and by Parker Brothers in the late 1970s. The game can also be played with pen and paper, and t...

fathom panther
#

I have a struct atom that contains coordinates of an atom, I guess I need to make a void that checks if a ray is close to an atom, but how do I "move" the ray? Seems like I need to write out an if for every scenario which will be messy

#

I don't have much code for now, I want to deconstruct the idea first

fathom panther
#

that's it

#

sounds messy

#

i was thinking about for example if ray is moving right and at ray position x+1 y+1 there's an atom, move up

#

but i would have to create 4 cases for each direction

fathom panther
#

right now I have a problem to display atoms

#
#include <iostream>
#include <stdio.h>
using namespace std;
const int max1 = 5;
const int max2 = 8;
const int max3 = 10;
int wiersze;        // l wierszy i kolumn - do przypisania dla nowego poziomu
int kolumny;
int A[max1][max1];
int Akop[max1][max1];
struct atom {
    int x;
    int y;
};
struct pointer {
    int x;
    int y;
};

pointer p;

void printGrid(int A[5][5]) {
    system("CLS"); 
    for (int i = 0; i < wiersze; ++i) {
        for (int j = 0; j < kolumny; ++j) {
            if (i == p.x && j == p.y) {   //na pozycji kursora drukuj *
                cout << "* ";
            }
            else {
                cout << A[i][j] << " ";
            }
        }
        cout << endl;
    }
}

void copyGrid(int A[5][5], int Akop[5][5]) {
    for (int i = 0; i < wiersze; ++i) {
        for (int j = 0; j < kolumny; ++j) {
            Akop[i][j] = A[i][j];
        }
    }
}

void restoreGrid(int A[5][5], int Akop[5][5]) {
    for (int i = 0; i < wiersze; ++i) {
        for (int j = 0; j < kolumny; ++j) {
            A[i][j] = Akop[i][j];
        }
    }
}



int main()
{
    cout << "\n" << "Black Box"<<endl;
    
    srand(time(NULL));
    struct atom atom1;
    struct atom atom2;
    struct atom atom3;
    atom1.x = rand() % 5;
    atom1.y = rand() % 5;
    atom2.x = rand() % 5;
    atom2.y = rand() % 5;
    atom3.x = rand() % 5;
    atom3.y = rand() % 5;
    system("pause");

    for (int i = 0; i < max1; i++) {
    for (int j = 0; j < max1; j++) {
        A[i][j] = 0;
    }
}

// Umieszczenie atomów na odpowiednich pozycjach
A[atom1.y][atom1.x] = 1;
A[atom2.y][atom2.x] = 1;
A[atom3.y][atom3.x] = 1;
    copyGrid(A, Akop);
    printGrid(A);```
#
    char userInput;
    wiersze = kolumny = max1;
    while (true) {
        userInput = getchar();

        if (userInput == 'w' && p.x > 0) {
            --p.x;
            printGrid(A);
        }
        else if (userInput == 'a' && p.y > 0) {
            --p.y;
            printGrid(A);
        }
        else if (userInput == 's' && p.x < wiersze - 1) {
            ++p.x;
            printGrid(A);
        }
        else if (userInput == 'd' && p.y < kolumny - 1) {
            ++p.y;
            printGrid(A);
        }
        else if (userInput == '\n') {
            restoreGrid(A, Akop);
            printGrid(A);
        }
    }

    return 0;
}```
#

but why like this