Help find the classes, how they are utilized and how many objects were created in this code provided by me Source is provided, mainmenu.cpp is the images. and mainmenu.h is also provided. Source.cpp #include #include "MainMenu.h" #include #include using namespace sf; int N = 30, M = 20; int size = 16; int w = size * N; int h = size * M; int dir, num = 4; struct Snake {     int x, y; }  s[100]; struct Fruit {     int x, y; } f; void Tick() {     for (int i = num;i > 0;--i)     {         s[i].x = s[i - 1].x; s[i].y = s[i - 1].y;     }     if (dir == 0) s[0].y += 1;     if (dir == 1) s[0].x -= 1;     if (dir == 2) s[0].x += 1;     if (dir == 3) s[0].y -= 1;     if ((s[0].x == f.x) && (s[0].y == f.y))     {         num++; f.x = rand() % N; f.y = rand() % M;     }     if (s[0].x > N) s[0].x = 0;  if (s[0].x < 0) s[0].x = N;     if (s[0].y > M) s[0].y = 0;  if (s[0].y < 0) s[0].y = M;     for (int i = 1;i < num;i++)         if (s[0].x == s[i].x && s[0].y == s[i].y)  num = i; } int main() {     sf::RenderWindow window(sf::VideoMode(1080, 720), "Snake");     MainMenu mainmenu(1080, 720);     Texture textureBackground;     textureBackground.loadFromFile("Snakebgs.png");     sf::Sprite spriteBackground;     spriteBackground.setTexture(textureBackground);     spriteBackground.setPosition(0, 0);     while (window.isOpen())     {         sf::Event event;         while (window.pollEvent(event))         {             if (event.type == sf::Event::Closed)                 window.close();             if (event.type == sf::Event::KeyReleased)             {                 if (event.key.code == sf::Keyboard::Up)                 {                     mainmenu.moveUp();                     break;                 }                 if (event.key.code == sf::Keyboard::Down)                 {                     mainmenu.moveDown();                     break;                 }                 if (event.key.code == sf::Keyboard::Return)                 {                     int x = mainmenu.mainMenuPressed();                     if (x == 1)                         return 0;                     if (x == 0)                         printf("Play Button was pressed\n");                     srand(time(0));                     sf::RenderWindow window(sf::VideoMode(w, h), "Snake");                     Texture t1, t2, t3;                     t1.loadFromFile("images/snakebg.png");                     t2.loadFromFile("images/red.png");                     t3.loadFromFile("images/green.png");                     Sprite sprite1(t1);                     Sprite sprite2(t2);                     Sprite sprite3(t3);                     Clock clock;                     float timer = 0, delay = 0.1;                     f.x = 10;                     f.y = 10;                     while (window.isOpen())                     {                         float time = clock.getElapsedTime().asSeconds();                         clock.restart();                         timer += time;                         Event e;                         while (window.pollEvent(e))                         {                             if (e.type == Event::Closed)                                 window.close();                         }                         if (Keyboard::isKeyPressed(Keyboard::Left)) dir = 1;                         if (Keyboard::isKeyPressed(Keyboard::Right)) dir = 2;                         if (Keyboard::isKeyPressed(Keyboard::Up)) dir = 3;                         if (Keyboard::isKeyPressed(Keyboard::Down)) dir = 0;                         if (timer > delay) { timer = 0; Tick(); }                         window.clear();                         for (int i = 0; i < N; i++)                             for (int j = 0; j < M; j++)                             {                                 sprite1.setPosition(i * size, j * size);  window.draw(sprite1);                             }                         for (int i = 0;i < num;i++)                         {                             sprite3.setPosition(s[i].x * size, s[i].y * size);  window.draw(sprite3);                         }                         sprite2.setPosition(f.x * size, f.y * size);  window.draw(sprite2);                         window.display();                     }                 }             }         }         window.clear();         window.draw(spriteBackground);         mainmenu.Draw(window);         window.display();     } } Main Menu.h #pragma once #include "SFML/Graphics.hpp" #include #define Max_main_menu 3 class MainMenu {     sf::Texture* image;     sf::Sprite* bg; public:     MainMenu(float width, float height);     void Draw(sf::RenderWindow& window);     void moveUp();     void moveDown();     int mainMenuPressed()     {         return mainMenuSelected;     }     ~MainMenu(); private:     int mainMenuSelected;     sf::Font font;     sf::Text mainMenu[Max_main_menu]; };

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Help find the classes, how they are utilized and how many objects were created in this code provided by me

