Jump to content

Recommended Posts

Posted

[C++] The "Matrix" in C++ (Win32 Console)

 

 

 

main.cpp

(cpp):
#include <iostream>
#include <vector>

#include "Matrix.h"

int main() {

    RemoveCursor();

    // Set the console title and double the consoles height
    #if (_WIN32_WINNT == _WIN32_WINNT_WINXP)
        if (!SetConsoleTitle("Matrix - Win32 Console")) {
            std::cout << "SetConsoleTitle returned an error: " << GetLastError();
        }

        SMALL_RECT windowSize = { 0, 0, 79, 49 };
        if (!SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &windowSize)) {
            std::cout << "SetConsoleWindowInfo returned an error: " << GetLastError();
        }
    #else
        // Windows Vista/7 have disabled FULL SCREEN
        ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
    #endif


    std::vector<Matrix>matrix;
/*
    matrix.push_back(Matrix(0, 0, 5, 15));
    matrix.push_back(Matrix(65, 0, 5, 15));
    matrix.push_back(Matrix(0, 0, 5, 15));
    matrix.push_back(Matrix(65, 0, 5, 15));

    matrix.push_back(Matrix(0, 0, 5, 15));  matrix.back().setErase(true);
    matrix.push_back(Matrix(65, 0, 5, 15)); matrix.back().setErase(true);
    matrix.push_back(Matrix(0, 0, 5, 15));  matrix.back().setErase(true);
    matrix.push_back(Matrix(65, 0, 5, 15)); matrix.back().setErase(true);
*/

    for (int y = 0; y < 15; y++) {
        matrix.push_back(Matrix());
    }

    for (int z = 0; z < 5; z++) {
        matrix.push_back(Matrix()); matrix.at(z).setErase(true);
    }

    while (1) {
        Sleep(1);

        for (int x = 0; x < matrix.size(); x++) {
            matrix.at(x).display();
        }
    }

    return 0;
}

 

Matrix.cpp

 

(cpp):
#include "Matrix.h"

using std::cout;

Matrix::Matrix() {

    // The initial seed value of the object
    srand(static_cast<unsigned int>(getpid()) ^ static_cast<unsigned int>(clock()) ^ static_cast<unsigned int>(time(NULL)));

    // Default constructor (no arguments)
    setDefault(true);

    // Default state for 'matrix lines'
    setErase(false);

    // 80 wide, 25 tall
    setPosition((rand() % 80 + 0), (rand() % 22 + 0));

    // Based on position Y
    setLength((rand() % (getPosition().Y + 1) + 0));

    // Speed of each letter being displayed
    setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));

    // Time between each iteration of a new color
    loopWhite_ = GetTickCount();
    loopLgreen_ = GetTickCount();
    loopDgreen_ = GetTickCount();
    lenCnt_ = 0;
};

Matrix::Matrix(const SMALL_RECT box) {

    // The initial seed value of the object
    srand(static_cast<unsigned int>(getpid()) ^ static_cast<unsigned int>(clock()) ^ static_cast<unsigned int>(time(NULL)));

    // Copy the argument to class member attribute
    setMatrixBox(box);

    // Default constructor (no arguments)
    setDefault(false);

    // Default state for 'matrix lines'
    setErase(false);

    // 80 wide, 25 tall
    setPosition((rand() % getMatrixBox().Right + getMatrixBox().Left), (rand() % getMatrixBox().Bottom + getMatrixBox().Top));

    // Based on position Y
    setLength((rand() % (getPosition().Y + 1) + 0));

    // Speed of each letter being displayed
    setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));

    // Time between each iteration of a new color
    loopWhite_ = GetTickCount();
    loopLgreen_ = GetTickCount();
    loopDgreen_ = GetTickCount();
    lenCnt_ = 0;
};

