mod07 Snakes and Ladders   Not on the Board   Part 05

mod07 Snakes and Ladders Not on the Board Part 05


SNAKES AND LADDERS: NOT ON THE BOARD 05 Alright guys, in the precious video we had
seen how to display the board as well as higher level overview of the game playing so in that
we had used some functionalities like some functionality we had used it like check snake,
check ladder we will define that now define check snake or check ladder may we let us
start with it check snake check ladder initial view I had asked you guys to make a note of
all these points where ladders were there the points where it start the point where
it ended I had asked you guys to make a note of it, I hope you would have made a note of
it based on that we will be writing this code if the first ladder we saw was at eight so
we say check ladder this takes an argument points so some specific points is given we
are checking if there is some ladder at that point and if there is a ladder we will return
what will be the new points after crossing that ladder that will be returned if the points
is equals to eight this is where we have the first ladder then you are suppose to print
that you have to notify the user that he has actual stepped on to ladder you print that
this is a ladder then you return the new position the ladder at eight actually landed at twenty
six so you return twenty six now the next ladder is at twenty one twenty one the thing
is the same so let me copy paste it or I will type ladder this ladder lands you at eighty
two so I will return eighty two so the same pattern will continue for other ladders too
so let me copy paste this block after twenty one the next ladder is at forty three that
is taking you to seventy seven the next ladder is at fifty that is taking you to ninety one
the next ladder is at fifty four that is taking you to ninety three the next ladder is at
sixty two it is taking you to ninety six the next ladder is at sixty six it is taking you
to eighty seven the next ladder is at eighty that is taking you to hundred the end point
here if you haven’t stepped into any of these points that is once after a dice is
rolled we check whether that is a ladder point are not these were the ladder points if the
points at which we are making a check by synch match any of these things that means you have
not stepped into a ladder so you get beck the points what was added you don’t have
any bonus so else this is not a ladder not a ladder so you return the same points that
is no addition of points no increment of points nothing is there no change in points just
return back what you got this is how check ladder functionality works. Alright! In a similar fashion we can write check snake
functionality check snake the first snake you have is at forty four let me check that
if points aright this event takes an argument points at this particular point whether there
is snake or not if points is equal to the first snake is at forty four if that is equal
to forty four you have to print snake you have stepped into a snake you need to note
the player so you have to print the snake so snakes will bring down your points so you
will come down to twenty two so that you have to return it I will say points is the next
snake is at forty six right? print snake print snake and then you return
the value where it takes you back it will take you to five so return five the snake
at forty six is taking you down to five so you are returning so this is the pattern for
all the other points so let me copy paste this ok the next snake is at forty eight that
will take you to nine the next snake is at fifty two that will take you to eleven the
next snake is at fifty five it is taking you to seven the next is at fifty nine that will
take you to seventeen the next is at sixty four it will take you to thirty six the next
is at sixty nine that is taking you to thirty three the next is at seventy three it will
take you soon to one the next is at eighty three that is taking you to nineteen the next
is at ninety two that will take you to fifty one the next is at ninety five it will take
you to twenty four the next is at ninety eight it is taking you to twenty eight else these
were the points where there were snakes otherwise you have not stepped into a snake not a snake
so there is no change in points you just return back the same points this is how check for
snake has been made this is nothing this is very simple that I had shown you a board in
the very first video when I have asked you to pause the video and make a note of the
snake and ladder where it starts where it takes you to based on that I had written this
code, you check if it is those special points in that case you display a message whether
you have sadder at a snake or ladder and accordingly you modify the points you return the modified
points so now I guess you could get it in the play functionality when we were using
see we add the points and we check if that points is a ladder if it is a ladder here
you will get the modifies points if it is not a ladder you would get back the same point
here similarly the check snake functionality also works, the difference is ladder takes
you from a lower point to a higher point if you step into a ladder, snake will take you
from a higher point to a lower point if you step into a snake that is only difference
if you didn’t step into a snake or a ladder you would retain the same points alright,
so these two functionalities are over so reached end this particular functionality is to be
realised let us do that now, realise is nothing but now you del deep into a to check the code
nothing but you give the code that is what you call as realise reached end at this particular
points you are checking whether you have reached end nothing if the particular points is equal
to end point you say true else you say false that is the logic this is the plain thing
there is an end point defined you just check whether this given value is equal to that
end point if that is the case then you return true true else you return false this is how
this works let me save and I am getting an error is it input only I guess the same input
will work input I guess it will work yeah oh that is the raw input for other use I am
sorry for this confusion this is input, input works alright so we are almost done with the
code everything has been defined see the code has been modularised well the first thing
we have to do is we have to show the board then we have to play, he next step is we are
playing the next step is we are playing, first we show the board then we play that is the
what we are doing this, so this is the highest level of overview so now if you want to know
what this particular show board functionality doing is we have an image file we take it
open it and show the image that is the that is what this particular functionality show
board is doing then the next functionality is the play functionality which is our main
functionality here what you do is, you input the names of two players you initially set
their points to zero you have some variable call turn which denotes which player has to
play now then you ask him if he wants to say that this is this person turn if he wants
to continue or quit the same so based on that if he wants to quit, you quit the game there
by denoting the status till now or if he wants to continue you roll a dice based on what,
what is shown up in the dice you add his points and then check if he has landed in a snake
or a ladder if so you modify his points otherwise you do it you do not do anything you just
retain his points so that basically what you do is you add his points and then you check
if he has landed into a ladder or into a snake and sometimes it may happen that during the
process of rolling a dice you may go out of the board in that case you are supposed to
stop at the end of the board itself so this check is done here then you display his score
and say if he has won when his points is exactly the end points you just you have to check
if he has reached the end point or not, if he has reached the end point you say that
he has won this is the higher level overview you have a variable turn denotes who has to
play if he wants to quit display the status and quit otherwise roll a dice add points
check if has landed into a ladder or a snake and if he has reached the end points you quit
the game, this is the higher level overview now the detail functionalities checking ladder
checking snake this I had defined based on the board I had shown to you, to check those
specific points if that particular point has been reached you display that he had stepped
into a ladder or snake appropriately and then you return the points where he will land finally,
you return that if he hasn’t stepped into it just return back the same points so that
there is no change in the points that’s how these things works and reached end this
functionality what it check is whether the points this person has got is same as the
defined end point or not this is the check performed here, this occurs continuously and
one of the condition will lead to quitting if the game, one is the player voluntarily
wants to quit the game the second condition is someone has reached the end point these
are the two constrain these are the two places where the game will quit alright this is how
we have coded now you please pause and see till now what has happened or you understand
the functionalities, you understand the overview level as well as to the details in depth you
proceed from this way itself, these are the major functionalities now let me tell deep
into it this way you just consider you have been given a big box you open that box then
get a smaller box then you open it then you get a smaller box this is how we are organised
a code you understand this well and this once you are very clear with it will proceed with
the running of this program alright please pause and understand this very well.

Leave a Reply

Your email address will not be published. Required fields are marked *