when my laptop charger is connected to my laptop, when I work or play games it causes it to switch off


Test with another charger, also try without the battery in the system. It may be overheating, if you have the charger connected, the laptop will run at full speed, causing more heat and stress on the components than on battery. You can try running on battery but set the power options to full on and see what happens.