( Index )


Brief Information about the September 2015 CSIG Meeting

One Balloon - Advanced to VS2015 - A Simple Graphics Program/Game/Practice-Aid

by Bruce Arnold

(General Csig Info)    This month's application is a Microsoft C-sharp program that deals with logic and graphics. We will also be discussing the latest Microsoft free compiler Visual Studio 2015. This new software has many new industry features such as:

Visual Studio Community 2015
Framework .NET 4.6
Support for Windows, Linux, and Os X
DotNet Open Source on Github
Support for all phones
C# Version 6
Code syntax simplification like string formatting
Website: gethub.com/dotnet/roslyn
Universal Windows Apps: Phones, Tablets, Raspberry Pi, etc.

Catch Me!  

 Catch Me Flow  

Welcome to the CSIG, a Special Interest Group of the ACGNJ. This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs. (Some are FREE!)

Here's a brief synopsis of this month's meeting:

The original C++/cli program from Sept. 2012 had been recoded into a C-sharp program in November 2013.  I have now brought it up to date. Since Microsoft has just released Visual Studio 2015, this will be an opportunity to demonstrate the latest compiler. The Microsoft compilers utilize the same DOT NET libraries. Therefore, the algorithm as well as the code remains quite similar.

The object of this program is to create a Teaching Aid for students of Computer Literacy who have no mouse experience.  That's right: NO-MOUSE-EXPERIENCE. A few years ago I wrote a program called "Balloons" for that same purpose. About 75 percent of new computer users can work with that program and then move on to programs like "Solitaire" in order to develop the proper HAND-EYE coordination necessary to productively use a computer. The other 25 percent are left behind. This application is for them.

 As can be seen in the screen shot above, the program displays a colored circle on a colored background. Additionally, the circle or balloon has some text printed inside. When the user moves the mouse over to the balloon, it "runs away" from the mouse. The goal of the game is to click the mouse inside the balloon before it runs away.  (1 second delay.) If the user is successful, the balloon "explodes" and the counter is incremented. A new balloon then appears in another location.

 This program demonstrates several of the DOT NET graphics functions. The algorithm is created around a STATE MACHINE in order to control sequence.  Trigger events into the code include: [A] The mouse has a new position; [B] the mouse has been clicked; and [C] the timer elapsed. There are five states in the program State Machine. Some of the states are: "Outside_Balloon", "Inside_Balloon", "Balloon_Exploding", and "Balloon_Imploding".

The program uses a number of DOT NET Library functions including the following:


There are a number of ways to refer to Microsoft's latest compilers and code. Here's what Wikipedia says: The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 3.5
C++ 9.0
.Net 3.5
Common Language Infrastructure

Sample Code

// // Paint Message Handler // private void Form1_Paint(System.Object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle windowRect = ClientRectangle; // Get size of window. Graphics g = e.Graphics; g.FillEllipse(BalloonBrush, // Fill the whole balloon with color BalloonCenter.X - BalloonRadius, BalloonCenter.Y - BalloonRadius, 2 * BalloonRadius, 2 * BalloonRadius); g.DrawEllipse(Pens.Black, // Draw a black line around it. BalloonCenter.X - BalloonRadius, BalloonCenter.Y - BalloonRadius, 2 * BalloonRadius, 2 * BalloonRadius); g.DrawEllipse(Pens.White, // Draw a white line around it. BalloonCenter.X - BalloonRadius - 1, BalloonCenter.Y - BalloonRadius - 1, 2 * BalloonRadius + 2, 2 * BalloonRadius + 2); Font mFont = new Font("Arial", 24, FontStyle.Bold); string mstring = "Catch Me!"; SizeF mFontSize = g.MeasureString(mstring, mFont); g.DrawString(mstring, mFont, Brushes.Yellow, (float)BalloonCenter.X - (mFontSize.Width / 2), (float)BalloonCenter.Y - (mFontSize.Height / 2)); } // // Randomize the center of the balloon // Point Form1_GetRandPoint(Rectangle rr) { Point pp = new Point(); if ((rr.Right - rr.Left) < 1 || (rr.Bottom - rr.Top) < 1) { pp.X = 0; pp.Y = 0; return pp; // trap potential d i v i d e by zero } pp.X = rr.Left + pRand.Next(rr.Right - rr.Left + 1); pp.Y = rr.Top + pRand.Next(rr.Bottom - rr.Top + 1); return pp; } // // Randomize the color of the Balloon to descrete values. // Color Form1_GetRandColor() { int[] arg = new int[3]; arg[0] = 0; arg[1] = 128; arg[2] = 192; int[] alpha = new int[3]; alpha[0] = 0xEF; alpha[1] = 0xF0; alpha[2] = 0xFF; return Color.FromArgb( alpha[2], // leave alpha solid. arg[pRand.Next(3)], arg[pRand.Next(3)], arg[pRand.Next(3)] ); }


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page