So I made a "game" in a c# console app project which is basically a hero who must kill a monster and both the hero and the monster have HP and a random amount of damage given and taken (as it should be).
I have a couple tiny problems which don't make sense to me. There is a Regeneration Potion that I have added to the game which obviously adds a random amount of hp between 10-30 to the player.
//Regenerating or not
if (isRegen == false) //if it doesn't
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("You've failed to regenerate!");
Console.WriteLine("Enemy: " + monster.name);
Console.WriteLine("Enemy's hp: " + monster.hp);
GetDamage();
}
else //if it does
{
if (myHP + regenAmount > 100 || myHP == 100)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("You can't regenerate above 100 hp.");
Game();
}
else
{
if (potionCounter == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("You are out of health potions. Cannot regenerate!");
Game();
}
potionCounter--;
myHP += regenAmount;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("You consumed a Health Potion!");
Console.WriteLine("Your hp was regenerated successfully! HP is raised by " + regenAmount);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Enemy: " + monster.name);
Game();
}
}
Now, as you can see in the code above, I have made an if statement that checks whether the sum of myHP and the regenAmount is higher than 100, a message that says "You can't regenerate above 100 hp" is displayed. Thing is, when I try this, sometimes it does display the message
as presented here,
but eventually it decides to display "You've failed to regenerate!" in here and well the game just goes on and the player gets hit. (which obviously shouldn't happen).
There is even another similar problem with the potionCounter. As presented in the code:
if (potionCounter == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("You are out of health potions. Cannot regenerate!");
Game();
}
Whenever the potion counter reaches 0, it should display a message that says that the user is out of potions. It happens and works, but similarly to the previous problem, it sometimes ignore the if statement and allows the user to either heal and continue on decrementing the potionCounter variable or fail to regenerate and get hit by the monster.
I know some of this code is kinda bad and well that's because im kinda new to programming but im trying my best to develop myself and learn as much as I can, which is why I decided to share it here.
Thank you for reading it and I hope you find the solution :)
Edit: The code for Game():
static void Game()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(monster.name + "'s hp: " + monster.hp);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Your hp: " + myHP + "\n");
Console.ForegroundColor = ConsoleColor.White;
while(monster.hp > 0 && myHP > 0) //Running until the enemy or the player dies.
{
Console.Write("A - ATTACK (Give damage but always get hit)\nD - DEFEND (50% chance of not getting hit)\nR - REGENERATE (Regenerates HP, but if it fails you get hit) - ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(potionCounter + " POTIONS LEFT\n");
string input = Console.ReadLine();
//ATTACK
if (input == "a" || input == "A")
{
Console.Clear();
Attack();
}
else if (input == "d" || input == "D")
{
Console.Clear();
Defend();
}
else if (input == "r" || input == "R")
{
Console.Clear();
Regenerate();
}
else
{
Console.Clear();
Game();
}
}
}
This is how I'd structure a simple game like this.
You already seem to have a "Monster" class – good! – but it's elided from this example for simplicity. Similarly, you would probably encapsulate Player as a class to keep track of each player's potions and HP individually.
Either way, the idea is that there's
an infinite loop governed by the "game over" flag
a function to run a single turn – checking whether the game is over, printing the game state, waiting for input, processing it, running AI actions (which, given our monster is a simple ogre of some ilk, is just it bashing your head in)
separate functions for the different events that occur in the game
... and a helper function that lets you change the console color and print a line of text in a single invocation ;-)
I hope this helps! It's not exactly a laser-focused pin-point answer, I know...
class Game
{
private int playerHp = 100;
private int monsterHp = 100;
private int nPotions = 3;
private readonly Random random = new Random();
private bool gameOver = false;
static void ColorPrint(string message, ConsoleColor color)
{
Console.ForegroundColor = color;
Console.WriteLine(message);
}
public void Play()
{
while (!gameOver)
{
RunTurn();
}
}
void RunTurn()
{
CheckGameOver();
if (gameOver) {
return;
}
ColorPrint(String.Format("Monster HP: {0}", monsterHp), ConsoleColor.Red);
ColorPrint(String.Format(" Your HP: {0}", playerHp), ConsoleColor.Green);
ColorPrint(String.Format(" Potions: {0}", nPotions), ConsoleColor.Yellow);
ColorPrint("(A)ttack / (P)otion / anything else to skip your turn?", ConsoleColor.White);
var command = Console.ReadLine().Trim().ToLower();
switch (command)
{
case "a":
DoPlayerAttack();
break;
case "p":
DoPlayerPotion();
break;
default:
ColorPrint("You decide to loiter around.", ConsoleColor.White);
break;
}
DoEnemyAttack();
}
void CheckGameOver() {
if (monsterHp <= 0)
{
gameOver = true;
ColorPrint("The monster is slain!", ConsoleColor.White);
}
if (playerHp <= 0)
{
gameOver = true;
ColorPrint("You are dead. :(", ConsoleColor.White);
}
}
void DoPlayerAttack()
{
var damage = random.Next(1, 10);
ColorPrint(String.Format("You strike the monster for {0} damage.", damage), ConsoleColor.White);
monsterHp -= damage;
}
void DoPlayerPotion()
{
if (nPotions > 0)
{
var heal = random.NextDouble() < 0.7 ? random.Next(5, 15) : 0;
if (heal > 0)
{
ColorPrint(String.Format("You heal for {0} HP.", heal), ConsoleColor.Gray);
}
else
{
ColorPrint("That potion was a dud.", ConsoleColor.Gray);
}
playerHp = Math.Min(100, playerHp + heal);
nPotions--;
}
else
{
ColorPrint("You rummage through your belongings to find no potions.", ConsoleColor.Gray);
}
}
void DoEnemyAttack()
{
var damage = random.Next(1, 10);
ColorPrint(String.Format("The monster nibbles on you for {0} damage.", damage), ConsoleColor.White);
playerHp -= damage;
}
}
Just focusing on this bit of your code for a moment:
if (potionCounter == 0)
{
// ...
}
potionCounter--;
myHP += regenAmount;
Think about what will happen when the potionCounter is zero:
- It will then set potionCounter to -1
- It will give you the HP
You probably meant to put this code inside an else statement.
Additionally, checking if (potionCounter <= 0) would be more robust than testing for zero exactly.
Related
So I'm building this RPG turn based game for a class. I'm not trying to get my homework done for me, but this one problem is REALLY spinning me out, I've been at this for like 3 hours and I can't figure out how to fix this problem.
Essentially, I have an update method that controls whos turn it is (either the player or the computer)
public bool Update()
{
// clears console for a fresh start
Console.Clear();
//branch who's turn it is and add a line indicating so
if (playerTurn)
{
//print that it's the player's turn
Console.WriteLine("It's Your Turn to Attack!");
//run the player turn
PlayerTurn();
}
else
{
//print the rivals turn label
Console.WriteLine("It's the Enemy's Turn to Attack!");
}
//run the rivals turn
RivalsTurn();
{
}
//end game check
return EndTurn();
}
Then, I have the player turn method ---
void PlayerTurn()
{
// print instructions to select an attacker
Console.WriteLine($"Select which character will attack!\n(1) To Select {playerArray[0].Name()}\n(2) To Select {playerArray[1].Name()}\n(3) To Select {playerArray[2].Name()}\n(4) to view your teams current status\n(5) To Heal An Ally");
// Loop until an attacker is chosen
while (Attacker == null)
{
// use num 1-3 to select player party member that is the attacker
ConsoleKeyInfo k = Console.ReadKey();
if (k.KeyChar == '1')
{
Attacker = playerArray[0];
Console.WriteLine($"\nYou've chosen to attack with {Attacker.Name()}");
}
else if (k.KeyChar == '2')
{
Attacker = playerArray[1];
Console.WriteLine($"You've chosen to attack with {Attacker.Name()}");
}
else if (k.KeyChar == '3')
{
Attacker = playerArray[2];
Console.WriteLine($"You've chosen to attack with {Attacker.Name()}");
}
else if(k.KeyChar == '4')
{
PrintParties();
continue;
} else if (k.KeyChar == '5') {
HealAlly();
break;
}
// start a new line after user input
Console.WriteLine();
// Data Validation: make sure the key typed is a valid key
if (k.KeyChar < '1' || k.KeyChar > '5')
{
Console.WriteLine("Please Enter (1), (2), or (3) to select your attacking character. Press (4) to view your stats, and (5) to Heal an Ally");
continue;
}
else // convert from key input (1-3) to array element space (0-2)
curSelection = int.Parse(k.KeyChar.ToString()) - 1;
{
}
if (Attacker.GetHP() <= 0)
{
//check to make sure the selected character is alive HP > 0
//print the attackers name
//character's dead choose again
Console.WriteLine($"{Attacker.Name()} is dead! Choose someone who is alive!");
Console.WriteLine("Please Enter (1), (2), or (3) to select your attacking character. Press (4) to view your stats, and (5) to Heal an Ally");
Attacker = null;
}
else
{
Console.WriteLine($"{Attacker.Name()} will attack!");
Thread.Sleep(1000);
}
}
//print instructions for choosing a rival.
Console.WriteLine($"Select which enemy to attack!\n(1) To Attack {enemyArray[0].Name()}\n(2) To Attack {enemyArray[1].Name()}\n(3) To Attack {enemyArray[2].Name()}\n(4) To see the Enemies Current Stats.");
//loop until a defender is choosen
while (Defender == null)
{
// use 1-3 to select player party member that is the attacker
ConsoleKeyInfo k = Console.ReadKey();
if (k.KeyChar == '1')
{
Defender = enemyArray[0];
Console.WriteLine($"\nYou will attack {Defender.Name()}");
} else if(k.KeyChar == '2') {
Defender = enemyArray[1];
Console.WriteLine($"\nYou will attack {Defender.Name()}");
}
else if (k.KeyChar == '3')
{
Defender = enemyArray[2];
Console.WriteLine($"\nYou will attack {Defender.Name()}");
} else if (k.KeyChar == '4')
{
playerTurn = false;
PrintParties();
playerTurn = true;
}
{ }
//add a new line aft er the user input
Console.WriteLine();
// Data Validation: make sure the key typed is a valid key
if (k.KeyChar < '1' || k.KeyChar > '3')
{
// repeat instructions
Console.WriteLine("Select an enemy to attack by pressing either 1, 2, or 3.\n");
// loop again
continue;
}
else // convert from key input (1-3) to array element space (0-2)
curSelection = int.Parse(k.KeyChar.ToString()) - 1; //minus one to use as index
//check to make sure the selected character is alive HP > 0
//print the defenders name
//assign the selected character as the defender
if (Defender.GetHP() <= 0)
{
//print instructions again
Console.WriteLine($"{Defender.Name()} is already dead! Pick another enemy!");
Console.WriteLine("Select an enemy to attack by pressing either 1, 2, or 3.\n");
Defender = null;
} else
{
Console.WriteLine($"{Attacker.Name()} attacks {Defender.Name()}!");
Thread.Sleep(2000);
}
}
//damage the defender by the attacker's Strength value
Defender.ApplyDamage(Attacker.GetStrength());
//change color for rival team
Console.BackgroundColor = Attacker.GetTeamColor();
//print the new rival's health
Console.WriteLine($"{Defender.Name()} was hit by {Attacker.Name()}! {Defender.Name()} now only has {Defender.GetHP()} HP!");
EndTurn();
//change color back for normal
Console.BackgroundColor = ConsoleColor.Black;
//pause for 2 seconds
Thread.Sleep(2000);
//reset attacker/defender for next attack
Attacker = null;
Defender = null;
}
What I am trying to do is when the player selects "5" and runs the HealAlly() Method, I want the program to Take the users next input (who to heal), tell the player whether or not they can heal (if the character is either dead or full health) and then switch turns.
Instead, the code jumps back to the middle of the PlayerTurn method and tries to execute from there, but since the Attacker was never set (the user hit 5 so they didn't pick an Attacker) the game will crash.
Here is the HealAlly() method:
void HealAlly()
{
float healing = 3;
while (Healee == null)
{
Console.WriteLine("\nWhich Ally Do You Want To Heal?");
Console.WriteLine($"(1) for {playerArray[0].Name()}\n(2) for {playerArray[1].Name()}\n(3) for {playerArray[2].Name()}");
// use 1-3 to select player party member that is being healed
ConsoleKeyInfo k = Console.ReadKey();
if (k.KeyChar == '1')
{
Healee = playerArray[0];
Console.WriteLine($"\nYou will heal {Healee.Name()}");
Console.WriteLine("Healing...");
}
else if (k.KeyChar == '2')
{
Healee = playerArray[1];
Console.WriteLine($"\nYou will heal {Healee.Name()}");
Console.WriteLine("Healing...");
}
else if (k.KeyChar == '3')
{
Healee = playerArray[2];
Console.WriteLine($"\nYou will heal {Healee.Name()}");
Thread.Sleep(1000);
Console.WriteLine("Healing...");
}
else if (k.KeyChar > 3 || k.KeyChar < 1)
{
Console.WriteLine("Choose which character you want to heal!");
continue;
}
if (Healee.GetHP() >= 12)
{
Thread.Sleep(1000);
Console.WriteLine($"{Healee.Name()} has full health! You can't heal them!");
EndTurn();
}
else if (Healee.GetHP() <= 0)
{
Thread.Sleep(1000);
Console.WriteLine($"{Healee.Name()} is dead! You can't heal them!");
EndTurn();
}
else
{
Healee.ApplyHealing(healing);
Thread.Sleep(2000);
Console.WriteLine($"{Healee.Name()} has been healed, and now has {Healee.GetHP()} HP!");
EndTurn();
}
I thought that adding the call to EndTurn() at the end of the HealAlly() method would cause the turn to end, but instead all it does is give me the delay message and then shoot back to the middle of the PlayerTurn() method. I'm sure it's because there was no Attacker set, but that's not what I want, because I don't want the player to be able to attack after healing.
Here is the EndTurn() method if that will help
bool EndTurn()
{
//switch turns for next loop
playerTurn = !playerTurn;
// loop through players to see if they're alive and store in a variable counting if they're alive or not
bool playersAlive = true;
for (int i = 0; i < playerArray.Length; i++)
{
if (playerArray[0].GetHP() <= 0 && playerArray[1].GetHP() <= 0 && playerArray[2].GetHP() <= 0)
{
playersAlive = false;
}
}
// same for rivals
bool rivalsAlive = true;
for (int i = 0; i < enemyArray.Length; i++)
{
if (enemyArray[0].GetHP() <= 0 && enemyArray[1].GetHP() <= 0 && enemyArray[2].GetHP() <= 0)
{
rivalsAlive = false;
}
}
// if both have things alive start the next round, pause the game, and return true to continue playing
if (playersAlive && rivalsAlive)
{
Console.WriteLine("Next Round Starts in 5 seconds");
Thread.Sleep(5000);
return true;
} // if only the players have members alive you win
else if (playersAlive)
{
//clear screen for results
Console.Clear();
//print you've won and parties
Console.WriteLine("Congrats you win! Final Standings:");
playerTurn = false;
PrintParties();
playerTurn = true;
PrintParties();
Thread.Sleep(5000);
Console.WriteLine("Thanks For Playing!");
Console.WriteLine("Press Any Key to Play Again");
Console.ReadKey();
Console.Clear();
Init();
return false;
} // only rival members are alive
else
{
//clear screen for results
Console.Clear();
//Print you've lost and parties
Console.WriteLine("You Lose :( Final Standings:");
playerTurn = false;
PrintParties();
playerTurn = true;
PrintParties();
Thread.Sleep(5000);
Console.WriteLine("Thanks For Playing!");
Console.WriteLine("Press Any Key to Play Again");
Console.ReadKey();
Console.Clear();
Init();
return false;
}
}
This is bugging me, can anyone help?
void PlayerTurn()
{
// ...
while (Attacker == null)
{
// ...
if (k.KeyChar == '5') {
HealAlly();
break;
}
}
// ...code that depends on Attacker...
}
The break statement here only causes the flow to break out of the while loop and continue with the code the depends on Attacker. If you want to leave the PlayerTurn() method altogether, replace the break; with a return;
sorry if this is a repeat question or sounds pretty stupid, but I'm really new to c# and looked throughout the forum and couldn't find anything that I could actually understand.
So I'm trying to write a simple program where the user tries to guess a number between 1 and 25. Everything works except that each run of the loop instead of updating the score from the last run of the loop, like 0+1=1, 1+1=2, 2+1=3, each time it adds 1 to 0. Here is my code. How do I fix this? Thank you!
int score = 0;
int add = 1;
while (add == 1)
{
Console.WriteLine("Guess A Number Between 1 and 25");
string input = Console.ReadLine();
if (input == "18")
{
Console.WriteLine("You Did It!");
Console.WriteLine("Not Bad! Your Score was " + score + add);
break;
}
else
{
Console.WriteLine("Try Again. Score: " + score + add);
}
}
You need to actually add add to score. Try something like this:
int score = 0;
int add = 1;
while (add == 1)
{
Console.WriteLine("Guess A Number Between 1 and 25");
string input = Console.ReadLine();
score += add; // add `add` to `score`. This is the same as `score = score + add;`
if (input == "18")
{
Console.WriteLine("You Did It!");
Console.WriteLine("Not Bad! Your Score was " + score);
break;
}
else
{
Console.WriteLine("Try Again. Score: " + score);
}
}
For 2 players in a console app the game draws numbers from 1 to 10 instead of cards. With a do-while loop asking the question, whether you want to choose a card. I have a problem with giving the right word after the answer not, because then the loop should be broken and when it gives break it asks still and how to return it exits the program at the end the program says who won.
`enter code here` Console.WriteLine("now the first player's turn");
int number = 0;
Random r = new Random();
` do
{
Console.WriteLine("Are you downloading the card?");
string odp = Console.ReadLine();
switch (odp)
{
case "yes":
int rInt = r.Next(1, 10);
number += rInt;
Console.WriteLine(number);
break;
case "not":
?
}
if (number >= 22)
{
Console.WriteLine("The player 1 lost with {0} pkt", number);
break;
}
} while (number < 22);
Here is a version that seems to do what you need with your current code.
I add a boolean condition (bool continuePlaying) to stay inside the "do loop" or not.
using System;
namespace BlackJack
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("First player's turn");
int number = 0;
Random random = new Random();
bool continuePlaying = true;
do
{
Console.WriteLine("Are you downloading the card? [Y]es/[N]o");
string userAnswer = Console.ReadLine();
switch (userAnswer.ToLower())
{
case "y":
int randomNumber = random.Next(1, 10);
number += randomNumber;
Console.WriteLine($"Your total of points is: {number}");
continuePlaying = true;
break;
case "n":
Console.WriteLine($"Your total of points is: {number}");
continuePlaying = false; // Stop playing
break;
default:
Console.Clear();
Console.WriteLine("Please choose [Y]es or [N]o");
continuePlaying = true;
break;
}
} while (number < 22 && continuePlaying == true);
if (number <= 21)
{
Console.WriteLine($"You end the game with a total of {number} points");
}
else
{
Console.WriteLine($"The player 1 lost with {number} points");
}
Console.ReadLine();
}
}
}
I'm trying to write a beginner program, where I roll 2 dies, and it tests the dies, if there's any evens it will say "evens are better then odds" and if there's a scenario where there's only odds it will say, "Odds are still cool", and after each roll it will ask the user if they want to play again, if not it will tell the user how many times they rolled the die. When I run the program, it will run, and ask the user if they want to roll again, when I type "YES" it runs infinitely. I don't know if the problem has to do with how my main method is written or if it's the TinasDice method.
I've tried going about using only the if/else statement in the main method where the user's input is tested, but that immediately exits out of the program.
TinasDice();
Console.WriteLine("Do you want to play again?");
string answer;
int counter = 0;
answer = Console.ReadLine();
while (answer == "YES")
{
if (answer == "YES")
{
TinasDice();
}
else
{
Console.WriteLine("The number of times the dice was die was thrown is: " + counter);
Console.WriteLine("Nice game!");
Console.WriteLine("Thanks for playing. Come play again soon!");
}
}
}
public static void TinasDice()
{
Random random = new Random();
int dice1 = new int();
int dice2 = new int();
dice1 = random.Next(1, 6);
dice2 = random.Next(1, 6);
Console.WriteLine("Hey Welcome to Tina's Dice Game.");
Console.WriteLine("Let's start!");
if (dice1 % 2 == 0 || dice2 % 2 == 0)
{
Console.WriteLine("I got " + dice1 + " and " + dice2);
Console.WriteLine("Evens are better then odds!");
}
else
{
Console.WriteLine("I got a " + dice1 + " and " + dice2);
Console.WriteLine("Odds ares still cool!");
}
I'm just trying to get the program to run incrementally after TinasDice is ran the first time, so when the user types "YES" it will run TinasDice once, and then prompt the user again, until the user types something else other then "YES".
Taking your example from above.
TinasDice();
Console.WriteLine("Do you want to play again?");
string answer = "YES";
int counter = 0;
while (answer == "YES")
{
answer = Console.ReadLine();
counter++;
if (answer == "YES")
{
TinasDice();
}
else
{
Console.WriteLine("The number of times the dice was die was thrown is: " + counter);
Console.WriteLine("Nice game!");
Console.WriteLine("Thanks for playing. Come play again soon!");
break;
}
}
}
Note the defaulting of the "YES" and the break
I'm trying to create a simple console game where you take care of yourself by feeding yourself.
using System;
namespace Project1
{
static class Program
{
static void Main(string[] args)
{
int hunger = 100;
Console.WriteLine("Enter your name: ");
string name = Console.ReadLine();
Console.WriteLine("Good choice, " + name);
Console.WriteLine("Press SPACE to continue");
while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Spacebar))
{
// do something
int h = hunger - 2;
}
Console.WriteLine("You are hungry," + name);
Console.WriteLine("Press F to feed");
while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.F))
{
// do something
int food = hunger;
}
}
}
}
How can I display the current hunger after a change is made too it? I want to display the food level so the player knows to feed it and does not accidentally over feed it. By any chance is there a way to go back to a earlier line so I don't need to copy and paste the thing forever and ever? Thanks.
It looks like this will be very broad to answer properly, so I'm going to leave it pretty abstract. You need to put reusable logic in methods. You need a "game loop" or "input loop". You need to learn about variables and passing them into methods.
You also may want to introduce a Player class as opposed to various variables to hold separate values.
Your game loop may look like this:
ConsoleKey input = null;
do
{
var player = DoGameLogic(input, player);
PrintGameInfo(player);
input = ReadInput(player);
}
while (input != ConsoleKey.Q)
When you got all this in order and you want to make the output look nice, take a look at Writing string at the same position using Console.Write in C# 2.0, Advanced Console IO in .NET.
You can modify the position of the cursor with Console.CursorLeft and Console.CursorTop and overwrite previous values.
Cursor.Left = 0;
Console.Write("Hunger: {0:0.00}", hunger);
EDIT: AS mentioned by "CodeMaster", you can do:
Console.Write("Test {0:0.0}".PadRight(20), hunger);
To make sure you have overwritten the previous data if it differs in length.
is this something you wanted to achieve:-
static void Main(string[] args)
{
const int MAX_FEED_LEVEL = 3; //configure it as per your need
const int HIGHEST_HUNGER_LEVEL = 0; //0 indicates the Extreme hunger
int hunger = MAX_FEED_LEVEL, foodLevel = HIGHEST_HUNGER_LEVEL;
string name = string.Empty;
char finalChoice = 'N', feedChoice = 'N';
Console.Write("Enter your name: ");
name = Console.ReadLine();
Console.Write("Good choice, {0}!", name);
Console.WriteLine();
do
{
Console.WriteLine();
Console.WriteLine("current hunger level : {0}", hunger);
if (hunger > 0)
Console.WriteLine("You are hungry, {0}", name);
Console.Write("Press F to feed : ");
feedChoice = (char)Console.ReadKey(true).Key;
if (feedChoice == 'F' || feedChoice == 'f')
{
if (foodLevel <= MAX_FEED_LEVEL && hunger > HIGHEST_HUNGER_LEVEL)
{
hunger = hunger - 1; //decrementing hunger by 1 units
foodLevel += 1; //incrementing food level
Console.WriteLine();
Console.WriteLine("Feeded!");
Console.WriteLine("Current Food Level : {0}", foodLevel);
}
else
{
Console.WriteLine();
Console.WriteLine("Well Done! {0} you're no more hungry!", name);
goto END_OF_PLAY;
}
}
else
{
Console.Clear();
Console.WriteLine();
Console.Write("You chose not to feed !");
}
Console.WriteLine();
Console.Write("want to continue the game ? (Y(YES) N(NO))");
finalChoice = (char)Console.ReadKey(true).Key;
} while (finalChoice == 'Y' || finalChoice == 'y');
END_OF_PLAY:
Console.WriteLine();
Console.Write("===GAME OVER===");
Console.ReadKey();
}