Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

VISUAL BASIC PROGRAM:

RIDDLE GAME
TABLE OF CONTENTS

TITLE Page No.

Title Page.................................................................................................................0
Table of Content......................................................................................................1
Project Description..................................................................................................2
Algorithm/Pseudocode............................................................................................4
Program Flowchart..................................................................................................5
Source Code.............................................................................................................6
Output Of the System..............................................................................................12
PROJECT DESCRIPTION

The Riddle Game is an interactive console program designed to challenge

and entertain players with a series of intriguing riddles. Put your problem-

solving skills to the test as you attempt to solve the riddles presented to

you.

Features:

1. Diverse Riddle Collection: The game offers a collection of carefully

selected riddles that will engage and stimulate your mind. Each riddle

presents a unique challenge, encouraging you to think creatively and

find the correct answer.

2. Randomized Riddles: With each new game session, the riddles are

randomly selected from a pool of challenging brain teasers. This

ensures that every gameplay experience is different and keeps you

on your toes.

3. Score Tracking: The game keeps track of your score, allowing you to

see how many riddles you have answered correctly. Challenge

yourself to achieve a perfect score!

4. Surrender Option: If you find yourself stumped or need to end the

game prematurely, you have the option to surrender. This provides

flexibility and allows you to control your gameplay experience.


5. User-Friendly Interface: The program features a user-friendly

interface, making it easy to read and interact with the riddles. Simply

type in your answer and receive immediate feedback on your

response.

The Riddle Game is a fun and intellectually stimulating program suitable for

players of all ages. Sharpen your problem-solving skills, expand your

knowledge, and enjoy the thrill of unraveling riddles. Are you up for the

challenge? Start playing the Riddle Game today and put your wits to the

test!
ALGORITHM/PSEUDOCODE

1. Initialize the variables:


- riddles: 2-dimensional array containing riddles and their answers
- random: Random object for generating random numbers
- score: Integer variable to track the player's score
- riddlesAnswered: Integer variable to count the number of riddles answered
- continuePlaying: Boolean variable to control the game loop
- askedRiddles: List to keep track of the riddles already asked
2. Display the welcome message and instructions to the player.
3. Enter the game loop:
- Check if the game should continue (continuePlaying is True) and the number of
riddles answered is less than 20.
- Generate a random index (randomIndex) for selecting a riddle from the riddles
array. Ensure the selected riddle has not been asked before by checking
askedRiddles.
- Add the randomIndex to askedRiddles and increment riddlesAnswered.
4. Retrieve the riddle and answer using the randomIndex.
5. Display the riddle number and the riddle to the player.
6. Prompt the player for their answer.
7. Check the user's answer:
- If the user enters "surrender", display a message indicating surrender and set
continuePlaying to False.
- If the user's answer matches the correct answer (case-insensitive), display
"Correct!" and increment the score.
- If the user's answer doesn't match exactly, but matches when ignoring the
case, display "Correct!" and increment the score.
- If none of the above conditions are met, display "Wrong!" along with the
correct answer.
8. Print a blank line for spacing.
9. End of the game loop.
10. Display the player's score.
11. Display a message to exit the game.
12. Wait for the player to press any key to exit.
PROGRAM FLOWCHART
SOURCE CODE

Module Module1

Sub Main()

Dim riddles As String(,) = {{"Many have heard me, but nobody has seen me, and
I will not speak back until spoken to. What am I?", "echo"},
{"I am taken from a mine, and shut up in a wooden
case, from which I am never released, and yet I am used by almost every person. What
am I?", "pencil"},
{"What has keys but can't open locks?", "piano"},
{"What has a heart that doesn't beat?",
"artichoke"},
{"I am full of holes but still holds water. What
am I?", "sponge"},
{"The more you take, the more you leave behind.
What am I?", "footsteps"},
{"I have cities but no houses, forests but no
trees, and rivers but no water. What am I?", "Map"},
{"What comes once in a minute, twice in a moment,
but never in a thousand years?", "M"},
{"I am the beginning of the end, the end of every
place. I am the beginning of eternity, the end of time and space. What am I?", "E"},
{"What can go through glass without breaking it?",
"light"},
{"Take off my skin, I won't cry but you wil.",
"Onion"},
{"If I drink, I die. If I eat, I'm fine. What am
i?", "Fire"},
{"SINONG BOSS", "IVAN"},
{"What has a face and two hands but no arms or
legs?", " clock"},
{"I have keys but no locks. I have space but no
room. You can enter but can't go outside. What am I?", " keyboard"},
{"SI BOSS IVAN AY ", "ASO"},
{"I am an odd number. Take away a letter and I
become even. What number am I?", "seven"},
{"KUNG AKO AY PUGE, ANO KA?", "TAE, NYEE"},
{"AYAN NA AYAN NA HINDI MOPA MAKITA", "HANAPIN
MO"},
{"PINASOK KO NG MALABOT, HINUGOT KO NG MATIGAS",
"TI? YELO"}}

Dim random As New Random()


Dim score As Integer = 0
Dim riddlesAnswered As Integer = 0
Dim continuePlaying As Boolean = True
Dim askedRiddles As New List(Of Integer)
Console.WriteLine("Welcome to the Riddle Game!")
Console.WriteLine("Type 'surrender' to give up.")
Console.WriteLine()

While continuePlaying AndAlso riddlesAnswered < 20


Dim randomIndex As Integer
Do
randomIndex = random.Next(0, riddles.GetLength(0))
Loop While askedRiddles.Contains(randomIndex)

askedRiddles.Add(randomIndex)
riddlesAnswered += 1

Dim riddle As String = riddles(randomIndex, 0)


Dim answer As String = riddles(randomIndex, 1)

Console.WriteLine("Riddle #" & riddlesAnswered & ":")


Console.WriteLine(riddle)
Console.Write("Your answer: ")

Dim userAnswer As String = Console.ReadLine().ToLower()

Select Case userAnswer


Case "surrender"
Console.WriteLine("You surrendered!")
continuePlaying = False
Case answer
Console.WriteLine("Correct!")
score += 1
Case Else
If String.Equals(userAnswer, answer,
StringComparison.OrdinalIgnoreCase) Then
Console.WriteLine("Correct! The answer is : " & answer)
score += 1
Else
Console.WriteLine("Wrong! The correct answer is: " & answer)
End If
End Select

Console.WriteLine()
End While

Console.WriteLine()
Console.WriteLine("Your score: " & score & " / 20")
Console.WriteLine("Press any key to exit...")
Console.ReadKey()

End Sub

End Module
OUTPUT OF THE SYSTEM

You might also like