C# Practice: Giving Points with Switch Statements

Sabrina Windsor
Jul 12, 2021

--

Let’s say that when we press certain keys, we’re given a set amount of points. Depending on the amount of points we have, a specific message will appear.

Objective: Use switch statements to check the points value to execute certain messages.

First, create an int variable and name it _points. Then, we want to be able to make certain keys give an amount of points when they’re pressed. We’ll need to if statements to assign key codes.

Q will get 50, W will get 100, and E will set the point value to 0. Now its time for the switch statement to execute messages.

This will check the value of the _points variable and execute the message that follows the matching case.

--

--

Sabrina Windsor
Sabrina Windsor

Written by Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!

No responses yet