"c++ how to falling numbers" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "c++ how to falling numbers" answered properly. Developers are finding an appropriate answer about c++ how to falling numbers related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like c++ how to falling numbers. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on c++ how to falling numbers. 

c++ how to falling numbers

By F3DF3D on Feb 11, 2021
#include <iostream>
#include <windows.h> 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
using namespace std;


#define KB_UP 72
#define KB_DOWN 80
#define KB_LEFT 75
#define KB_RIGHT 77
#define KB_ESCAPE 27
#define KB_F8 66


/* Variables*/

char screen_buffer[2000]={' '};
int y_coord[2000]={0};
int x=0, y=0,dy=0;
int XMAX=77;
int YMAX=23;
int KB_code=0;
bool QuitGame=false;
int platformX=35, platformY=23;

/* function prototypes*/

void gotoxy(int x, int y);
void clrscr(void);
void setcolor(WORD color); 
void simple_keyboard_input();  
void draw_falling_numbers();
void draw_platform();

/*  main  */

int main(void)
{
  /* generate random seed */
  srand ( time(NULL) );

  /* generate random number*/
  for(int i=0;i<XMAX;i++) y_coord[i]=   rand() % YMAX;

  while(!QuitGame)
  {
      /* simple keyboard input */
      simple_keyboard_input();

      /* draw falling numbers */
      draw_falling_numbers();

  }

  /* restore text color */
  setcolor(7);
  clrscr( );
  cout<<" \n";

  cout<<" \nPress any key to continue\n";
  cin.ignore();
  cin.get();

   return 0;
}

/* functions  */

void draw_falling_numbers()
{

    for(x=0;x<=XMAX;x++)
    {
        /* generate random number */
        int MatixNumber=rand() % 2 ;

        /* update falling number */
        y_coord[x]=y_coord[x]+1;

        if (y_coord[x]>YMAX) y_coord[x]=0;

        /* draw dark color */
        setcolor(2);
        gotoxy(x ,y_coord[x]-1); cout<<"  "<<MatixNumber<<"   ";

        /* draw light color */
        setcolor(10);
        gotoxy(x ,y_coord[x]); cout<<"  "<<MatixNumber<<"   ";
    }
    /* wait some milliseconds */
    Sleep(50);
    //clrscr( );
}


void draw_platform()
{
  setcolor(7);
 gotoxy(platformX ,platformY);cout<<"       ";

 gotoxy(platformX ,platformY);cout<<"ÜÜÜÜÜÜ";
 setcolor(7);
 Sleep(5);
}




void simple_keyboard_input()
{
    if (kbhit())
      {
            KB_code = getch();
            //cout<<"KB_code = "<<KB_code<<"\n";

            switch (KB_code)
            {

                case KB_ESCAPE:

                    QuitGame=true;

                break;

                case KB_LEFT:
                           //Do something
                    platformX=platformX-4;if(platformX<3) platformX=3;
                break;

                case KB_RIGHT:
                           //Do something     
                    platformX=platformX+4;if(platformX>74) platformX=74;
                break;

                case KB_UP:
                           //Do something                     
                break;

                case KB_DOWN:
                           //Do something                     
                break;

            }        

      }

}


void setcolor(WORD color)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
    return;
}


void gotoxy(int x, int y)
{
  static HANDLE hStdout = NULL;
  COORD coord;

  coord.X = x;
  coord.Y = y;

  if(!hStdout)
  {
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  }

  SetConsoleCursorPosition(hStdout,coord);
}


void clrscr(void)
{
  static HANDLE hStdout = NULL;      
  static CONSOLE_SCREEN_BUFFER_INFO csbi;
  const COORD startCoords = {0,0};   
  DWORD dummy;

  if(!hStdout)               
  {
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hStdout,&csbi);
  }

  FillConsoleOutputCharacter(hStdout,
                             ' ',
                             csbi.dwSize.X * csbi.dwSize.Y,
                             startCoords,
                             &dummy);    
  gotoxy(0,0);
}

Add Comment

1

All those coders who are working on the C++ based application and are stuck on c++ how to falling numbers can get a collection of related answers to their query. Programmers need to enter their query on c++ how to falling numbers related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c++ how to falling numbers for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of c++ how to falling numbers while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "c++ how to falling numbers". Visit this developer's friendly online web community, CodeProZone, and get your queries like c++ how to falling numbers resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "c++ how to falling numbers"

View All C++ queries

C++ queries related to "c++ how to falling numbers"

c++ how to falling numbers arduino falling edge Given the following declarations below. Write a loop to read a list of numbers from the keyboard terminated by -999 and store the even numbers (skip over the odd numbers) in the vector v. sum of 2 numbers in cpp c program to add two numbers c++ generate random numbers c++ find prime numbers sum of 2 numbers in cpp function making random numbers in c++ reversing numbers in C++ c++ generate random numbers in range c++ how to sort numbers in ascending order Add Two Numbers gcd of two numbers c++ c++ program for addition of two numbers using functions how to get a random number between two numbers in c++ find the biggest number from 3 numbers c++ c++ sum up numbers c++ display numbers as binary first prime numbers add two numbers in c++ random numbers c++ sum of two numbers c++ cpp program to find average of n numbers return odd numbers c++ for loop return odd numbers c++ c++ program to find gcd of 3 numbers first prime numbers less than max two numbers c++ c++ program to generate prime numbers how to use mersenne_twister_engine in c++ to generate random numbers print numbers after decimal point c++ c++ modulo make it give only positive numbers how to sort string containing numbers in c++ Sum of two large numbers in C++ Lucas numbers logarithmic functions with complex numbers in c/c++ kadane algorithm with negative numbers included as sum all trigonometric functions with complex numbers in c/c++ Find the two non-repeating elements in an array of repeating elements/ Unique Numbers 2 Read in three numbers, and calculate the sum. Output the sum as an integer. in c visual studio c++ sum of even and odd numbers how to add numbers in for loop c++ Create a program that finds the minimum value in these numbers how to print all numbers in an integer in c++ sum of n natural numbers in c how to substract two numbers to give positive outcome in c++ by the hep of pointers addition of two numbers in c add 2 numbers in c c code to add two numbers gcd of 2 numbers guessing game 3 numbers c++

Browse Other Code Languages

CodeProZone