Source is provided, mainmenu.cpp is the images. and mainmenu.h is also provided.

Source.cpp

#include <SFML/Graphics.hpp>
#include "MainMenu.h"
#include <time.h>
#include <SFML/Window.hpp>

using namespace sf;


int N = 30, M = 20;
int size = 16;
int w = size * N;
int h = size * M;

int dir, num = 4;

struct Snake
{
    int x, y;
}  s[100];

struct Fruit
{
    int x, y;
} f;

void Tick()
{
    for (int i = num;i > 0;--i)
    {
        s[i].x = s[i - 1].x; s[i].y = s[i - 1].y;
    }

    if (dir == 0) s[0].y += 1;
    if (dir == 1) s[0].x -= 1;
    if (dir == 2) s[0].x += 1;
    if (dir == 3) s[0].y -= 1;

    if ((s[0].x == f.x) && (s[0].y == f.y))
    {
        num++; f.x = rand() % N; f.y = rand() % M;
    }

    if (s[0].x > N) s[0].x = 0;  if (s[0].x < 0) s[0].x = N;
    if (s[0].y > M) s[0].y = 0;  if (s[0].y < 0) s[0].y = M;

    for (int i = 1;i < num;i++)
        if (s[0].x == s[i].x && s[0].y == s[i].y)  num = i;

}
int main()
{
    sf::RenderWindow window(sf::VideoMode(1080, 720), "Snake");
    MainMenu mainmenu(1080, 720);
    Texture textureBackground;

    textureBackground.loadFromFile("Snakebgs.png");
    sf::Sprite spriteBackground;

    spriteBackground.setTexture(textureBackground);
    spriteBackground.setPosition(0, 0);

    while (window.isOpen())

    {

        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (event.type == sf::Event::KeyReleased)
            {
                if (event.key.code == sf::Keyboard::Up)
                {
                    mainmenu.moveUp();
                    break;
                }
                if (event.key.code == sf::Keyboard::Down)
                {
                    mainmenu.moveDown();
                    break;
                }
                if (event.key.code == sf::Keyboard::Return)
                {
                    int x = mainmenu.mainMenuPressed();
                    if (x == 1)
                        return 0;
                    if (x == 0)
                        printf("Play Button was pressed\n");
                    srand(time(0));

                    sf::RenderWindow window(sf::VideoMode(w, h), "Snake");

                    Texture t1, t2, t3;
                    t1.loadFromFile("images/snakebg.png");
                    t2.loadFromFile("images/red.png");
                    t3.loadFromFile("images/green.png");

                    Sprite sprite1(t1);
                    Sprite sprite2(t2);
                    Sprite sprite3(t3);

                    Clock clock;
                    float timer = 0, delay = 0.1;

                    f.x = 10;
                    f.y = 10;

                    while (window.isOpen())
                    {
                        float time = clock.getElapsedTime().asSeconds();
                        clock.restart();
                        timer += time;

                        Event e;
                        while (window.pollEvent(e))
                        {
                            if (e.type == Event::Closed)
                                window.close();
                        }

                        if (Keyboard::isKeyPressed(Keyboard::Left)) dir = 1;
                        if (Keyboard::isKeyPressed(Keyboard::Right)) dir = 2;
                        if (Keyboard::isKeyPressed(Keyboard::Up)) dir = 3;
                        if (Keyboard::isKeyPressed(Keyboard::Down)) dir = 0;

                        if (timer > delay) { timer = 0; Tick(); }
                        window.clear();

                        for (int i = 0; i < N; i++)
                            for (int j = 0; j < M; j++)
                            {
                                sprite1.setPosition(i * size, j * size);  window.draw(sprite1);
                            }

                        for (int i = 0;i < num;i++)
                        {
                            sprite3.setPosition(s[i].x * size, s[i].y * size);  window.draw(sprite3);
                        }

                        sprite2.setPosition(f.x * size, f.y * size);  window.draw(sprite2);

                        window.display();
                    }

                }
            }
        }
        window.clear();
        window.draw(spriteBackground);
        mainmenu.Draw(window);
        window.display();


    }
}

Main Menu.h

#pragma once
#include "SFML/Graphics.hpp"
#include <iostream>
#define Max_main_menu 3
class MainMenu

{
    sf::Texture* image;
    sf::Sprite* bg;
public:
    MainMenu(float width, float height);

    void Draw(sf::RenderWindow& window);
    void moveUp();
    void moveDown();

