Registrierung Kalender Mitgliederliste Teammitglieder Suche Häufig gestellte Fragen Zur Startseite

Informatiker Board » Themengebiete » Praktische Informatik » Softwaretechnik » "Die Matrix" programmieren » Hallo Gast [Anmelden|Registrieren]
Letzter Beitrag | Erster ungelesener Beitrag Druckvorschau | An Freund senden | Thema zu Favoriten hinzufügen
Neues Thema erstellen Antwort erstellen
Zum Ende der Seite springen "Die Matrix" programmieren
Autor
Beitrag « Vorheriges Thema | Nächstes Thema »
MAC_BOSS
Grünschnabel


Dabei seit: 16.03.2010
Beiträge: 1

"Die Matrix" programmieren Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

Meine Frage:
Hi

Ich versuche schon seit einiger Zeit eine "Matrix"(Film!!, nichts mathematisches) in C++ zu programmieren. hab mir schon ein paar Videos dazu angesehen, aber die haben leider den Quellcode nicht mehr.

So sollte es in etwa dann aussehen:
www.youtube.com/watch?v=rkC8b9tJGh8

Mein Problem ist vor allem, das die Zeichen immer von links nach rechts und nicht von oben nach unten gezeichnet werden. (Es sieht im Video zumindest so aus.). Wie kann ich das verwirklichen



Vielen Dank im Voraus



Meine Ideen:
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <windows.h>

using namespace std;

int main(){
system("color 0A");
char* signs[5]={"10 10 1 1 1 1" ,"10 10 0 01 01", " 1 00 1 110101 1 1 11 0", "1 000 10 101000 001 111", "11 0 11 0"};
int i = 0;
while(1){
i = rand() % 5;
Sleep(50);
cout << signs[i] << '\t';
}
getch();
}

Dieser Beitrag wurde 4 mal editiert, zum letzten Mal von MAC_BOSS: 16.03.2010 20:27.

16.03.2010 19:04 MAC_BOSS ist offline E-Mail an MAC_BOSS senden Beiträge von MAC_BOSS suchen Nehmen Sie MAC_BOSS in Ihre Freundesliste auf
texelmax
Grünschnabel


Dabei seit: 12.11.2010
Beiträge: 1

RE: "Die Matrix" programmieren Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

Ich hätte da ne Idee:

#include <iostream>
#include <vector>
#include <windows.h>
#include <cstdio>
#include <algorithm>

using namespace std;

const int max_x = 80; //console width
const int max_y = 24; //console height
const int col1 = 10; //color code for higlighted char
const int col2 = 2; //color code for normal char
const int col3 = 0; //color code for background
const int c_min = 32; //char minimum ascii code
const int c_max = 126; //char maximum ascii code

const inline char rc(int m1, int m2) //random char
{
return (rand()%(m2-m1))+m1;
}

void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void setcol(int fore, int back)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), fore + back*16);
}

void clrscr()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };

hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;

/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;

/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;

/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;

/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}

void At(char chr, int x, int y) //print char at x-y pos in console
{
if (y>=0 && y<=max_y)
{
gotoxy(x,y);
printf("%c",chr);
}
}

class FallChar //falling char
{
public:
int X, Y;
char code;
int speed;
FallChar();
};

FallChar::FallChar()
{
X=rand()%max_x;
Y=0;
code=rc(c_min,c_max);
speed=rand()%3+1;
}

int main()
{
vector<FallChar> chars;
FallChar* cchar;

while (1)
{
chars.push_back(FallChar());
chars.push_back(FallChar());
chars.push_back(FallChar());
random_shuffle(chars.begin(), chars.end()); //shuffle to make flashing more equally distributed
for (int i=0; i<chars.size(); i++)
{
cchar = &chars[i];
if (cchar->Y!=max_y+4)
{
setcol(col1,col3);
At(cchar->code, cchar->X, cchar->Y);
At(rc(c_min,c_max), cchar->X, cchar->Y-1);
setcol(col2,col3);
At(rc(c_min,c_max), cchar->X, cchar->Y-2);
At(rc(c_min,c_max), cchar->X, cchar->Y-3);
At(rc(c_min,c_max), cchar->X, cchar->Y-4);
cchar->Y+=cchar->speed;
}
else
{
chars.erase(chars.begin()+i);
i--;
}
}
Sleep(30);
clrscr();
}
return 0;
}
12.11.2010 10:59 texelmax ist offline Beiträge von texelmax suchen Nehmen Sie texelmax in Ihre Freundesliste auf
KjubE
Grünschnabel


images/avatars/avatar-47.jpg

Dabei seit: 11.01.2011
Beiträge: 3

Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

Ich kenne mich mit c++ leider nicht aus. Aber in C# würde der Quellcode so aussehen:

#
using System;
#

