
-----------------------------------
LolADuck
Sun Dec 17, 2017 7:30 pm

Snakes and ladders V2 summative project
-----------------------------------
Sup, posted a snakes and ladders game for one player a few weeks ago, here's my revised form, a lot better in my opinion. My coding skills have gotten better in the span of just a few weeks :)
Constructive criticism is appreciated

[code]%DATEMADE:12/16/2017
%FUNCTION: To play snakes and ladders board game. There is your player tile and a cpu tile (yellow,red) first to the 100th tile wins, there are obstacles and power
%boosts on the way, ladders let you go up whille snakes push you down.
%COMPLETED PROJECTS: arrays, constants, integers, strings, graphics, booleen funtions, keyboard input, put, get, if/then/else, loop, exit when, for, procedure, bulletproof, header, 300 lines
%REMAINING PROJECTS: Real, comments, or, flickering, polishing
import GUI %GUI package
setscreen ("graphics:800;600;nobuttonbar") %screen 800*600 no buttonbar at the top
setscreen ("nocursor") %remove blinking cursor

%DECLARING VARIABLES AND ARRAYS-----------------------------------------------------------------------------------------------
var urname : string %varable where your name will be held
var font, font2, dice, newplayertile, newcputile, oldplayertile, oldcputile : int %font 1&2 are for graphics, newplayertile new cpu tile are for the array
newplayertile := 1 %set the players to square one
newcputile := 1 %set the players to square one
const radius := 10 %the radius of the player tile will always be 10 pixels
font := Font.New ("Palatino:35") %giving font a font to work with
font2 := Font.New ("serif:14") %another font for smaller things
var chars : array char of boolean %for keyboard input
var randomizer1, randomizer2 : int %for drawing the snakes on the board
type gamecoords : %a record for the array, keep track of the player and cpu x,y position at all times
    record
        playerx, playery, cpux, cpuy : int
    end record
var board : array 1 .. 100 of gamecoords %the array for the board with all 100 squares
%END OF DECLARING VARIABLES AND ARRAYS----------------------------------------------------------------------------------------

%GREETING PLAYER, ASKING NAME--------------------------------------------------------------------------------------------------
var Playgame : int := GUI.CreateButtonFull (300, 300, 200, "Play Game", GUI.Quit, 100, 'p', true) %button to start the game
loop
    exit when GUI.ProcessEvent
end loop
GUI.Dispose (Playgame)

put "Welcome to snakes and ladders! Press enter to move your player(yellow)" %rules of game
put "press escape to quit"
put "Land on a snake to slide down, land on a ladder to move up"
put "You are playing against the computer(red)"
put "First to land on tile 100 wins the game!"
put ""
put "What is your username?"
loop
    get urname %get your name%get players username
    exit when length (urname)  0 and newplayertile > 100 then
        newplayertile := 100 - (dice - (100 - oldplayertile))
    end if
    if newplayertile = 100 then
        drawfilloval (board (newplayertile).playerx, board (newplayertile).playery, 10, 10, yellow)
        drawfilloval (board (newcputile).cpux, board (newcputile).cpuy, 10, 10, red)
        delay (1000)
        win
    end if
    drawfilloval (board (newplayertile).playerx, board (newplayertile).playery, 10, 10, yellow)
    drawfilloval (board (newcputile).cpux, board (newcputile).cpuy, 10, 10, red)
    View.Update
    drawfillbox (605, 0, maxx, maxy, 148)
    Draw.Text (urname + " Rolled:", 605, 100, font2, yellow)
    Draw.Text (intstr (dice), 620, 50, font, yellow)
    delay (1000)
    drawfillbox (605, 0, maxx, maxy, 148)
    View.Update
    movecpu
end moveplayer
%END OF MOVING PLAYERS TILE------------------------------------------------------------------------------------------------

%INITIALIZING PLAYER AND CPU POSITIONS-------------------------------------------------------------------------------------
drawfilloval (board (newcputile).cpux, board (newcputile).cpuy, radius, radius, red)
drawfilloval (board (newplayertile).playerx, board (newplayertile).playery, radius, radius, yellow)
%END OF INITIALIZING PLAYER AND CPU POSITIONS------------------------------------------------------------------------------

%QUIT THE GAME-------------------------------------------------------------------------------------------------------------
procedure leavegame
    cls
    Draw.Text ("GOODBYE, " + urname, 200, 300, font, 148)
    delay (1000)
    quit
end leavegame
%END OF QUITTING THE GAME--------------------------------------------------------------------------------------------------

%PROSSESING USER KEYBOARD INPUT-------------------------------------------------------------------------------------------
loop %when the user presses enter they will play a round, when they press escape they end the game
    drawfillbox (605, 0, maxx, maxy, 148)
    Input.KeyDown (chars)
    if chars (KEY_ENTER) then
        drawfillbox (605, 0, maxx, maxy, 148) %box covering the side
        View.Update
        moveplayer
    elsif chars (KEY_ESC) then
        leavegame
    end if
end loop
%END OF PROSSESING USER KEYBOARD INPUT-----------------------------------------------------------------------------------
[/code]

-----------------------------------
TokenHerbz
Mon Dec 18, 2017 4:04 am

RE:Snakes and ladders V2 summative project
-----------------------------------
just doing a quick skimming over your code...

you should simplify your procedures to do only one thing, and that thing well...

drawing and moving is two things, why not try to create a drawing procedure to does just that, drawing everything.   

this way also its easier to manage/debug.

also you have way to much View.Updates.  make the game have only one cls/View.update in all the code.  thats the challenge i put fourth to you for snakes and ladders V3.

I think you'll learn much doing so
