tags:

views:

90

answers:

2
////////////////comet snake////////////////////////////////////
////////////////////////////////////////////////////////

//Compilator :Microsoft Visual C++
//
//Created by :Dani (Indonesia)
//My Email   :[email protected]
//My Graduate is Architech
//
/////This is still practice program for me/////////
/////so, many bugs are maybe found////////////////
///////////////////////////////////////////////////////


#include<windows.h>
#include<stdio.h>
#include<time.h>
#include<math.h>


struct tm *local(){
    time_t t;
    t = time(NULL);

    return localtime(&t);
}

const char *ClsName = "BitmapLoading";
const char *WndName = "Easy bitmaploading!";
MSG        Msg;
HWND       hWnd;
WNDCLASSEX WndClsEx;
HINSTANCE hInstance;


int main(void)
{
    GetSystemMenu(GetForegroundWindow(),1);
    ShowWindow(GetForegroundWindow(),1);
    int D=100;
    int m,n;

    MoveWindow(GetForegroundWindow(),0,0,0,0,1);
    MessageBox(GetForegroundWindow(), "To close the screen running, you can move the cursor on the program taskbar. Right click & then click close  ","Users Guide - lonely night rain",MB_ICONASTERISK);

    RegisterClassEx(&WndClsEx);
    // Create the window object
    hWnd = CreateWindow(ClsName,
              WndName,
              WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              GetForegroundWindow(),
              CreatePopupMenu(),
              hInstance,
              NULL);
    HDC hdc=GetDC(hWnd);

    for(m=0;m<=(local()->tm_hour*5)+local()->tm_min;m++)rand();//Random based on time

    char *Label="  ScreenMove.SoftEng2010 - Copyright 2020  ";

    int a[35],b[35],c[35],d[35],e=0;

        for(n=1;n<=21;n++){
            a[n]=(10+n)*n;
            b[n]=(10+n)*n;
            c[n]=1,d[n]=1;
        }

        do{
            for(n=1;n<=21;n++){
                if(a[n]+(6+n+n)<=740 && a[n]>=0 && c[n]==1)a[n]++;
                else{ a[n]--;c[n]=0; }

                if(a[n]<=0)c[n]=1;

                if(b[n]+(6+n+n)<=1000 && b[n]>=0 && d[n]==1)b[n]++;
                else{ b[n]--;d[n]=0; }

                if(b[n]<=0)d[n]=1;

                e++;
                if(e==4)e=0;
                RoundRect(hdc,b[n]+(2+n+n)+e,a[n]+(2+n+n)+e,b[n],a[n],b[n],a[n]);

                TextOut(hdc,360,10,Label,43);//TEXT
            }
            for(m=0;m<=D*4;m++)Rectangle(hdc,1300,0,1350,50);

            for(n=100;n>=0;n--)LineTo(hdc,rand()%1100,rand()%740);
            SetTextColor(hdc,rand());
        }while(1);

return 0;
}
A: 

My opinion: This looks great! :) Though, as I understood, this is still practice program for you.

thelost
So you understand it? :0
thyrgle
Especially the first lines (the ones starting with `//`). But as he said, this is a practice program and I think that's perfect given the level. Oh, almost forgot, I also understand what the `#include` lines do.
thelost
You understood the comet snake part?!? You must be like a freakin mind reader or something.
thyrgle
it seems so! don't tell me you got that too
thelost
+2  A: 

You probably want to do error handling - check the return values of the various win32 apis you are calling. Functions like CreateWindow can fail.

Also (subjective personal opinion ahead), consider writing

if(b[n]<=0)
    d[n]=1;

instead of

if(b[n]<=0)d[n]=1;

And, use the flags instead of substituting their values. e.g. consider writing:

ShowWindow(GetForegroundWindow(),SW_SHOWNORMAL);

instead of

ShowWindow(GetForegroundWindow(),1);

and better variable names.

int D = 100;

what is D? I should ideally be able to figure out what the variable represents by looking at the name.

And finally, indent consistently across your entire code.

obelix
Wow, you really gave it a shot. +1
Merlyn Morgan-Graham
@Merlyn nothing to do :)
obelix