Warning
I have posted a topic in the Discussions section of this repository to seek advice and solutions for some bugs in this program. I will review all suggested solutions and approve all comments that successfully address the issues.
Note
Starter and Final code for the Challenge project: Create methods C# console applications
from the Microsoft Learn
collection Getting started with C#
This mini project comes with a starter code, containing the following functions:
void InitializeGame();
bool TerminalResized();
void ShowFood();
void ChangePlayer();
void FreezePlayer();
void Move();
Important
Move() function has 2 optional parameters check
and speed
for tasks 1 and 3.
If I call Move() without any arguments, the default parameters come into play.
- Game Termination: The game should end if the terminal window is resized.
- Optional Parameter in Move Function: I added an optional parameter to
Move()
that stops the game when any non-directional key is pressed.
To achieve these, I:
- Created a function called
AnnounceTerminating()
for the resizing condition. - Used an instance of the
Random
class to decide the optional parameter's value (1 to stop the game, 0 to continue).
void AnnounceTerminating();
- Food String Update: Update the food if there's nothing left.
- Change Player's Appearance: Update the player's appearance by calling the
ChangePlayer()
function
bool JustAteFood();
- Freeze the player temporarily if his appearance is
(X_X)
, therefore I have created the functionCheckFreezeCondition()
- Increase player's speed to left/right by 3 based on this exact appearance
(^-^)
, therefore I have created theCheckMovementSpeed()
function
bool CheckMovementSpeed();
bool CheckFreezeCondition();
Tip
Thanks for reading! Practice daily and have fun!