#
namespace m7tr1x
#
{
#
class Program
#
{
#
static void Main(string[ ] args)
#
{
#
Console.Title = "tH3 M7tr1x 3ff3<t";
#
Console.ForegroundColor = ConsoleColor.DarkGreen;
#
Console.WindowLeft = Console.WindowTop = 0;
#
Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
#
Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
#
#if readkey
#
Console.WriteLine("H1T 7NY K3Y T0 C0NT1NU3 =/");
#
Console.ReadKey();
#
#endif
#
Console.CursorVisible = false;
#
int width, height;
#
int[ ] y;
#
int[ ] l;
#
Initialize(out width, out height, out y, out l);
#
int ms;
#
while ( true )
#
{
#
DateTime t1 = DateTime.Now;
#
MatrixStep(width, height, y, l);
#
ms = 10 - (int)( (TimeSpan)( DateTime.Now - t1 ) ).TotalMilliseconds;
#
if ( ms > 0 )
#
System.Threading.Thread.Sleep(ms);
#
if ( Console.KeyAvailable )
#
if ( Console.ReadKey().Key == ConsoleKey.F5 )
#
Initialize(out width, out height, out y, out l);
#
}
#
}
#

#
static bool thistime = false;
#

#
private static void MatrixStep(int width, int height, int[ ] y, int[ ] l)
#
{
#
int x;
#
thistime = !thistime;
#
for ( x = 0 ; x < width ; ++x )
#
{
#
if ( x % 11 == 10 )
#
{
#
if ( !thistime )
#
continue;
#
Console.ForegroundColor = ConsoleColor.White;
#
}
#
else
#
{
#
Console.ForegroundColor = ConsoleColor.DarkGreen;
#
Console.SetCursorPosition(x, inBoxY(y[x] - 2 - ( l[x] / 40 * 2 ), height));
#
Console.Write(R);
#
Console.ForegroundColor = ConsoleColor.Green;
#
}
#
Console.SetCursorPosition(x, y[x]);
#
Console.Write(R);
#
y[x] = inBoxY(y[x] + 1, height);
#
Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height));
#
Console.Write(' ');
#
}
#
}
#

#
private static void Initialize(out int width, out int height, out int[ ] y, out int[ ] l)
#
{
#
int h1;
#
int h2 = ( h1 = ( height = Console.WindowHeight ) / 2 ) / 2;
#
width = Console.WindowWidth - 1;
#
y = new int[width];
#
l = new int[width];
#
int x;
#
Console.Clear();
#
for ( x = 0 ; x < width ; ++x )
#
{
#
y[x] = r.Next(height);
#
l[x] = r.Next(h2 * ( ( x % 11 != 10 ) ? 2 : 1 ), h1 * ( ( x % 11 != 10 ) ? 2 : 1 ));
#
}
#
}
#

#
static Random r = new Random();
#
static char R
#
{
#
get
#
{
#
int t = r.Next(10);
#
if ( t <= 2 )
#
return (char)( '0' + r.Next(10) );
#
else if ( t <= 4 )
#
return (char)( 'a' + r.Next(27) );
#
else if ( t <= 6 )
#
return (char)( 'A' + r.Next(27) );
#
else
#
return (char)( r.Next(32, 255) );
#
}
#
}
#

#
public static int inBoxY(int n, int height)
#
{
#
n = n % height;
#
if ( n < 0 )
#
return n + height;
#
else
#
return n;
#
}
#
}
#
}
11.01.2011 09:57 KjubE ist offline Beiträge von KjubE suchen Nehmen Sie KjubE in Ihre Freundesliste auf
Blackarro Blackarro ist männlich
Eroberer


images/avatars/avatar-44.jpg

Dabei seit: 02.01.2011
Beiträge: 62
Herkunft: Deutschland

RE: "Die Matrix" programmieren Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

Hier stand mal was...

//Edit 3FBN: Schön von http://www.c-plusplus.de/forum/p1759315#1759315 kopiert -.-
11.01.2011 19:42 Blackarro ist offline Homepage von Blackarro Beiträge von Blackarro suchen Nehmen Sie Blackarro in Ihre Freundesliste auf Fügen Sie Blackarro in Ihre Kontaktliste ein AIM-Name von Blackarro: - YIM-Name von Blackarro: - MSN Passport-Profil von Blackarro anzeigen
Ibn Batuta Ibn Batuta ist männlich
Mitglied


images/avatars/avatar-45.jpg

Dabei seit: 02.01.2011
Beiträge: 26

Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

Was soll dein Code bringen, Blackarro? Das hat ja nichts mit dem Thema zu tun.


Ibn Batuta
11.01.2011 22:12 Ibn Batuta ist offline Beiträge von Ibn Batuta suchen Nehmen Sie Ibn Batuta in Ihre Freundesliste auf Fügen Sie Ibn Batuta in Ihre Kontaktliste ein
Baumstruktur | Brettstruktur
Gehe zu:
Neues Thema erstellen Antwort erstellen
Informatiker Board » Themengebiete » Praktische Informatik » Softwaretechnik » "Die Matrix" programmieren