Php - BGA Stuff Flashcards

1
Q

What is the purpose of the build_page method in a BGA game view file?

A

The build_page method generates and modifies the HTML for the game interface. It is called when the game starts or when a player refreshes the page.

public function build_page($viewArgs) {
    // Custom HTML rendering logic goes here
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the begin_block() function do in a BGA game view file?

A

The begin_block() function marks the start of a block in the template file (.tpl), allowing you to dynamically populate it with content.

$this->page->begin_block("reversiturorial_reversiturorial", "square");

This tells the template engine to start populating the “square” block in the reversiturorial_reversiturorial.tpl file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two parameters passed to begin_block() in the build_page method?

A

The first parameter is the name of the template file (without the .tpl extension), and the second is the name of the block within that template.

$this->page->begin_block("game_view_name", "block_name");
  • game_view_name: The template file name (without .tpl).
  • block_name: The block to be populated.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the insert_block() function do in a BGA game view file?

A

The insert_block() function inserts dynamically calculated values into the block defined in the template file (.tpl), rendering the corresponding HTML.

$this->page->insert_block("square", array(
    'X' => $x,
    'Y' => $y,
    'LEFT' => round(($x - 1) * 64.8 + 10),
    'TOP' => round(($y - 1) * 64.4 + 7)
));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In the context of BGA, what are ‘X’, ‘Y’, ‘LEFT’, and ‘TOP’ used for when passed into insert_block()?

A

‘X’ and ‘Y’ represent the square’s coordinates on the game board, while ‘LEFT’ and ‘TOP’ represent the square’s calculated position in pixels for absolute positioning.

$this->page->insert_block("square", array(
    'X' => 1,  // X coordinate
    'Y' => 2,  // Y coordinate
    'LEFT' => 74,  // Calculated horizontal position
    'TOP' => 128   // Calculated vertical position
));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an associative array in PHP?

A

An associative array is a data structure that stores key-value pairs, where each key is associated with a specific value.

$person = array(
    "name" => "Alice",
    "age" => 25,
    "job" => "Engineer"
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you access a value from an associative array in PHP?

A

You access a value from an associative array by referencing its key.

echo $person["name"];  // Outputs: Alice

You access the value “Alice” using the key ‘name’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you loop through rows and columns in the build_page method?

A
for ($x = 1; $x <= 8; $x++) {
    for ($y = 1; $y <= 8; $y++) {
        // Insert each square's data into the template
    }
}

Looping through rows and columns allows the creation of an 8x8 grid, dynamically positioning each square on the game board based on its row and column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does absolute positioning work in the BGA grid layout?

A

Absolute positioning uses ‘LEFT’ and ‘TOP’ values in CSS to place each square at its correct location on the board, relative to the board’s top-left corner.

.square {
    position: absolute;
    left: 74px;  /* Horizontal position */
    top: 128px;  /* Vertical position */
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do hor_scale and ver_scale represent in the build_page method?

A

hor_scale and ver_scale are constants representing the width and height of each individual square on the game board in pixels.

$hor_scale = 64.8;  // Width of each square
$ver_scale = 64.4;  // Height of each square
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are hor_scale and ver_scale used in the build_page method?

A

They are used to calculate the exact pixel positions (LEFT and TOP) for each square on the board by multiplying the square’s position (X or Y) by the respective scale.

$left = round(($x - 1) * $hor_scale + 10);
$top = round(($y - 1) * $ver_scale + 7);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does the LEFT and TOP calculation work for a specific square (e.g., X=3, Y=5)?

A

For square (X=3, Y=5), you calculate the pixel position like this:

$left = round((3 - 1) * 64.8 + 10);  // $left = 140px
$top = round((5 - 1) * 64.4 + 7);    // $top = 265px

he square will be positioned at (140px, 265px) on the board.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly