Aguirre Prog Lang TP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Game 1: Simple RPG game

The first game is a simple rpg game. The player will be given options, fight , rest, or quit.
When the player chooses to fight, he/she will generate a random attack damage to the monster.
He wins when the monster dies, and loses when his hp runs out.
Game 2: Guess the Number

The player guesses a number from 1-100. It will show if the number is too high or too
low. When the player guesses wrong he will be asked to give another number. When he
guesses right he will win.
CODES

SIMPLE RPG
using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to Simple RPG Game!");
Console.WriteLine("Create your character:");

Character player = CreateCharacter();

Console.WriteLine("Your journey begins...");

while (true)
{
Console.WriteLine("\nChoose an action:");
Console.WriteLine("1. Fight");
Console.WriteLine("2. Rest");
Console.WriteLine("3. Quit");

string choice = Console.ReadLine();

switch (choice)
{
case "1":
Fight(player);
break;
case "2":
Rest(player);
break;
case "3":
Console.WriteLine("Thanks for playing!");
return;
default:
Console.WriteLine("Invalid choice. Try again.");
break;
}
}
}

static Character CreateCharacter()


{
Console.Write("Enter your character's name: ");
string name = Console.ReadLine();
return new Character(name, 100, 10);
}

static void Fight(Character player)


{
Random rand = new Random();
int enemyHealth = rand.Next(20, 51); // Random health between 20 and 50
int enemyAttack = rand.Next(5, 16); // Random attack between 5 and 15

Console.WriteLine($"A monster appears with {enemyHealth} health and


{enemyAttack} attack!");

while (true)
{
Console.WriteLine("\n1. Attack");
Console.WriteLine("2. Run");

string choice = Console.ReadLine();

switch (choice)
{
case "1":
// Player attacks the enemy
int damageDealt = rand.Next(player.Attack - 5, player.Attack + 6);
enemyHealth -= damageDealt;
Console.WriteLine($"You deal {damageDealt} damage to the enemy.");

if (enemyHealth <= 0)
{
Console.WriteLine("You defeated the monster!");
return;
}

// Enemy attacks the player


int damageReceived = rand.Next(enemyAttack - 5, enemyAttack + 6);
player.Health -= damageReceived;
Console.WriteLine($"The enemy deals {damageReceived} damage to you.
Your health: {player.Health}");

if (player.Health <= 0)
{
Console.WriteLine("You were defeated by the monster!");
return;
}
break;
case "2":
Console.WriteLine("You ran away!");
return;
default:
Console.WriteLine("Invalid choice. Try again.");
break;
}
}
}

static void Rest(Character player)


{
Console.WriteLine("You rest and regain some health.");
player.Health += 20;
if (player.Health > 100)
player.Health = 100;
Console.WriteLine($"Your health is now {player.Health}");
}
}

class Character
{
public string Name { get; set; }
public int Health { get; set; }
public int Attack { get; set; }

public Character(string name, int health, int attack)


{
Name = name;
Health = health;
Attack = attack;
}
}
CODES

GUESS THE NUMBER

using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to Guess the Number Game!");
Console.WriteLine("I have selected a random number between 1 and 100.");

Random random = new Random();


int randomNumber = random.Next(1, 101);
int attempts = 0;
bool guessedCorrectly = false;

while (!guessedCorrectly)
{
Console.Write("Enter your guess: ");
string input = Console.ReadLine();

if (!int.TryParse(input, out int guess))


{
Console.WriteLine("Invalid input. Please enter a valid number.");
continue;
}

attempts++;

if (guess < randomNumber)


{
Console.WriteLine("Too low! Try again.");
}
else if (guess > randomNumber)
{
Console.WriteLine("Too high! Try again.");
}
else
{
guessedCorrectly = true;
Console.WriteLine($"Congratulations! You guessed the number
{randomNumber} correctly in {attempts} attempts.");
}
}
}
}

You might also like