[Music]
so
right now we have the score being
greased for each player
and if if you wait when any of the
players reach
five points scores are set to zero
and you start all over again
what you do now is implement a procedure
to draw a game over screen or menu that
will appear
whenever someone reaches the five points
and for this we need to keep track of
whenever the game is over or when the
player wins the game
and we'll check this on this check time
label that is our game
loop so let's create a variable
we'll keep track of this game active
that will start as one to indicate that
the game
is active
this is like a boolean variable to keep
track
if the game is active if true we assign
it to one
and if false you set it to zero
and the game is over
now in the game over
where we are assigning zero to each
other players
we also set to false
to zero the game active
variable and the
idea is that this variable will stop
the game
now again in the game loop
before drawing and moving everything
we'll check if the game is not active
so cmp to compare cmp
game active zero
and if not we show
the game over menu
if the game is not active if game active
is zero
we show the game over menu
if the game active variable is one the
game is active and we continue
with our game processing so let's create
now
show gameover label
in this label we'll call
draw gameover menu procedure
so if the game is not active we show
the game over menu
after we draw this we just
jump to our game loop
again and in the future we'll have
key presses to jump to main menu or
restart
the game so let's create now the
procedure
to draw the game over menu we call this
draw game over menu
let's clear the screen first before
displaying
the menu
let's comment this clear the screen
and this procedure oops this procedure
will draw the game over menu
we can copy the code
we have already created to print the
string to the screen
let's copy this
and here
we change we show the game over
menu
now we just need to change the string to
be
the game over title
and let's create now this variable
right here let's go to the
data segment
you can game over
and we ended with a dollar sign
game over menu title
let's test this now
let's wait for the game to end
so you can see the game over screen
when the player reaches five points and
let's
see the text appears but
it's on the far right and it's blinking
awesome so let's bring it more to the
left
let's change the position
let's bring it more to the left
zero four
and let's add some text to tell
which player has won the game
shows the winner
let's copy this
let's increase the row number
and change to be the string of the
winner
let's create now this string on the data
segment
db
player zero one
this will be
text with the winner
text
okay
let's test this now again
let's wait for the five points
so as you can see now
appears on the screen blinking as always
but it's on the
on screen so it's working
so this is happening probably because
we're all in drawing this text
over and over so let's just draw it
one time and then wait for keep press
so we'll use the one six interruption
and this is not what we want
we just want to wait for any
stroke we need to move to ah 0
then call the interruption so
move to ah 0
and then we call interruption16h
let's test and now whenever the game
over screen appears
we wait for any key press before
starting
the game again
let's assemble this
and cool so now the game over screen
appears and it's not blinking like crazy
as we've seen before so let's change
now the code so we can see different
messages
depending on which player has won the
game
let's create a winner
index that will be
1 if player 1 has won the game in 2
if player 2 has won the game
then we just will fit this value into
the text gameover winner
string instead of the zero
that now appears so one for player one
and two
for player two
now on the game over label
we need to check which player has
reached
the five points
so we
just need to compare
player one points to five
whenever we reach game over and if it's
not
less than five the winner
is a player 1
and of course if the player 1 is less
than 5 points
then the player 2 has won the game
so
let's
move to winner index one
let me continue the game
processing the game over screen
and if the winner is player two we set
the winner index
2 and we continue the game over
processing again
so let's continue came over and
we continue to draw
and restart the game
so this code we just added will check
which player is five
or more points
if the player one has le not less
than 5 the player 1 is the winner
and if not then the player 2
is the winner
so if the player 1 has won the game we
update
the winner index with the player 1
index
and if the player 2 has won the game we
update the winner index
with two so let's update the text
and before we draw the winner text
we update the text with
the winner index we already set up
so let's create
here
a procedure that will update the winner
text before
we draw it
and this basically this procedure what
we'll do
is feed into the text game over
winner string instead of zero
you will feed one if player one is the
winner and two
if the player two is the winner so in
here
we'll update the index of this
string right here so this zero
with the value of the winner index this
index will be
zero one two
three four five six and seven
so it's the index seven the zero
that we want to update with the
winner index
so let's move
to the index the new value you can do
this using this
index notation plus seven
the address of the beginning of the
string plus 7
with this we reach the desired character
and you set it to be
equal to the winner index but before we
do this
this operation we need to move the
winner index to a register first
so we move to the l register and then
we update with the ar register value
so very simple
remember that to show the value as the
ascii character of the number
we also need to add 3 0h
to the value of the a register to
summarize this
if the winner index is 1
for example
the al register becomes
one to convert this value
one to be the character one that
we want to display on the screen we
convert it to the ascii value by adding
31h so the results of this
will be the one character in ascii
and then we just update the index
in the text with a character
so let's test this now
let's wait for the five points as always
so the player one
will win the game and game over and
player 1
1 as you can see the character 1 is
appearing now
and right now we have our game over
screen implemented