In Shakespeare's Hamlet, Hamlet is very careful to set up the play concisely to see if he can push Claudius into responding in such a way that he will reveal his guilt; in this manner, Hamlet believes he will have enough proof so that he can finally kill Claudius for his father's murder.
When Hamlet speaks to Ophelia, he is rude, making ribald jokes at her expense. Ophelia believe his is being extremely disrespectful in delivering sexual innuendos at her expense, and she tries to concentrate on the play. Ironically, the play is called The Mousetrap; and when Hamlet kills Polonius, thinking it is the King, he announces that he suspects a rat and will kill it cheaply.
How now? A rat! Dead for a ducat, dead.
The reference here is another veiled insult of Claudius in comparing him to some kind of vermin. This is a play within a play. As it continues, Hamlet keeps up a running dialogue, explaining the play's context, all the while throwing around hidden taunts at the members of his company of friends and family.
The rest of the group is somewhat confused about the play's plot, but Hamlet reassures them that they need not take offense at anything in the play because they are not guilty of any similar act shown on stage in The Murder of Gonzago. There is sarcasm in Hamlet's manner, as he continues to show his lack of respect for his uncle, all the while searching for signs of guilt on Claudius's part.
[Hamlet] will have [the actors] stage a play, The Murder of Gonzago, re-enacting his father's murder and determine Claudius's guilt or innocence by studying his reaction to it...Hamlet provides an agitated running commentary throughout. When the murder scene is presented, Claudius abruptly rises and leaves the room, which Hamlet sees as proof of his uncle's guilt.
Throughout the play, Hamlet's attitude is offensive, sarcastic and insulting, weaving his way in and out of the play that he has arranged, delivering commentary upon those involved (Gertrude, Claudius and Ophelia) in a scathing way, until the King finally stands and the play ends, giving Hamlet his proof of Claudius' guilt in murdering Old Hamlet.