Czy ktoś może stworzyć bombę która eksploduje po ustawionym czasie oraz może zostać stworzona przez gracza?

0

https://pastebin.com/W5J52A3K

// bomberman.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include "pch.h"
#include <windows.h>
#include <gl/gl.h>
#include "glut.h"
#include <math.h>
#include <iostream>
#include <time.h>
#define SIZE 19
using namespace std;
//Player
struct point {
int x;
int y;
}position;

struct bomb {
int x;
int y;
}posb;

typedef float point2[2];

int field[SIZE][SIZE];
int condition;
int TimeA;
int TimeB=(TimeA+10000);

//Bomb Right
int BR() {

int Bx;
int By;
TimeB = TimeA + 10000;
Bx = (position.x + 1);
By = position.y;

field[Bx][By] = 5;
if (TimeA < TimeB)
if(TimeA=TimeB){
    TimeA++;
    if (TimeA = TimeB) {

    if (field[Bx + 1][By] != 2)
        field[Bx + 1][By] = 0;

    if (field[Bx][By - 1] != 2)
        field[Bx][By - 1] = 0;

    if (field[Bx][By + 1] != 2)
        field[Bx][By + 1] = 0;

    if (field[Bx - 1][By] != 2)
        field[Bx - 1][By] = 0;

    field[Bx][By] = 0;

}
}
return 0;

}
//Bomb Left
int BL() {
int Bx;
int By;
TimeB = TimeA + 10000;
Bx = (position.x - 1);
By = (position.y);

field[Bx][By] = 5;

if (TimeA < TimeB) {
    TimeA++;
    if(TimeA=TimeB)
    {

        if (field[Bx + 1][By] != 2)
            field[Bx + 1][By] = 0;

        if (field[Bx][By - 1] != 2)
            field[Bx][By - 1] = 0;

        if (field[Bx][By + 1] != 2)
            field[Bx][By + 1] = 0;

        if (field[Bx - 1][By] != 2)
            field[Bx - 1][By] = 0;

        field[Bx][By] = 0;

    }
}
return 0;

}

//Bomb Up
int BUP() {
int Bx;
int By;
TimeB = TimeA + 10000;

Bx = position.x;
By = (position.y - 1);

field[Bx][By] = 5;

if (TimeA <= TimeB) {
    TimeA++;
    if (TimeA = TimeB) {

        if (field[Bx + 1][By] != 2)
            field[Bx + 1][By] = 0;

        if (field[Bx][By - 1] != 2)
            field[Bx][By - 1] = 0;

        if (field[Bx][By + 1] != 2)
            field[Bx][By + 1] = 0;

        if (field[Bx - 1][By] != 2)
            field[Bx - 1][By] = 0;

        field[Bx][By] = 0;

    }
}
return 0;

}

int BDWN() {
int Bx;
int By;
TimeB = (TimeA + 10000);

Bx = position.x;
By = (position.y + 1);

field[Bx][By] = 5;

if (TimeA <= TimeB) {
    TimeA++;
    if (TimeA = TimeB) {

        if (field[Bx][By + 1] != 2)
            field[Bx][By + 1] = 0;

        if (field[Bx + 1][By] != 2)
            field[Bx + 1][By] = 0;

        if (field[Bx - 1][By] != 2)
            field[Bx - 1][By] = 0;

        if (field[Bx][By - 1] != 2)
            field[Bx][By - 1] = 0;

        field[Bx][By] = 0;

    }
}
return 0;

}

void MyInit(void){
{
//The void color(filling/background)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//Spawning the character
position.x = 1;
position.y = 1;
//Condition/Movement
condition = 10;

TimeA = 0;
TimeA++;

}


//Setting the map
for (int i = 0; i < SIZE; ++i)
{
    for (int j = 0; j < SIZE; ++j)
    {
        if (i == position.x && j == position.y)
        {
            field[i][j] = 1;
        }
        else if (i == 0 || i == SIZE - 1 || j == 0 || j == SIZE - 1)
        {
            field[i][j] = 2;
        }
        else
        {
            field[i][j] = 0;
        }
        if (i == posb.x && j == posb.y)
        {
            field[i][j] = 5;
        }
    }
}

for (int i = 0; i < SIZE; i += 2)
{
    for (int j = 0; j < SIZE; j += 2)
    {
        if (i % 2 == 0)
        {
            field[i][j] = 2;
        }
    }
}

for (int i = 0; i < SIZE; ++i)
{
    for (int j = 0; j < SIZE; ++j)
    {
        if (field[i][j] == 0)
        {
            if (rand() > RAND_MAX / 100)
            {
                field[i][j] = 3;
            }
        }
    }
}

field[1][2] = 4; //Starting area(Right block of start-area)
field[2][1] = 4; //Starting area(Down block of start-area)

}