Matrix::Matrix(const unsigned __int8 left, const unsigned __int8 top,
               const unsigned __int8 bottom, const unsigned __int8 right) {

    // The initial seed value of the object
    srand(static_cast<unsigned int>(getpid()) ^ static_cast<unsigned int>(clock()) ^ static_cast<unsigned int>(time(NULL)));

    // Copy the argument to class member attribute
    setMatrixBox(top, bottom, left, right);

    // Default constructor (no arguments)
    setDefault(false);

    // Default state for 'matrix lines'
    setErase(false);

    // 80 wide, 25 tall
    setPosition((rand() % getMatrixBox().Right + getMatrixBox().Left), (rand() % getMatrixBox().Bottom + getMatrixBox().Top));

    // Based on position Y
    setLength((rand() % (getPosition().Y + 1) + 0));

    // Speed of each letter being displayed
    setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));

    // Time between each iteration of a new color
    loopWhite_ = GetTickCount();
    loopLgreen_ = GetTickCount();
    loopDgreen_ = GetTickCount();
    lenCnt_ = 0;
};

void Matrix::randLength() {
    setLength((rand() % (getPosition().Y + 1) + 5));
}

void Matrix::randSpeed() {
    setSpeed((rand() % 50 + 50), (rand() % 100 + 100), (rand() % 150 + 150));
    //setSpeed(0);
}

 

 

Matrix.h

(cpp):
#pragma once

#include <time.h>
#include <process.h>
#include <iostream>

#include "TextControl.h"

class Matrix {
    private:
        bool isDefault_; // Flag to signal using default "0 to 80" width, and "0 to 25" height
        bool erase_; // Flag to signal erasing of text (black matrix lines)

        // Timers for each color (no alternative)
        unsigned __int32 loopWhite_;
        unsigned __int32 loopLgreen_;
        unsigned __int32 loopDgreen_;

        unsigned __int16 speed_[3]; // Delay between printing a new line
        unsigned __int8 length_; // Max. length before it quits
        unsigned __int8 lenCnt_; // Counter for length

        COORD position_; // Position on the console

        SMALL_RECT matrixBox_; // Box for the "Matrix" to be in

    public:
        Matrix::Matrix();
        Matrix::Matrix(const SMALL_RECT);
        Matrix::Matrix(const unsigned __int8, const unsigned __int8, const unsigned __int8, const unsigned __int8);

        void display();

        void setErase(const bool);
        bool getErase();

        void setSpeed(const unsigned __int16, const unsigned __int16, const unsigned __int16);
        unsigned __int16 getSpeed(const unsigned __int8);

    private:
        void randLength();
        void randSpeed();
        void randPos();

        void setDefault(const bool);
        bool getDefault();

        void setLength(const unsigned __int8);
        unsigned __int8 getLength();

        void setPosition(const COORD);
        void setPosition(const unsigned __int8, const unsigned __int8);
        COORD getPosition();

        void setMatrixBox(const SMALL_RECT);
        void setMatrixBox(const unsigned __int8, const unsigned __int8, const unsigned __int8, const unsigned __int8);
        SMALL_RECT getMatrixBox();
};

 

TextControl.cpp

(cpp):
#include "TextControl.h"

void RemoveCursor() {

    /* Remove the cursor (does not work in full screen) */
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO CursoInfo;
    CursoInfo.dwSize = 1;         /* The size of caret */
    CursoInfo.bVisible = false;   /* Caret is visible? */
    SetConsoleCursorInfo(hConsole, &CursoInfo);

    return;
}

void SetColor(const int foreground) {

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, foreground);

    return;
}

void PlaceCursor(const int x, const int y) {

    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    COORD PlaceCursorHere;
    PlaceCursorHere.X = x;
    PlaceCursorHere.Y = y;

    SetConsoleCursorPosition(hConsole, PlaceCursorHere);
    return;
}

 

 

TextControl.h

(cpp):
#pragma once

#include <windows.h>

enum COLORS {
    BLACK       = 0,
    DARK_BLUE   = 1,
    DARK_GREEN  = 2,
    TEAL        = 3,
    DARK_RED    = 4,
    DARK_PURPLE = 5,
    GOLD        = 6,
    GREY        = 7,
    DARK_WHITE  = 8,
    BLUE        = 9,
    GREEN       = 10,
    CYAN        = 11,
    RED         = 12,
    PURPLE      = 13,
    YELLOW      = 14,
    WHITE       = 15
};

