avoiding poo[i]Please tell me the meaning of act = FALSE;!)

Asked 1 weeks ago, Updated 1 weeks ago, 2 views

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h> // system("cls"), Sleep()
//#incldue <conio.h> kbhit, getch
#define WIDTH 20
#define HEIGHT 10

typedef struct
{
    int x;
    int y;

    int act;
}Poo;

typedef struct
{
    int x;
}Player;

Poo poo[WIDTH];
Player player;

void gotoxy(int x, int y)
{
    COORD pos = { 2 * x, y };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

int isKeyDown(int key)
{
    return ((GetAsyncKeyState(key) & 0x8000) != 0);
}

void init()
{
    int i;

    for (i = 0; i < WIDTH; i++)
        poo[i].act = FALSE; // I'm not sure what this means. I don't understand why you're doing FALSE. You can change it to TRUE, so I'd appreciate it if you could tell me what it means.

    player.x = WIDTH / 2;
}

void CreatePoo()
{
    int i;

    for (i = 0; i < WIDTH; i++)
    {
        if (!poo[i].act)
        {
            poo[i].x = rand() % WIDTH;
            poo[i].y = HEIGHT - 1;

            poo[i].act = TRUE;

            return;
        }
    }
}

void MovePoo()
{
    int i;

    for (i = 0; i < WIDTH; i++)
    {
        if (poo[i].act)
        {
            poo[i].y--;
        }
    }
}

void DeletePoo()
{
    int i;

    for (i = 0; i < WIDTH; i++)
    {
        if (poo[i].act && poo[i].y < 0)
        {
            poo[i].act = FALSE;
        }
    }
}

int PlayerContainsPoo()
{
    int i;

    for (i = 0; i < WIDTH; i++)
    {
        if ((poo[i].act) && (poo[i].y == 0) && (poo[i].x == player.x))
        {
            return TRUE;
        }
    }

    return FALSE;
}

void MovePlayer()
{
    if (isKeyDown(VK_LEFT))
        player.x -= 1;
    if (isKeyDown(VK_RIGHT))
        player.x += 1;

    if (player.x < 0)
        player.x = 0;
    if (player.x > WIDTH - 1)
        player.x = WIDTH - 1;
}

void PrintMap()
{
    system("cls");

    int i;

    for (i = 0; i < WIDTH; i++)
    {
        if (poo[i].act)
        {
            gotoxy(poo[i].x, HEIGHT - poo[i].y)y);
            printf("■");
        }
    }

    gotoxy(player.x, HEIGHT);
    printf("□");

    gotoxy(0, HEIGHT + 1);
    for (i = 0; i < WIDTH; i++)
        printf("▤");
}

void main()
{
    char key;

    init();

    do
    {
        srand((int)malloc(NULL));

        CreatePoo();
        MovePoo();
        DeletePoo();

        MovePlayer();

        PrintMap();

        Sleep(100);
    } } while (!(PlayerContainsPoo()));
}

c

2022-09-19 23:33

1 Answers

If you have poo and are falling from the sky,

poo[i].act is TRUE

As long as the poop has touched the floor and disappeared

poo[i].Act is FALSE

In the question, the init function is an initialization function It's a code that's initializing with all the poo gone.


2022-09-19 23:33

If you have any answers or tips


© 2022 pinfo. All rights reserved.