At the beginning of Act 3, Claudius and Polonius set up a trap for Hamlet, to see if he is madly in love or if it is something else, with Ophelia as the willing bait.
Before Hamlet sees Ophelia, he delviers one of the greatest speeches, "To be, or not to be..."
To be, or not to be, that is the question, Whether 'tis nobler in the mind to suffer..."
In scene 2, we read Hamlet is setting up his play, which is a variant of "The Murder of Gonzago."
Just as Hamlet had planned for, once upon arriving to the similar death of Hamlet's father, Claudius stands up and rushes out of the room.
Subsequent to leaving the room, Claudius is meets with Rosencrantz and Guildenstern. Claudius believes that Hamlet is crazy and is a threat to the safety of Denmark.
Later that night, Claudius goes to his room to pray, but then Hamlet arrives ready to kill him. Then realizes that while Claudius is killed during his repentance he will still get sent to heaven, but what Hamlet doesn't know is that Claudius isn't fully sorry.