Opening Sequence

This is a discussion on Opening Sequence within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <windows.h> #include <conio.h> #include <fstream.h> #include <stdio.h> #include <time.h> void fullscreen() { keybd_event(VK_MENU,0x38,0,0); keybd_event(VK_RETURN,0x1c,0,0); keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0); keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0); ...

  1. #1
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    Opening Sequence

    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    #include <fstream.h>
    #include <stdio.h>
    #include <time.h>
    void fullscreen()
    {
    keybd_event(VK_MENU,0x38,0,0);
    keybd_event(VK_RETURN,0x1c,0,0);
    keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
    keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0);
    }
    void clrscr()
    {
        COORD                       coordScreen = { 0, 0 };
        DWORD                       cCharsWritten;
        CONSOLE_SCREEN_BUFFER_INFO  csbi;
        DWORD                       dwConSize;
        HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        FillConsoleOutputCharacter(hConsole, TEXT(' '), 
                                   dwConSize, coordScreen, &cCharsWritten);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        FillConsoleOutputAttribute(hConsole, csbi.wAttributes, 
                                   dwConSize, coordScreen, &cCharsWritten);
        SetConsoleCursorPosition(hConsole, coordScreen);
    }
    void pos( int X, int Y)
    {
         HANDLE OutputH;
         COORD position = {X, Y};
         OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleCursorPosition(OutputH, position);
    }
    int title(int a[],int b[])
    {
    	int c=0;
    	ifstream fin;
        fin.open("Title.txt");
        if (fin.fail())
            {
                cprintf("The title File couldn't be opened");
                return 0;
            }
    
        while (c!=66)
            {
                    fin>>a[c]>>b[c];
    				c++;
            }
    	fin.close();
    	return 0;
    }
    
    bool check(int v[])
    {
            int a=0;
            while (a!=28)
            {
                    if (v[a]!=0)
                    {
                            return false;
                    }
                    a++;
            }
            return true;
    }
    bool che(int m,int n,int a[],int b[])
    {
    	m=m-24;
    	n=n-8;
    
    	if (m>28 || n>5 || m<1 || n<1)
    		return false;
    	int c=0;
    	while (c!=67)
    	{
    		if (m==a[c] && n==b[c])
    			return true;
    		c++;
    	}
    	return false;
    }
    void main()
    {
    	int v[27],a[66],b[66];
            HANDLE OutputH;
    		fullscreen();
    		Sleep(3000);
            clrscr();
            srand(time(0));
            int m,n,z=0,c=0,d,x=0,y=0,x1=80,x2=-1,y1=24,y2=0;
    		pos(56,24);
    		cprintf("Created by: Alex Hanson");
            while (y1 > y2 )
            {
    
                    while (x!=x1)
                    {
                            pos(x,y);
                            cprintf("@");
                            x++;
    						Sleep(3);
                    }
                    x--;
                    while (y!=y1)
                    {
                            pos(x,y);
                            cprintf("@");
                            y++;
    						Sleep(3);
                    }
                    y--;
                    while (x!=x2)
                    {
                            pos(x,y);
                            cprintf("@");
                            x--;
    						Sleep(3);
                    }
                    x++;
                    while (y!=y2)
                    {
                            pos(x,y);
                            cprintf("@");
                            y--;
    						Sleep(3);
                    }
                    y++;            
                    y1--;
                    x1--;
                    x2++;
                    y2++;
            }
            while (v[z]<28)
            {
                    v[z]=1;
                    z++;
            }
    		title(a,b);
            c=0;
            while (c != 66)
            {
                    d=rand()%66;
                    if (a[d] != 0)
                    {
                            pos(a[d]+24,b[d]+8); 
                            OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
                            SetConsoleTextAttribute(OutputH, FOREGROUND_BLUE);
                            printf("@");
                            c++;
                            Sleep(7);
                            a[d]=0;
                    }
    
            }
            Sleep(1000);
            bool held;
            held=check(v);
            while ( held==false)
            {
                    m=rand()%28+25;
                    while (v[m-25]!=0)
                    {
                            n=22;
                            while (n!=-1)
                            {
                                    pos(m,n);
                                    SetConsoleTextAttribute(OutputH, FOREGROUND_GREEN);
                                    printf("@");
                                    Sleep(25);
                                    pos(m,n+1);
    								SetConsoleTextAttribute(OutputH, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
                                    cprintf("@");
                                    pos(78,24);
                                    n--;
                            }
                            pos(m,n+1);
                            cprintf("@");
                            v[m-25]=0;
                    }
                    held=check(v);
            }
            m=79;
            n=24;
    		title(a,b);
            int p=79;
            bool ch;
            while ( m!=0 || n !=0)
            {
                    ch=che(m,n,a,b);
                    if (ch==false)
                    {
                            pos(m,n);
                            cprintf(" ");
                    }
                    m++;
                    n--;
                    if (m==80)
                    {
                            p--;
                            m=p;
                            n=23;
                    }
                    if (n==-1)
                    {
                            p--;
                            if (p<0)
                            {
                                    n=p+23;
                                    m=0;
                            }
                            else
                            {               
                                    n=23;           
                                    m=p;                   
                            }
                    }
    
            }
    		pos(m,n);
    		cprintf(" ");
    		Sleep(1000);
    		c=0;
    		while (c != 66)
            {
                    d=rand()%66;
                    if (a[d] != 0)
                    {
                            pos(a[d]+24,b[d]+8); 
                            printf(" ");
                            c++;
                            Sleep(7);
                            a[d]=0;
                    }
    
            }
    
            pos(0,0);
            cprintf(" ");
    		clrscr();
            pos(78,24);
            Sleep(4000);
    }
    i dont know what is wrong with my code i'm using a vc++ 6.0 compiler and the program compiles but when its running and it comes to that last sleep command it does it then freezes kind of windows kills the programm and gives me an error.

    basically all i'm asking is y?


    It's / not \ in the tags!
    Style is overrated.

    - ₽ -

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    are you sure it gets down to that last Sleep()? the problem you described brings back memories of inifinite loops, actually...


    Odds and Ends:
    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    #include <fstream.h>
    #include <stdio.h>
    #include <time.h>
    should be:
    Code:
    #include <iostream>
    #include <windows>
    #include <conio.h>
    #include <fstream>
    #include <cstdio>
    #include <ctime>
    
    using namespace std;
    I wouldn't use the sleep function... just create your own using the <ctime> functions... like one of these

    and:
    Code:
    void main()
    don't do that... use:
    Code:
    int main(int argc,char**argv) {...}  //for command-line arguments
    /* or */
    int main() {...} //if your not planning on using command-line arguments
    Last edited by major_small; 03-05-2004 at 01:21 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    It worked for me. I did notice one thing:
    > int v[27]

    This should be:
    int v[28]

    Either that or change the below code to while (a!=27):
    Code:
    bool check(int v[])
    {
            int a=0;
            while (a!=28)
            {
                    if (v[a]!=0)
                    {
                            return false;
                    }
                    a++;
            }
            return true;
    If you're still having trouble, perhaps post a copy of this file:
    fin.open("Title.txt");

    And as major_small pointed out, don't use:
    void main()

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
            while (c != 66)
            {
                    d=rand()%66;
                    if (a[d] != 0)
                    {
                            pos(a[d]+24,b[d]+8); 
                            OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
    This line:
    OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
    should be moved outside the while () loop, in case it never gets inside the loop. Either move it to the beginning of the loop, or you could put it at the beginning of main().
    Code:
    	int v[27],a[66],b[66];
    	HANDLE OutputH = GetStdHandle(STD_OUTPUT_HANDLE);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 11:52 AM
  2. sequence
    By braddy in forum C Programming
    Replies: 2
    Last Post: 03-30-2006, 01:15 PM
  3. Opening Multiple Files in sequence
    By wujiajun in forum C++ Programming
    Replies: 7
    Last Post: 01-16-2006, 07:47 PM
  4. wsprintf and format specifiers
    By incognito in forum Windows Programming
    Replies: 2
    Last Post: 01-03-2004, 09:00 PM
  5. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21