Blue Theme Orange Theme Green Theme Red Theme
 
Mindcracker MVP Summit 2012
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » Visual C++ 6.0 » APPLE GAME

APPLE GAME

TAKE THE APPLE THIS GAME...

Page Views : 2813
Downloads : 90
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
sourceproject.zip
 
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction

In This Game: if you loss 8 red apples, and 8 yellow apples ,you are game over. If take 3 life all the loss apples is zero. and you want continue.

Example usage

we need 4 structurs for men , red apple, yellow apple and life. 

// use 4 structurs

struct Apple

{

     int  Xpos;

     int  Ypos;

     BOOL Falling;

}
Apple[1000];

struct snow

{

     int  Xpos;

     int  Ypos;

     BOOL Falling;

}
snow[1000];

struct life

{

     int  Xpos;

     int  Ypos;

     BOOL Falling;

}
life[1000];

struct men

{

     int  Xpos;

     int  Ypos;

     int  Frame;

     BOOL FacingLeft;

     BOOL FacingRight;

}
men;

Ok. Therefore load bitmap for men , apples and life.
   

HBITMAP fillbmp;

CClientDC pdc(this);

HDC MemoryDC;

fillbmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_1));

MemoryDC = CreateCompatibleDC(pdc);

SelectObject(MemoryDC, fillbmp);

if(men.FacingRight)

{

    switch(men.Frame)    // go men left ,right

    {

        case 0:

        BitBlt(pdc, men.Xpos, men.Ypos  , 32, 32, MemoryDC, 1, 34, SRCAND);

        BitBlt(pdc, men.Xpos, men.Ypos , 32, 32, MemoryDC, 1, 1, SRCPAINT);

        break;

        case 1:

        BitBlt(pdc,men.Xpos, men.Ypos  , 32, 32, MemoryDC, 34, 34, SRCAND);

        BitBlt(pdc, men.Xpos, men.Ypos , 32, 32, MemoryDC, 34, 1, SRCPAINT);

        break;

    }

}

if(men.FacingLeft)

{

    switch(men.Frame)

   {

       case 0:

       BitBlt(pdc, men.Xpos, men.Ypos, 32, 32, MemoryDC, 1, 100, SRCAND);

       BitBlt(pdc, men.Xpos, men.Ypos, 32, 32, MemoryDC, 1, 67, SRCPAINT);

       break;

       case 1:

       BitBlt(pdc, men.Xpos, men.Ypos, 32, 32, MemoryDC, 34, 100, SRCAND);

       BitBlt(pdc, men.Xpos, men.Ypos, 32, 32, MemoryDC, 34, 67, SRCPAINT);

       break;

   }

}

for(int i = 0; i < 500; i ++)    // falling apples

{

    if(Apple[i].Falling)

    {

        BitBlt(pdc, Apple[i].Xpos, Apple[i].Ypos, 32, 32, MemoryDC, 67, 34, SRCAND);

        BitBlt(pdc, Apple[i].Xpos, Apple[i].Ypos, 32, 32, MemoryDC, 67, 1, SRCPAINT);

    }

}

}


load the bitmap backgrouan, in the resource project,and draw on the dialog;

// calling background bitmap for draw the workspace.

HINSTANCE hi=NULL;

HBITMAP hbmp;

BITMAP bmp;

CClientDC pdc(this);

HDC hdc2 = CreateCompatibleDC(pdc);

hbmp = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_2));

GetObject(hbmp, sizeof(bmp),&bmp);

SelectObject(hdc2, hbmp);

BitBlt(pdc, 0, 0, bmp.bmWidth, bmp.bmHeight, hdc2, 50, 150, SRCCOPY); //draws the image

DeleteObject(hbmp);

DeleteDC(pdc);

DeleteDC(hdc2); 

// free DC

for runing this 4 structurs,we used Function timer();
for runing timer checking :run men,apples and life.

The Code

Collapse

if(losr>=8&&losy>=8){KillTimer(1);

{
    MessageBox("Oh Sorry ! You Loss " );
    exit(0);
}

GetWindowText(checklife);

CString str[]={"3","6","9","12","15","18","21","24","27","30"};

for(int q=0;q<=10;q++)
{

    if(checklife==str[q])
    {

         losy=-1;

         losr=-1;

         strtakelife="";SetWindowText(strtakelife);}

    }
if(checklife=="30")
{
    KillTimer(1);
    MessageBox("BRAVO !!!  You Win ");
    exit(0);
}

for(int j = 0; j < 500; j ++)
{
    InvalidateRect(0);
    if(snow[j].Falling)
    {

         snow[j].Ypos+=6;    //Checking yellow apples for falling in this Timer

         if(snow[j].Ypos >= 310)
         {
              losy++;

              char ah[10];

              itoa(losy,ah,10);
              strlosy=ah;

              snow[j].Falling = FALSE;

              snow[(j+ 1)].Falling = TRUE;
              InvalidateRect(0);

         }
    RECT RMen;

    RECT Rsnow;

    RECT RCalc1;

    SetRect(&RMen, men.Xpos, men.Ypos, men.Xpos + 32,men.Ypos + 32);

    SetRect(&Rsnow, snow[j].Xpos, snow[j].Ypos, snow[j].Xpos + 30,snow[j].Ypos+30); 

    IntersectRect(&RCalc1, &RMen, &Rsnow);

    if((RCalc1.right - RCalc1.left) >= 10 &&(RCalc1.right - RCalc1.left) <= 32)
    {

         takey++;

         char vh[10];

         itoa(takey,vh,10);strtakey=vh;

         snow[j].Falling = FALSE;

         InvalidateRect(0);

         snow[(j + 1)].Falling = TRUE;

     }
}

for(int k= 0; k < 500; k ++)
{
    InvalidateRect(0);
    if(life[k].Falling)
    {

         life[k].Ypos+=6;    // checcking life

         if(life[k].Ypos >= 310)
         {
              loselife++;

              char kh[10];

              itoa(loselife,kh,10);
              strloslife=kh;

              life[k].Falling = FALSE;

              InvalidateRect(0);

              life[(k+ 1)].Falling = TRUE;
              InvalidateRect(0);

         }
     RECT RMen;

     RECT Rlife;

     RECT RCalc2;

     SetRect(&RMen, men.Xpos, men.Ypos, men.Xpos + 32,men.Ypos + 32); 

     SetRect(&Rlife, life[k].Xpos, life[k].Ypos, life[k].Xpos + 30,life[k].Ypos + 30);

     IntersectRect(&RCalc2, &RMen, &Rlife);
}

THEREFORE, we created sample easy game by this.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mohammad Mirshahi

Hi!
I am mohammad mirshahi and I live in iran...
My Jobs : Windows Programer & Web Programer  
Visual C++ 6 , Visual C#.net , Asp.net 
PHP , Flash Script , SQL Server 2000 , SQL Server 2005 ,
And Afew Java & Linux Programing

Location Work : Semnan Science & Technology Park


Other My Project In Another Sites :
http://www.planet-source-code.com/vb/authors/ShowBio.asp?lngAuthorId=88512601397&lngWId=3

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Comments
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.