-
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!
-
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: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
-
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()
-
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);