One of the rules of our gameplay is the one saying that the game sends in new columns of blocks from the left. And it does so until the player runs out of empty columns… We'll divide this into three basic steps. And later on, we'll add a timer to our game. A timer will make sure that a new column will be created every time at a specified interval. These are the steps for our basic gameplay:
- Create new column with random colors
- Move existing columns to the right to make some room for the new column
- If we can't move any columns – Game Over!
- If the player cleared a certain ammount of columns – move him to a new level
And to make this work we'll declare some more variables – like the number of different colors allowed in the new column. By increasing this number, the game becomes more difficult to play. And one other way to make the game more difficult to play is by shortening the time interval between new column creation. The third way to make our game harder is to increase the number of columns needed to be cleared in a level. Later on, we'll incorporate all this stuff in our game. So, our game will become more and more difficult – from level to level.
Back to the code – here's what we need to add to our declarations:
// Declare the number of different colors
// that are used in the current level.
// We'll set it to 4 - for now:
int iColor = 4;
// Declare the counter that we'll use
// for changing colors every X levels.
int iColors;
// Declare the integer that will hold
// the number of columns created in
// the current level:
int iColumn;// Declare the integer that will hold
// the total number of columns in
// the current level.
int iColumns;
Add these lines of code right under the Game Field Height, Width, and Field Size declarations. Before moving on, we have to add a label to our form. So, add a label to the form, and then set it's properties like shown in the next list:
Label
- (name): lblColumn
- BackgroundColor: Web > Transparent
- Location: 555; 97
- Font: Microsoft Sans Serif; 9,75pt; style=Bold
- Text: 0/0
Finally, the code that will create our new column. Put it in your CreateNewColumn() function.
if (iColumn < iColumns)
{
// Initializing the random function.
// It will come up with random
// numbers every time we call it.
Random Rnd = new Random();
// We have to create 10 new fields.
// (Our column is 10 fields high.)
for (int p = 0; p < iHeight; p++)
{
// We set the random function in
// a way, so it couldn't return
// a value larger than we declared
// it in the beginning, and it
// couldn't return 0 (wich means –
// empty field).
Field[p, 0] = Rnd.Next(1, iColor + 1);
}
// Increase the number of columns created
iColumn++;
// Display the column count in the new
// label on our form.
lblColumn.Text = iColumn.ToString() +
"/" + iColumns.ToString();
}
else
{
// The level is over when the number
// of columns created in the current
// level is equal to the total number
// of columns predicted for that level.
// When the level is over, we call our
// methods for counting bonus points
// and switching to a new level.
LevelScore();
NewLevel();
}
That's it for this chapter. In the next one, we'll add a timer to our game, and add some code to make it create new colums every second. We'll also start talking about moving all existing colums to the right.
0 comments:
Post a Comment