void RemoveCursor();
void SetColor(const int);
void PlaceCursor(const int, const int);

 

 

 

by Lightness

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • NEW SEASON 2025     GRAND OPENING 31.01.2025 Dear players, we would like present you the new season of the L2Exoplanet server. The new server will be rate x10 with alot new updates & fixes. We promise you the best High Five server with big community and balanced economy. Our project consists team of enthusiasts who love Lineage 2 and we would like invite to this iconic game.     GRAND OPENING:  31.01.2025 at 20:00 GMT+1 BETA TEST:   24.01.2025    Client: High Five Rates: x10   Website: https://l2exoplanet.net Facebook: https://www.facebook.com/L2-Exoplanet-106811564103836 Discord: https://discord.gg/4fzhW7ZSPc      
    • NEW SEASON START 31.1.2025       GRAND OPENING:  31.01.2025 at 20:00 GMT+1 BETA TEST:   24.01.2025    Client: High Five Rates: x10   Website: https://l2exoplanet.net Facebook: https://www.facebook.com/L2-Exoplanet-106811564103836 Discord: https://discord.gg/4fzhW7ZSPc       Game Rates    Experience: x10  Skill Points: x10  Adena: x8  Drop: x8  Spoil: x8  Quest: x5  Raid Boss Drop: x5  Fame: x2  Epaulette: x8  Manor: x8  MW Craft Chance: 6%  Key-Matherial-Recepie: x16    Safe Enchant: +3  Maximum Enchant: +16  Normal Scroll Chance: 60%  Blessed Scroll Chance: 63%  Attribute Stone Chance: 50%  Attribute Crystal Chance: 30%      Game Settings    Multibox - 3 game clients per HWID  Autoloot  Autolearn Skills  NPC Buffer  Buff Slots (24+4/12)  Buff Duration (2h)  Olympiad Period 7days (new heroes appear every monday)  Seven Signs Period  Class Transfer for Adena  Max Sub-Class 3  Sub-Class Max Level 85  Essence Interface  Champions System  Vote Reward System  Dayli Reward System  PC Points Reward (500PC = 1 Donate Coin)      Epic Bosses Respawn Times     Queen Ant:  24 Hours +/- 4 Hours   Beleth: 2 Days +/- 8 Hours   Baium: 2 Days +/- 8 Hours   Antharas: 3 Days +/- 8 Hours   Valakas:  3 Days +/- 8 Hours     Instance Info     Normal Freya = 6 Players   Hard Freya = 12 Players   Frintezza = 6 Players   Zaken 83 Day = 6 Players   Zaken 60 Day = 6 Players   Zaken Nightly = 6 Players   Tiat = 6 Players   Beleth = 12 Players
    • i think u need edit server files side too... bcs for interlude missing cmd for this set
    • Hi. I'm trying to rewrite the Lineage 2 interlude interface so that the screen displays information that, for example, the “Curse Gloom” debuff has entered and that it displays what skill has been resisted (there is only general information). Is it possible to do this?
    • OPENING ON MARCH 21 AT 18:00 GMT+1 Airin Server — a journey from the classic Chronicle 1 to the epic Chronicle 5, followed by a world merge with the Teon server. We are creating a unique gaming experience where each era unfolds gradually. From your first steps to battles with epic bosses, from the importance of every equipment grade to the significance of every location. Progressive Chronicles — your journey through history. Limits: 1 client per person Rates: Epic drop chance: x1 Quest drop chance: x1 Raid drop chance: x2 Adena (dynamic): x3~ (x1 for high-level) EXP\SP: x2-x3 Drop chance: x2-x3 Spoil chance: x2-x3 Quests A-grade: x1-x3 Quests S-grade: x1-x2 Welcome to Elmorelab.com!
  • Topics

×
×
  • Create New...