Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "windows.h"
  3. #include <conio.h>
  4. #include <time.h>
  5. #include <iostream>
  6.  
  7.  
  8. //ustawia kursor we wsp x  y
  9. void gotoxy(int x, int y){
  10.   COORD c;
  11.   c.X = x - 1;
  12.   c.Y = y - 1;
  13.   SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
  14. }
  15.  
  16.  
  17.  
  18. void SetColor(int color){
  19.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
  20. }
  21.  
  22. char Character(){
  23.     char tmp = rand()%3;
  24.     if ( tmp == 0 ) {
  25.             return ( rand() % 26 ) + 65; //65-90
  26.     }
  27.     else if( tmp == 1 ){
  28.         return ( rand() % 26 ) + 97; //97-122
  29.     }
  30.     else {
  31.         return ( rand() % 10 ) + 48; //48-57
  32.     }
  33. }
  34.  
  35. void Print(int j, int position){
  36.     SetColor(10);
  37.     if (position<26){
  38.         gotoxy(j, position);
  39.         std::cout<<Character();
  40.     }
  41.         if(position>1 &&  position<26 ){
  42.         SetColor(2);
  43.         gotoxy(j, position-1);
  44.         std::cout<<Character();
  45.     }
  46.     if(position>15 &&  position< (26+15) ){
  47.         gotoxy(j, position-15);
  48.         std::cout<<" ";
  49.     }
  50. }
  51.  
  52. void Matrix(){
  53.     int position[80];
  54.     for (int i = 0; i < 80; i ++){
  55.         position[i]=0;
  56.     }
  57.     int j;
  58.     int counter;
  59.     do{
  60.         counter=0;
  61.         j=rand()%80 + 1;
  62.         position[j]++;
  63.  
  64.         Print(j, position[j]);
  65.  
  66.         for(int i=0; i < 80; i ++){
  67.             if(position[i]>41){
  68.                counter++;
  69.             }
  70.         }
  71.                if (position[j]>12 && (j>34 && j < 45) ){
  72.             SetColor(10);
  73.             gotoxy(j, 13 );
  74.             switch (j){
  75.                 case 35: std::cout<<'D'; break;
  76.                 case 36: std::cout<<'a'; break;
  77.                 case 37: std::cout<<'w'; break;
  78.                 case 38: std::cout<<'i'; break;
  79.                 case 39: std::cout<<'d'; break;
  80.                 case 40: std::cout<<' '; break;
  81.                 case 41: std::cout<<'D'; break;
  82.                 case 42: std::cout<<'e'; break;
  83.                 case 43: std::cout<<'b'; break;
  84.                 case 44: std::cout<<'y'; break;
  85.             }
  86.         }
  87.         if(j%5==0)
  88.             Sleep(1);
  89.  
  90.  
  91.     }while (counter<79);
  92.  
  93.  
  94. }
  95.  
  96. int main(){
  97.  
  98.     srand(time(NULL));
  99.     char key;
  100.  
  101.     SetColor(10);
  102.     gotoxy(31, 13);
  103.     std::cout<<"Mlodszy programista C++";
  104.     Sleep(1000);
  105.     gotoxy(31, 13);
  106.     std::cout<<"                       ";
  107.  
  108.     Matrix();
  109.  
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement