Well, I finished the AGK2 book and rather than re-read the entire book again I figured I would just dive in butt naked and see what I know versus what I don't. I suspect I will be having many sleepless nights trying to get my code working both correctly and efficiently. I'm doing a very basic beginner mode right now with 25 boxes, easy to win and just wanting to get the functionality going. I ran into my first conundrum today as I know there must be a better way to generate the following code:
// Project: Sweeper
// Created: 2015-05-04
// set window properties
SetWindowTitle( "Shooter" )
SetWindowSize( 640, 480, 0 )
// set display properties
SetOrientationAllowed( 1, 1, 1, 1 )
//Load the images for use using version 2 AKG
celldown = LoadImage("CellDown.png")
easy = LoadImage("Easy.png")
emptycell = LoadImage("EmptyCell.png")
explodedminecell = LoadImage("ExplodedMineCell.png")
flagbutton = LoadImage("FlagButton.png")
mine = LoadImage("Mine.png")
newgame = LoadImage("NewGame.png")
revealedminecell = LoadImage("RevealedMineCell.png")
//Create the cell sprite here for first row
cell = CreateSprite(celldown)
SetSpriteSize(cell,5,-1) // This is 5 across and 7 down or (5,7) insize
SetSpritePosition(cell,5,7)
cell2 = CloneSprite(cell)
SetSpritePosition(cell2,10,7)
cell3 = CloneSprite(cell)
SetSpritePosition(cell3,15,7)
cell4 = CloneSprite(cell)
SetSpritePosition(cell4,20,7)
cell5 = CloneSprite(cell)
SetSpritePosition(cell5,25,7)
//Create cells for row 2
cell6 = CloneSprite(cell)
SetSpritePosition(cell6,5,14)
cell7 = CloneSprite(cell)
SetSpritePosition(cell7,10,14)
cell8 = CloneSprite(cell)
SetSpritePosition(cell8,15,14)
cell9 = CloneSprite(cell)
SetSpritePosition(cell9,20,14)
cell10 = CloneSprite(cell)
SetSpritePosition(cell10,25,14)
//Create cells for row 3
cell11 = CloneSprite(cell)
SetSpritePosition(cell11,5,21)
cell12 = CloneSprite(cell)
SetSpritePosition(cell12,10,21)
cell13 = CloneSprite(cell)
SetSpritePosition(cell13,15,21)
cell14 = CloneSprite(cell)
SetSpritePosition(cell14,20,21)
cell15 = CloneSprite(cell)
SetSpritePosition(cell15,25,21)
//Create cells for row 4
cell16 = CloneSprite(cell)
SetSpritePosition(cell16,5,28)
cell17 = CloneSprite(cell)
SetSpritePosition(cell17,10,28)
cell18 = CloneSprite(cell)
SetSpritePosition(cell18,15,28)
cell19 = CloneSprite(cell)
SetSpritePosition(cell19,20,28)
cell20 = CloneSprite(cell)
SetSpritePosition(cell20,25,28)
//Create cells for row 5
cell21 = CloneSprite(cell)
SetSpritePosition(cell21,5,35)
cell22 = CloneSprite(cell)
SetSpritePosition(cell22,10,35)
cell23 = CloneSprite(cell)
SetSpritePosition(cell23,15,35)
cell24 = CloneSprite(cell)
SetSpritePosition(cell24,20,35)
cell25 = CloneSprite(cell)
SetSpritePosition(cell25,25,35)
// Clear the screen
ClearScreen()
// Make colors here if I need them, delete them when finished to clean up the code
Blue = MakeColor(0,0,255)
Red = MakeColor(255,0,0)
Green = MakeColor(0,255,0)
Yellow = MakeColor(255,255,0)
do
DrawBox(5,7,30,41,blue,blue,blue,blue,0)
Sync()
loop
As you can see, I had to make 5 separate blocks of code for each row. The AGK2 basic first 8 chapters or so really only goes into theory and how to do things on a basic level. My question, is there a better way to do this? I know in other languages I could write functions to do this so I don't have 500 lines of code in just creating one sprite only to have to do it again for mines and other images.