2010-08-14 3 views
0
////////////////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; 
} 
+1

가장 먼저해야 할 일은 모든 1 자의 변수 이름을 더 명쾌하게 설명하는 것입니다. 두 번째는 모든 정수 리터럴을 명명 된 리터럴 상수로 대체하는 것입니다. –

+0

알고리즘의 목표는 무엇입니까? – Tom

+0

더 구체적인 방법이 필요합니다. 무슨 의견을 묻고 있니? 엄청난 양의 코드를 게시하는 것은 도움이되지 않습니다. 특히 많은 코드가 의도적으로 난독 화 된 것처럼 보이면 "당신의 의견은 무엇입니까?" –

답변

0

내 의견 : 멋지 네요! :) 비록 내가 알기 론, 이것은 여전히 ​​당신을위한 연습 프로그램입니다.

+0

당신은 그것을 이해합니까? : 0 –

+0

특히 첫 번째 줄 ('//'로 시작하는 줄). 그러나 그가 말했듯이,이 프로그램은 연습 프로그램이며 나는 레벨이 주어지면 완벽하다고 생각합니다. 아, 거의 잊어 버렸고, 나는 또한'#include'줄이하는 일을 이해한다. – thelost

+0

혜성 뱀 부분을 이해하셨습니까?!? 당신은 기괴한 마음 독자 같은 존재 여야합니다. –

2

아마도 오류 처리를 원할 것입니다. 호출중인 다양한 win32 API의 반환 값을 확인하십시오. CreateWindow와 같은 함수는 실패 할 수 있습니다.

또한 (앞서 주관적인 개인 의견),

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

대신

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

서면으로 고려하고, 그 값을 대체하는 대신 플래그를 사용합니다. 예 : 고려 쓰기 :

ShowWindow(GetForegroundWindow(),SW_SHOWNORMAL); 

대신

ShowWindow(GetForegroundWindow(),1); 

더 나은 변수 이름

의.

int D = 100; 

무엇입니까? 이상적으로 이름을보고 변수가 무엇을 나타내는 지 알아낼 수 있어야합니다.

마지막으로 전체 코드에서 일관되게 들여 쓰기하십시오.

+0

와우, 너 정말 그걸 쐈어. +1 –

+0

@ 메린 아무것도 할 :) – obelix

관련 문제