After a move, ask two separate questions about the player whose turn it is: is their king in check, and do they have any legal move? No legal move with check means checkmate. No legal move without check means stalemate, a draw.
Worked example
In the starting picture, White's king is f6 and queen g6; Black's king is h8. Compare queen g6 to g7 with queen g6 to f7. Both queen moves are legal, but only the queen on g7 attacks h8.
Two Different Endings
For each comparison, return to the starting picture. After queen g6 to g7, Black's king is attacked on h8. The white king protects g7, and the queen controls g8 and h7. After queen g6 to f7, h8 is not attacked, but f7's queen controls h7, g7 and g8. Black has only its king, so there is no other piece to move.