void tbomb(){
for (TimeA = 0; TimeA < 100; TimeA++) {
if (field[posb.x - 1][posb.y] != 2) { field[posb.x - 1][posb.y] = 0; }
if (field[posb.x + 1][posb.y] != 2) { field[posb.x + 1][posb.y] = 0; }
if (field[posb.x][posb.y - 1] != 2) { field[posb.x][posb.y - 1] = 0; }
if (field[posb.x][posb.y + 1] != 2) { field[posb.x][posb.y + 1] = 0; }
if (field[posb.x][posb.y] != 2) { field[posb.x][posb.y] = 0; }
}
}

void Run()
{
TimeA++;

//Movement
switch (condition)
{
case 0:
    if (position.x != 0) {
        if (field[position.x + 1][position.y] != 2 
            && field[position.x + 1][position.y] != 3 
            && field[position.x + 1][position.y] != 5 
            && field[position.x + 1][position.y] != field[posb.x][posb.y])
            {
            if (field[position.x][position.y] != field[posb.x][posb.y]) {
                field[position.x][position.y] = 0;
            }
            position.x++;
            field[position.x][position.y] = 1;
        }
    }

    condition = 10; // To stop the player

    break;

case 1:
    if (position.y != 0) {
        if (field[position.x][position.y + 1] != 2 
            && field[position.x][position.y + 1] != 3 
            && field[position.x][position.y + 1] != 5 
            && field[position.x][position.y + 1] != field[posb.x][posb.y])
            {
            if (field[position.x][position.y] != field[posb.x][posb.y]) {
                field[position.x][position.y] = 0;
            }
            position.y++;
            field[position.x][position.y] = 1;
            }
    }

    condition = 10;
    break;

case 2:
    if (position.x != 0) {
        if (field[position.x - 1][position.y] != 2 
            && field[position.x - 1][position.y] != 3 
            && field[position.x - 1][position.y] != 5
            && field[position.x - 1][position.y] != field[posb.x][posb.y]) 
            {
            if (field[position.x][position.y] != field[posb.x][posb.y]) {
                field[position.x][position.y] = 0;
            }
            position.x--;
            field[position.x][position.y] = 1;
        }
    }

    condition = 10;
    break;

case 3:
    if (position.y != 0) {
        if (field[position.x][position.y - 1] != 2 
            && field[position.x][position.y - 1] != 3 
            && field[position.x][position.y - 1] != 5
            && field[position.x][position.y - 1] != field[posb.x][posb.y]) {

            if (field[position.x][position.y] != field[posb.x][posb.y]) {
                field[position.x][position.y] = 0;
            }
            position.y--;
            field[position.x][position.y] = 1;
        }
    }

    condition = 10;
    break;

    //Bomb initiation on 'k' key
case 4:
    field[position.x][position.y] = field[posb.x][posb.y];
    tbomb();
    

    break;

case 5:
    if (field[position.x + 1][position.y] != 2 && field[position.x + 1][position.y] != 3 && field[position.x + 1][position.y] != 5)
        BR();
    break;

case 6:
    if (field[position.x - 1][position.y] != 2 && field[position.x - 1][position.y] != 3 && field[position.x - 1][position.y] != 5)
        BL();
    break;

case 7:
    if (field[position.x][position.y - 1] != 2 && field[position.x][position.y - 1] != 3 && field[position.x][position.y - 1] != 5)
        BUP();
    break;

case 8:
    if (field[position.x][position.y + 1] != 2 && field[position.x][position.y + 1] != 3 && field[position.x][position.y + 1] != 5)
        BDWN();
    break;

case 9:
    field[position.x][position.y] = 0;
    break;

default:
    break;
    }



    Sleep(1);
    glutPostRedisplay();
    }
        // The squares
    void square(point location, float cr, float cg, float cb)
    {
        point2 a = { -1.0f + 0.1f * location.x, 1.0f - 0.1f * location.y };
        point2 b = { -1.0f + 0.1f * location.x + 0.1f, 1.0f - 0.1f * location.y };
        point2 c = { -1.0f + 0.1f * location.x + 0.1f, 1.0f - 0.1f * location.y - 0.1f };
        point2 d = { -1.0f + 0.1f * location.x, 1.0f - 0.1f * location.y - 0.1f };
        glBegin(GL_QUADS);
        glColor3f(cr, cg, cb);
        glVertex2fv(a);
        glColor3f(cr, cg, cb);
        glVertex2fv(b);
        glColor3f(cr, cg, cb);
        glVertex2fv(c);
        glColor3f(cr, cg, cb);
        glVertex2fv(d);
        glEnd();
    }


        // The player's point
    void smallsquare(point location)
    {
        point2 a = { -1.0f + 0.1f * location.x + 0.05f, 1.0f - 0.2f * location.y - 0.05f };
        point2 b = { -1.0f + 0.1f * location.x + 0.1f - 0.05f, 1.0f - 0.1f * location.y - 0.05f };
        point2 c = { -1.0f + 0.1f * location.x + 0.1f - 0.05f, 1.0f - 0.1f * location.y - 0.1f + 0.05f };
        point2 d = { -1.0f + 0.1f * location.x + 0.05f, 1.0f - 0.1f * location.y - 0.1f + 0.05f };
        glColor3f(1.0f, 0.0f, 0.0f);
        glBegin(GL_QUADS);
        glVertex2fv(a);
        glVertex2fv(b);
        glVertex2fv(c);
        glVertex2fv(d);
        glEnd();
    }

    void RenderScene(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        point tmp;
        //Drawing the map
        for (int i = 0; i < SIZE; i++) {
            for (int j = 0; j < SIZE; j++) {
                tmp.x = i;
                tmp.y = j;
                if (field[i][j] == 0)
                    square(tmp, 1.0, 1.0, 1.0);
                if (field[i][j] == 1)
                    square(tmp, 1.0, 0.0, 0.0);
                if (field[i][j] == 2)
                    square(tmp, 0.0, 0.0, 1.0);
                if (field[i][j] == 3)
                    square(tmp, 0.0, 1.0, 1.0);
                if (field[i][j] == 4)
                    square(tmp, 1.0, 1.0, 1.0);
                if (field[i][j] == 5)
                    square(tmp, 1.0, 1.0, 1.0);
            }
        }
        //Drawing the player
        smallsquare(position);

        glutSwapBuffers();

    }

        //Inputkeys
    void keys(unsigned char key, int x, int y)
    {
        //Input movement keys
        if (key == 'w') condition = 3;
        if (key == 'a') condition = 2;
        if (key == 's') condition = 1;
        if (key == 'd') condition = 0;

        //Input keys creating the bomb

        if (key == 'k') condition = 4;//Bombonme
        if (key == 'l') condition = 5;//Bombonright
        if (key == 'j') condition = 6;//Bombonleft
        if (key == 'i') condition = 7;//Bombonup
        if (key == ',') condition = 8;//Bombondown
        if (key == 'x') condition = 9;//Cleanmespace


        RenderScene();
    }

    int main(void)
    {
        srand(time(0));
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(800, 800);
        // Initializing the Window size
        glutCreateWindow("Bomberman");
        // Naming the Window
        glutDisplayFunc(RenderScene);
        // RenderScene as a return function
        // (callback function).  It'll be ommited everytime when redrawing the window will be needed
        glutKeyboardFunc(keys);
        // Return function detecting the state of the keyboard
        glutIdleFunc(Run);
        MyInit();
        // Function MyInit() (defined above) executes every pre-settings before rendering
        glEnable(GL_DEPTH_TEST);
        // Enabling the machine to clean the invisible elements of the scene
        glutMainLoop();
        // Function initializes the core of the GLUT library
    }
0

Czyli w sumie czego nie umiesz zrobić? Umieścić bomby? Odczekać czasu? Wybuchnąć jej? Zadaj konkretne pytanie.

5

Chłopie. Zmień ten tytuł bo ci policja na hate wjedzie.

1 użytkowników online, w tym zalogowanych: 0, gości: 1