    int mainMenuPressed()
    {
        return mainMenuSelected;
    }
    ~MainMenu();

private:
    int mainMenuSelected;
    sf::Font font;
    sf::Text mainMenu[Max_main_menu];
};

 

MainMenu::~MainMenu()
Evoid MainMenu::Draw(sf::RenderWindow& window)
for (int i = 0; i < 3; i++)
{
window.draw(dramable: MainMenu[i]);
void MainMenu::moveUp()
if (mainMenuSelected - 1 >= -1)
mainMenu[mainMenuSelected]. setFillColor(sf::Color::White);
mainMenuSelected--;
if (mainMenuSelected == -1)
{
mainMenuSelected = 1;
mainMenu[mainMenuSelected]. setFillColor(sf::Color::Cyan);
}
avoid MainMenu::moveDown()
if (mainMenuSelected + 1 <= Max_main_menu)
mainMenu[mainMenuSelected]. setFillColor(sf::Color: :White);
mainMenuSelected++;
if (mainMenuSelected == 2)
{
mainMenuSelected = 0;
mainMenu[mainMenuSelected]. setFillColor(sf::Color::Cyan);
}
Transcribed Image Text:MainMenu::~MainMenu() Evoid MainMenu::Draw(sf::RenderWindow& window) for (int i = 0; i < 3; i++) { window.draw(dramable: MainMenu[i]); void MainMenu::moveUp() if (mainMenuSelected - 1 >= -1) mainMenu[mainMenuSelected]. setFillColor(sf::Color::White); mainMenuSelected--; if (mainMenuSelected == -1) { mainMenuSelected = 1; mainMenu[mainMenuSelected]. setFillColor(sf::Color::Cyan); } avoid MainMenu::moveDown() if (mainMenuSelected + 1 <= Max_main_menu) mainMenu[mainMenuSelected]. setFillColor(sf::Color: :White); mainMenuSelected++; if (mainMenuSelected == 2) { mainMenuSelected = 0; mainMenu[mainMenuSelected]. setFillColor(sf::Color::Cyan); }
#include "MainMenu.h"
#include <SFML/Graphics.hpp>
EMainMenu::MainMenu(float width, float height)
{
if (!font.loadFromFile(filename: "pixel_azure_bonds.otf"))
printf(_Format: "Cannot load");
sf::Texture texturex;
if (!texturex. loadFromFile(filename: "Snakebgs.png"))
{
}
sf::Sprite background (texturex);
//play
mainMenu[0].setFont (font);
mainMenu[0].setFillColor(sf::Color: :Yellow);
mainMenu[0].setString(string: "PLAY");
mainMenu[0].setCharacterSize(size: 40);
mainMenu [0].setPosition (x: 500, y: 300);
mainMenuSelected = 0;
//Quit
mainMenu[1].setFont (font);
mainMenu[1].setFillColor(sf::Color::Yellow);
mainMenu[1].setString(string: "Quit");
mainMenu[1].setCharacterSize(size: 40);
mainMenu[1].setPosition (x: 500, y: 450);
mainMenuSelected = 0;
MainMenu::~MainMenu()
Evoid MainMenu::Draw(sf::RenderWindow& window)
for (int i = 0; i < 3; i++)
window.draw(dramable: MainMenu[i]);
Transcribed Image Text:#include "MainMenu.h" #include <SFML/Graphics.hpp> EMainMenu::MainMenu(float width, float height) { if (!font.loadFromFile(filename: "pixel_azure_bonds.otf")) printf(_Format: "Cannot load"); sf::Texture texturex; if (!texturex. loadFromFile(filename: "Snakebgs.png")) { } sf::Sprite background (texturex); //play mainMenu[0].setFont (font); mainMenu[0].setFillColor(sf::Color: :Yellow); mainMenu[0].setString(string: "PLAY"); mainMenu[0].setCharacterSize(size: 40); mainMenu [0].setPosition (x: 500, y: 300); mainMenuSelected = 0; //Quit mainMenu[1].setFont (font); mainMenu[1].setFillColor(sf::Color::Yellow); mainMenu[1].setString(string: "Quit"); mainMenu[1].setCharacterSize(size: 40); mainMenu[1].setPosition (x: 500, y: 450); mainMenuSelected = 0; MainMenu::~MainMenu() Evoid MainMenu::Draw(sf::RenderWindow& window) for (int i = 0; i < 3; i++) window.draw(dramable: MainMenu[i]);
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY