C++ Arrays: Electronic Billboard Imitation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • inihility
    New Member
    • Jun 2007
    • 18

    C++ Arrays: Electronic Billboard Imitation

    Let me state first off that this is not a school assignment, its something I thought that would be nice to do and well I ended up with the idea of using arrays to perform the task (if possible).

    I've done a cast-based animation with a static int, and bool, which works, however is limited to one line (prove me wrong, I'm still new to this).

    This is what I have so far, in terms of the function that animates the 'billboard':

    Code:
    void animateBoard()
    {
    	//for (int x = 0; x < 20; x++)
    	//{
    
    	for (int i = 0; i < 20; i++)
    	{
    		for (int j = 0; j < 20; j++)
    		{
    			for (int k = 0; k < 20; k++)
    			{
    				myArray[k][i] = myDisplay[k][19-i];
    				//myArray[19-k][j-19-i] = '_';
    			}
    			for (int l = 0; l < 20; l++)
    			{
    				myArray[l][i-j] = myDisplay[l][19-i];
    			}
    			displayBoard();
    			Sleep(250);
    			system("cls");
    		}
    
    	/*
    	int x, y, i, j;
    	y = 19;
    	for (i = 0; i < 20; i++)
    	{
    		x = 19;
    		for (j = 0; j < 20; j++)
    		{
    			myArray[j][i] = myDisplay[x][y];
    			x--;
    		}
    		y--;
    		Sleep(250);
    		system("cls");
    		displayBoard();
    
    		//for (x = 0; x <= i; x++)
    		//{
    		//	for (y = 0; y <= j; y++)
    		//	{
    		//		myArray[y][x] = '_';
    		//	}
    			//Sleep(220);
    			//system("cls");
    			//displayBoard();
    		//}
    	}
    	*/
    
    	}
    }
    I have two, two-dimensional arrays, and I am using a recursion function (several nested) to change their values.

    As you can see I've tried a lot of methods that I have commented out and most just deleted (the current version does something bizzarre). The problem I am having is that its not giving me any error instead it doesn't print the desired results. I've had it do what I wanted (in a sense) diagonally, however printing in a non-chronological order.

    I'm trying to imitate a common advertising electronic billboard you see everywhere that shuffles a message (or picture) across the screen or perform some sort of animation.

    I'm quite confident its possible to do this in C++ while it may be tedious, I hope someone can help me out here.

    Thanks.
  • inihility
    New Member
    • Jun 2007
    • 18

    #2
    I forgot to add that in the code provided, it is based on the already mentioned two, two dimensional arrays of the size 20 (thus the i < 20, etc. conditions).

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      When you cast in C++, you destroy the type safety of your program. Casting in C++ is used when a) you are calling a relic C function with a void* argument or b) your C++ design is screwed up.

      The code I see here is C code.

      Then there's this:
      Originally posted by nihility
      I'm trying to imitate a common advertising electronic billboard you see everywhere that shuffles a message (or picture) across the screen or perform some sort of animation.
      This looks like a base class ElectronicBillb oard Crawler data member.
      [code=cpp]
      class ElectronicBillb oard
      {
      private:
      Crawler c;
      };
      [/code]

      The Crawler is a base class with a virtual Crawl() method. So you derive a CrawlingPicture class from Crawler and override the Crawl() method. CrawlingPicture IS-A Crawler.

      The ElectronicBillb oard has a Display() method and part of that method is to display the crawler.

      [code=cpp]
      void ElectronicBillb oard::Display()
      {
      //displays the main board here
      while(etc...)
      {
      this->c->Crawl()//displays the crawler
      }
      }
      [/code]

      You create CrawlingPicture object and use it as a Crawler object.

      [code=cpp]
      CrawlingPicture cp("c:\\thepict ure.jpg");
      ElectronicBillb oard b("the text of the top of the board", cp);
      b.Display(); //shows the text of the billboard with the picture crawling across the bottom.
      [/code]

      You just add derived classes from Crawl for the various crawlers.

      Comment

      • inihility
        New Member
        • Jun 2007
        • 18

        #4
        Thanks for the reply weaknessforcats . Could you perhaps put together a small example of a 3(?) line message/characters running across the screen? I'm pretty new to C++ (at the really beginning of OOP) like I mentioned earlier and I'm having a little trouble trying to understand all the code snippets, what they do, and where they should be put, so it would be really helpful if you could use the Crawler (class?) in an example, that way I could probably analyse the example and have a better understanding of how things work.

        Also when I mentioned cast-based animation, I mean't that I did it before to clear things up, and not in this example as I was only able to animate one line at a time at most (I'm trying to simultaneously animate several lines).

        Many thanks.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Here you go:
          [code=cpp]
          #include <windows.h>
          #include <iostream>
          using namespace std;
          #include <string>

          class Crawler
          {
          public:
          virtual ostream& Crawl(ostream& os) = 0;
          };

          class TextCrawler : public Crawler
          {
          private:
          string text;
          public:
          TextCrawler(str ing str);
          ostream& Crawl(ostream& os);


          };
          TextCrawler::Te xtCrawler(strin g str)
          : text(str)
          {

          }
          ostream& TextCrawler::Cr awl(ostream& os)
          {
          string spaces;
          for (int i = 0; i < 3; ++i)
          {
          for (int i = 0; 60 > spaces.size(); ++i)
          {
          os << '\r' << spaces << text;
          spaces += " ";
          Sleep(500);
          }
          spaces += " ";
          os << '\r' << spaces;
          spaces.erase();
          }
          return os;
          }
          class ElectronicBillB oard
          {
          private:
          Crawler* c;
          string str; //the billboard text
          public:
          ElectronicBillB oard(string text, Crawler* thecrawler);
          //Display the billboard:
          friend ostream& operator<<(ostr eam& os, const ElectronicBillB oard& bb);
          };
          ElectronicBillB oard::Electroni cBillBoard(stri ng text, Crawler* thecrawler)
          : str(text), c(thecrawler)
          {
          }
          ostream& operator<<(ostr eam& os, const ElectronicBillB oard& bb)
          {
          string str(" ");
          os << str << bb.str << endl << endl << endl;
          bb.c->Crawl(os);
          return os;
          }

          int main()
          { Crawler* crawler = new TextCrawler("Bu y today");
          ElectronicBillB oard billboard("Used cars cheap", crawler);

          cout << billboard << endl;
          }
          [/code]

          Comment

          Working...