C1Chart provides plenty of intriguing features which help in developing a base for an awesome application. Charts are always considered as a component to display the data in a graphical view but that’s not where it ends. There is much more to work beyond displaying data in Charts.
Gaming has always been the catch of everyone's eye. BubbleSmash is a game which can be created using the Chart for WinForms control. A game which can freshen up one's mind between a tightly packed schedule. Apart from the entertaining view, the show stopper here is the vulnerability and features of C1Chart.
Well, it's a simple game where the bubbles moving through the Chart need to be punctured. The maximum number of bubbles punctured will get you the highest score.
The implementation is not a burdensome job. The prerequisites here are just a few code snippets implementing the logic, a pinch of creativity that would make the application look classy and attractive and last but not the least, our main ingredient, C1Chart which is the key to this implementation. The logic that we need to focus on this implementation is:
Remove a bubble if it moves out of the region.
int i = 0;
for (int index = 0; index < c1Chart1.ChartGroups[0].ChartData.SeriesList.Count; index++)
{
C1.Win.C1Chart.ChartDataSeries series = c1Chart1.ChartGroups[0].ChartData.SeriesList[index];
series.Y[0] = (int)series.Y[0] + 10;
if ((int)series.Y[0] > 100)
{
c1Chart1.ChartGroups[0].ChartData.SeriesList.Remove(series);
nLosts++;
break;
}
series.Y1[0] = (int)series.Y[0] / 20;
i++;
}
Create a new bubble when needed.
if (count >= 10 / this.numCandies)
{
count = 0;
C1.Win.C1Chart.ChartDataSeries series = this.c1Chart1.ChartGroups[0].ChartData.SeriesList.AddNewSeries();
series.SymbolStyle.Shape = C1.Win.C1Chart.SymbolShapeEnum.Dot;
series.FillStyle.GradientStyle = C1.Win.C1Chart.GradientStyleEnum.Radial; ;
series.FillStyle.Color1 = Color.FromArgb(xPosRandom.Next(0, 255), xPosRandom.Next(0, 255), xPosRandom.Next(0, 255));
series.FillStyle.Color2 = Color.FromArgb(xPosRandom.Next(0, 255), xPosRandom.Next(0, 255), xPosRandom.Next(0, 255));
series.Display = C1.Win.C1Chart.SeriesDisplayEnum.Show;
series.X.Length = 1;
series.Y.Length = 1;
series.Y1.Length = 1;
series.X[0] = xPosRandom.Next(10, 90);
series.Y[0] = 10;
series.Y1[0] = (int)series.Y[0] / 20;
}
private void c1Chart1_MouseDown(object sender, MouseEventArgs e)
{
if (flag)
{
int s = 0, d = 0, p = 0, index = 0;
C1.Win.C1Chart.ChartRegionEnum region = c1Chart1.ChartRegionFromCoord(e.X, e.Y);
c1Chart1.ChartGroups[0].CoordToDataIndex(e.X, e.Y, C1.Win.C1Chart.CoordinateFocusEnum.XandYCoord, ref s, ref p, ref d);
if (d < 20 && s > -1 && p > -1)
{
C1.Win.C1Chart.ChartDataSeries series = c1Chart1.ChartGroups[0].ChartData.SeriesList[index];
nScore += 100 - (int)series.Y[0];
c1Chart1.ChartGroups[0].ChartData.SeriesList.RemoveAt(s);
nHits++;
}
SetStatusLabel();
}
}
So finally, we have successfully created a bubble smashing game. C1Chart can be thought of much more than a simple displaying control. What matters here is the business to think out of the box. Read more about Chart for WinForms here. Read more about ComponentOne Studio WinForms Edition (controls, demos, samples, and more).