Vous êtes sur la page 1sur 29

1.

WHEEL OF FORTUNE
Source Code:
using System;
namespace WHEEL_OF_FORTUNE
{
class Program
{
public static void ScoreBoard(string player1, string player2, int player1mo
ney, int player2money)
{
Console.Write("\t\tContestant");
Console.WriteLine("\t\t\t Total $");
Console.Write("\t\t==========");
Console.WriteLine("\t\t\t =======");
Console.Write("\t\t{0}",player1);
Console.WriteLine("\t\t\t ${0}",player1money);
Console.Write("\t\t{0}",player2);
Console.WriteLine("\t\t\t ${0}",player2money);
}
public static void displayavailableletters(char[] availableletters,int coun
ter)
{
Console.Write("\t\t\t");
for (counter=0;counter<26;counter++)
{
Console.Write("{0}",availableletters[counter]);
}
Console.WriteLine("\n");
}
public static int spinthewheel(int randctr, string[] wheeloffortune)
{
spinagain:
Random rnd = new Random();
randctr = rnd.Next(0, 25);

if (wheeloffortune[randctr] != "_")
{
return randctr;
}
else
goto spinagain;
}
public static int playermove(int playerMov,int nume, char[] newarraycontain
er, int max,string player1,char[] availableletters,int counter,string player2,int p
layer1money, int player2money)
{playermovagain:
try{
Console.Clear();
GameTitleGenerator();
callphrase(nume,newarraycontainer,max);
Console.WriteLine("\t\t\t\t{0}'s turn",player1);
displayavailableletters(availableletters,counter);
ScoreBoard(player1,player2,player1money,player2money);
Console.WriteLine("\n\n\t\t\t+------------------+");
Console.WriteLine("\t\t\t| 1 - Spin / Guess |");
Console.WriteLine("\t\t\t| 2 - Buy a vowel |");
Console.WriteLine("\t\t\t| 3 - Solve
|");
Console.WriteLine("\t\t\t+------------------+");
Console.Write("\t\tChoose your option : ");

playerMov = int.Parse(Console.ReadLine());
if (playerMov>3 || playerMov<1)
{
invalidgenerator();
goto playermovagain;
}
return playerMov;
}catch(FormatException)
{
invalidgenerator();
goto playermovagain;
}
}
public static void Setting(string player1, string player2,string FirstMove)
{
Console.WriteLine("\n\n\t\t\t1 | Player 1's Name : {0} ",player1);
Console.WriteLine("\t\t\t2 | Player 2's Name : {0} ",player2);
Console.WriteLine("\t\t\t3 | First Turn
: {0} ",FirstMove);
Console.WriteLine("\t\t\t4 | Back
\n\n");
return;
}
public static int Settingscreen(string player1, string player2,string First
Move,int settings)
{
settingsagain:
try
{
Console.Clear();
GameTitleGenerator();
Setting(player1,player2,FirstMove);
Console.Write("\t\tModify : ");
settings = int.Parse(Console.ReadLine());
if (settings >4 || settings<1)
{
invalidgenerator();
goto settingsagain;
}
return settings;
}
catch(FormatException)
{
invalidgenerator();
goto settingsagain;
}
}
public static int menu(int menuselected)
{
startmenu:
try{
Console.Clear();
GameTitleGenerator();
Console.WriteLine("\n\n\t\t\t+-------------------------+");
Console.WriteLine("\t\t\t|
1 - Start Game
|");
Console.WriteLine("\t\t\t|
2 - Settings
|");
Console.WriteLine("\t\t\t|
3 - Exit
|");
Console.WriteLine("\t\t\t+-------------------------+\n");
Console.Write("\t\tSelect menu: ");
menuselected = int.Parse(Console.ReadLine());
if (menuselected>3 || menuselected <1)
{
invalidgenerator();
goto startmenu;
}
}

catch(FormatException)
{
invalidgenerator();
goto startmenu;
}
return menuselected;
}
public static void invalidgenerator()
{
Console.Clear();
Console.WriteLine("\n\n\n\n\n\t\t\t+-------------------------------+");
Console.WriteLine("\t\t\t| -+- | | | | .^. |
-+- |\\
|");
Console.WriteLine("\t\t\t| | |\\| | | |_| |
| | | |");
Console.WriteLine("\t\t\t| -+- | | \\/
| | +-- -+- |/
|");
Console.WriteLine("\t\t\t+--------------------------------+\n");
Console.WriteLine("\n\t\tPress any key to continue . . .");
Console.ReadKey(true);
return;
}
public static void GameTitleGenerator()
{
Console.Clear();
Console.WriteLine("\n\n\t+---------------------------------------------------------------+");
Console.WriteLine("\t| | | | | | +-- +-- |
+-+ +-- +-- +-+ +-+ +- | | | | +-- |");
Console.WriteLine("\t| | | | +-+ |- |- |
| | ||- | | ++ | | | |\\| |- |");
Console.WriteLine("\t| \\/ \\/ | | +-- +-- +-- +-+ |
|
+-+ |
\\ |
\\/| | | +-- |");
Console.WriteLine("\t+---------------------------------------------------------------+\n");
}
public static int Firstmovopt(int firstmov)
{Firstmovoptagain:
try{
Console.Clear();
GameTitleGenerator();
Console.WriteLine("\n\n\t\t+-----------------------------------------------+");
Console.WriteLine("\t\t|
1 - Player 1 | 2 - Player 2 | 3 Random
|");
Console.WriteLine("\t\t+-----------------------------------------------+\n");
Console.Write("\t\tSelect : ");
firstmov = int.Parse(Console.ReadLine());
if (firstmov >3 || firstmov <1)
{
invalidgenerator();
goto Firstmovoptagain;
}
return firstmov;
}
catch(FormatException)
{
invalidgenerator();
goto Firstmovoptagain;
}
}
public static char masking(int nume, char[] phraseexample, char[] newarrayc
ontainer)
{

if (phraseexample[nume] != '_')
{
newarraycontainer[nume] = '_';
//Console.Write("_");
return newarraycontainer[nume];
}
else
{
newarraycontainer[nume]=' ';
//Console.Write(" ");
return newarraycontainer[nume];
}
//
}
public static int firstrandom(int firstmov)
{
Random rnd = new Random();
firstmov = rnd.Next(1, 3);
return firstmov;
}
public static char Guess(char guessedchar,int nume, char[] newarraycontaine
r, int max,string player1,char[] availableletters,int counter,string player2,int pl
ayer1money, int player2money,int randctr,string[] wheeloffortune,string prize)
{guessagain:
try{
Console.Clear();
GameTitleGenerator();
callphrase(nume,newarraycontainer,max);
Console.WriteLine("\t\t\t\t{0}'s turn",player1);
displayavailableletters(availableletters,counter);
ScoreBoard(player1,player2,player1money,player2money);
Console.WriteLine("\n");
Console.WriteLine("\t\tWheel of space contains : $"+prize+"\n");
Console.Write("\t\tGuess a letter : ");
guessedchar = char.Parse(Console.ReadLine().ToUpper());
if (guessedchar=='0' || guessedchar=='1'|| guessedchar=='2'|| guess
edchar=='3'|| guessedchar=='4'|| guessedchar=='5'|| guessedchar=='6'|| guessedchar=
='7'|| guessedchar=='8'|| guessedchar=='9')
{
invalidgenerator();
goto guessagain;
}
return guessedchar;
}
catch(FormatException)
{
invalidgenerator();
goto guessagain;
}
}
public static void callphrase(int nume,char[] newarraycontainer,int max)
{
Console.Write("\t\t");
for (nume=0;nume<max;nume++)
{
Console.Write(newarraycontainer[nume]);
}Console.WriteLine("\n");
}
public static char checkphrase(char[] phraseexample,char guesschar, int num
e)
{
if (phraseexample[nume] == guesschar)
{return phraseexample[nume];}
else if (phraseexample[nume] == '_')
{return phraseexample[nume]=' ';}
else

{return phraseexample[nume] = '_';}


}
public static char checkletters(char guessedchar, char[] availableletters,i
nt counter)
{
if (availableletters[counter]==guessedchar)
{
return guessedchar='_';
}
return availableletters[counter];
}
public static void Main(string[] args)
{overagain:
string player1="Player 1", player2="Player 2", FirstMove="Random";
int player1money=0, player2money=0, counter=0, randctr=0, menuselected=
0, settings=0, firstmov = 3, turnctr= 0,playerMov=0,ctr=0;
char[] availableletters
= new Char[26] {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q'
,'R','S','T','U','V','W','X','Y','Z'};
string[] wheeloffortune
= new String[24] {"350","450","700","300","600","5000","600","500","850","500","800
","550","400","300","750","500","300","900","Bankrupt","600","400","300","Lose a
turn","900"};
char[] phraseexample
= new Char[]{'A','_','Q','U','I','C','K','_','B','R','O','P','N','_','F','O','X','_
','J','U','M','P','S','_','O','V','E','R','_','T','H','E','_','L','A','Z','Y','_','
D','O','G'};
char guessedchar=' ';
string phrasesolution = ("A QUICK BROWN FOX JUMPS OVER THE LAZY DOG");
int max = phraseexample.GetLength(0),nume=0;
char[] newarraycontainer = new Char[max];
Console.Write("\t\t");
for (nume=0;nume<max;nume++)
{
newarraycontainer[nume] = masking(nume, phraseexample, newarraycont
ainer);
}
Menu:
menuselected = menu(menuselected);
switch (menuselected)
{
case 1:
goto StartGame;
case 2:
settingmenu:
settings = Settingscreen(player1,player2,FirstMove,settings);
switch (settings)
{
case 1:
Console.Clear();
GameTitleGenerator();
Setting(player1,player2,FirstMove);
Console.Write("\t\tPlayer 1's Name : ");
player1 = Console.ReadLine();
goto settingmenu;
case 2:
Console.Clear();
GameTitleGenerator();
Setting(player1,player2,FirstMove);
Console.Write("\t\tPlayer 2's Name : ");
player2 = Console.ReadLine();
goto settingmenu;
case 3:

firstmov = Firstmovopt(firstmov);
switch (firstmov) {
case 1:
FirstMove = "Player 1";
break;
case 2:
FirstMove = "Player 2";
break;
case 3:
FirstMove = "Random";
break;
}
goto settingmenu;
case 4:
goto Menu;
}
break;
case 3:
goto exit;
}
StartGame:
Console.Clear();
GameTitleGenerator();
callphrase(nume,newarraycontainer,max);
if (firstmov==3) {
firstmov = firstrandom(firstmov);
}
turnctr = firstmov;
if (turnctr%2==1)
{
Console.WriteLine("\t\t\t\t{0}'s turn",player1);
displayavailableletters(availableletters,counter);
ScoreBoard(player1,player2,player1money,player2money);
playerMov
= playermove(playerMov,nume,newarraycontainer,max,player1,availableletters,counter,
player2,player1money,player2money);
switch (playerMov)
{
case 1:
Console.Clear();
string prize = wheeloffortune[randctr];
randctr = spinthewheel(randctr,wheeloffortune);
GameTitleGenerator();
callphrase(nume,newarraycontainer,max);
Console.WriteLine("\t\t\t\t{0}'s turn",player1);
displayavailableletters(availableletters,counter);
ScoreBoard(player1,player2,player1money,player2money);
Console.WriteLine("\n");
Console.WriteLine("\t\tWheel of space contains :
${0}\n",prize);
guessedchar
= Guess(guessedchar,nume,newarraycontainer,max,player1,availableletters,counter,pla
yer2,player1money,player2money,randctr,wheeloffortune,prize);
foreach (char guessedchar1 in phraseexample) {
if (guessedchar1==guessedchar)
ctr++;
}
if (ctr==0)
{goto Players2s;}
for (nume=0;nume<max;nume++)
{
newarraycontainer[nume] = checkphrase(phraseexample,gue

ssedchar, nume);
}
player1money += int.Parse( prize);
ctr =0;
goto Players2s;
case 2:
break;
case 3:
break;
}Players2s:
turnctr++;
}
if (turnctr%2==0)
{turnctr++;
Console.WriteLine("\t\t\t\t{0}'s turn",player1);
displayavailableletters(availableletters,counter);
ScoreBoard(player1,player2,player1money,player2money);
playerMov
= playermove(playerMov,nume,newarraycontainer,max,player1,availableletters,counter,
player2,player1money,player2money);
switch (playerMov)
{
case 1:
Console.Clear();
string prize = wheeloffortune[randctr];
randctr = spinthewheel(randctr,wheeloffortune);
GameTitleGenerator();
callphrase(nume,newarraycontainer,max);
Console.WriteLine("\t\t\t\t{0}'s turn",player1);
displayavailableletters(availableletters,counter);
ScoreBoard(player1,player2,player1money,player2money);
Console.WriteLine("\n");
Console.WriteLine("\t\tWheel of space contains :
${0}\n",prize);
guessedchar
= Guess(guessedchar,nume,newarraycontainer,max,player1,availableletters,counter,pla
yer2,player1money,player2money,randctr,wheeloffortune,prize);
foreach (char guessedchar1 in phraseexample) {
if (guessedchar1==guessedchar)
ctr++;
}
if (ctr==0)
{goto StartGame;}
for (nume=0;nume<max;nume++)
{
newarraycontainer[nume] = checkphrase(phraseexample,gue
ssedchar, nume);
}
player1money += int.Parse( prize);
ctr =0;
goto StartGame;
case 2:
break;
case 3:
break;
}

}
exit:
Console.Write("\n\t\tGoodbye!");
Console.ReadKey(true);
}
}
}

Output:

2. WHO WANTS TO BE A MILLIONAIRE?


Source Code:
using System;
using System.Linq;
namespace WhoWantsToBeAMillionaire
{
class Program
{
static Random r = new Random();
public static void Main(string[] args)
{
int a = 1;
int prize = 0,d = 0, e = 0;
string answer, finalanswer;
bool playing = true, repeat = true;
int [] noclone = new int[3];
int [] currentprize
= new int[] {100,200,300,400,500,1000,2000,5000,8000,16000,32000,64000,250000,50000
0,1000000};
Console.SetWindowSize(90, 55);
while(playing == true && a<=15)
{
chart(a);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\n\n\n\tPhp {0} Question",currentprize[a-1]);
Console.ForegroundColor = ConsoleColor.Green;
int n = r.Next(1,10);
if(d==3)
{
Array.Clear(noclone,0,noclone.Length);
d=0;
}
repeat = true;
while(repeat == true)

{
foreach ( int f in noclone)
{
if(f == n)
{
n = r.Next(1,10);
noclone[e] = n;
}
else
{
repeat = false;
}
e++;
}
e=0;
}
noclone[d] = n;
answer = questions(a,n);
Console.ResetColor();
Console.Write("\n\tWhat is your final answer: ");
finalanswer = Console.ReadLine();
while(finalanswer!= "a" && finalanswer!= "b" && finalanswer!= "c" &
& finalanswer!= "d")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\tInvalid answer please try again");
Console.ResetColor();
Console.Write("\n\tWhat is your final answer: ");
finalanswer = Console.ReadLine();
}
if(finalanswer != answer)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("\n\tYour answer is incorrect, The corrent answer
is ");
Console.ResetColor();
Console.WriteLine("{0}", answer);
if(a>=5)
{
prize = 1000;
}
else if (a >=10 )
{
prize = 3200;
}
else if (a >= 14)
{
prize = 1000000;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\n\t\t\t\t***********************\n");
Console.WriteLine("\t\t\t\t
You won {0} !\n", prize);
Console.WriteLine("\t\t\t\t***********************");
Console.ResetColor();
playing = false;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\tYour answer is correct!!\n");
Console.ResetColor();
if(a ==15)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\n\t\t\t******************************
***************\n");
Console.WriteLine("\t\t\tCongratulations!!! You are now a

millionaire!\n");
Console.WriteLine("\t\t\t**********************************
***********");
Console.ResetColor();
playing = false;
}
}
if(playing == true)
{
Console.Write("\tDo you want to continue playing for Php {0}?
\n\tPress any key to continue and n if not: ",currentprize[a]);
ConsoleKeyInfo key;
key = Console.ReadKey(true);
if(key.Key != ConsoleKey.N)
{
playing = true;
Console.Clear();
}
else
{
prize = currentprize[a-1];
playing = false;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\n\t\t\t\t***********************\n");
Console.WriteLine("\t\t\t\t
You won {0} !\n", prize);
Console.WriteLine("\t\t\t\t***********************");
Console.ResetColor();
}
}
a++;
d++;
}
Console.ReadKey(true);
} // end of public
static string questions(int b, int n)
{
int c = 0;
string answer = "";
c++;
if(b < 4)
{
if(n == 1)
{
line();
Console.WriteLine("\tWho is the current president of the United
States of America?\n\n");
Console.ForegroundColor = ConsoleColor.Green;
line();
Console.ResetColor();
Console.WriteLine("\ta. George W. Bush \t\t b. Bill Clinton ");
Console.WriteLine("\tc. Barack Obama \t\t d. Donald Trump ");
answer = "c";
}
else if ( n == 2)
{
line();
Console.WriteLine("\tComplete this line from Wham's classic
song, 'Last Christmas, I gave you ...'?\n");
line();
Console.WriteLine("\ta. My heart \t\t b. Roses ");
Console.WriteLine("\tc. Fine art \t\t d. Some tart ");
answer = "a";
}
else if ( n == 3)
{

line();
Console.WriteLine("\tWho had the longest term of being the
President of the Philippines?\n");
line();
Console.WriteLine("\ta. Emilio Aguinaldo \t\t b. Ferdinand
Marcos ");
Console.WriteLine("\tb. Manuel L. Quezon \t\t d. Gloria
Macapagal Arroyo ");
answer = "b";
}
else if(n == 4)
{
line();
Console.WriteLine("\tWhat is the largest mammal in the
world?\n");
line();
Console.WriteLine("\ta. Blue Whale \t\t b. Great White Shark
");
Console.WriteLine("\tc. Elephant \t\t d. Giraffe ");
answer = "a";
}
else if ( n == 5)
{
line();
Console.WriteLine("\tAn extremely pleasant situation is said to
be a bed of what?\n");
line();
Console.WriteLine("\ta. Chocolate \t\t b. Roses ");
Console.WriteLine("\tc. Bubbles \t\t d. Nails ");
answer = "b";
}
else if ( n == 6)
{
line();
Console.WriteLine("\tWhat famous Shakespeare characters last
words are Thus with a kiss I die?\n");
line();
Console.WriteLine("\ta. Leonardo \t\t b. Michael ");
Console.WriteLine("\tc. Romeo \t\t d. James ");
answer = "c";
}
else if(n == 7)
{
line();
Console.WriteLine("\tWhat is the fastest land animal in the
world?\n");
line();
Console.WriteLine("\ta. Lion \t\t b. Tiger ");
Console.WriteLine("\tc. Hyeana \t\t d. Cheetah ");
answer = "d";
}
else if ( n == 8)
{
line();
Console.WriteLine("\tWhat name is given to a playing card with
a single symbol on it?\n");
line();
Console.WriteLine("\ta. Whizz \t\t b. Hotshot ");
Console.WriteLine("\tc. Ace \t\t\t d. Star");
answer = "c";
}
else if ( n == 9)
{
line();
Console.WriteLine("\tWhich of these produce items is known for
having high levels of lycopene?\n");
line();
Console.WriteLine("\ta. Tomato \t\t b. Apple ");

Console.WriteLine("\tc. Banana \t\t d. Watermelon");


answer = "a";
}
} //end of 1
else if (b < 7)
{
if(n == 1)
{
line();
Console.WriteLine("\tWho is the founder of Microsoft
Corporation?\n");
line();
Console.WriteLine("\ta. Mark Zuckerberg \t\t b. Bob Barker ");
Console.WriteLine("\tc. Bill Gates \t\t\t d. Chuck Woolery ");
answer = "c";
}
else if ( n == 2)
{
line();
Console.WriteLine("\tWhat is the largest ocean in the
world?\n");
line();
Console.WriteLine("\ta. Arctic Ocean \t\t b. Indian Ocean ");
Console.WriteLine("\tc. Atlantic Ocean \t\t d. Pacific Ocean
");
answer = "d";
}
else if ( n ==3)
{
line();
Console.WriteLine("\tWhat is the most popular sport in the
world?\n");
line();
Console.WriteLine("\ta. Basketball \t\t b. Football ");
Console.WriteLine("\tc. Boxing \t\t d. Tennis ");
answer = "b";
}
else if(n == 4)
{
line();
Console.WriteLine("\tWhat is the fastest land animal in the
world?\n");
line();
Console.WriteLine("\ta. Lion \t\t b. Tiger ");
Console.WriteLine("\tc. Hyeana \t\t d. Cheetah ");
answer = "d";
}
else if ( n == 5)
{
line();
Console.WriteLine("\tWhat is Miley Cyrus'
line();
Console.WriteLine("\ta. Destiny Hope \t\t
Console.WriteLine("\tc. Sophia Miles \t\t
answer = "a";
}
else if ( n == 6)
{
line();
Console.WriteLine("\tWhat country has the

birthname?\n");
b. Claire ");
d. Tiffany ");

largest population in

2010?\n");
line();
Console.WriteLine("\ta. China \t\t b. USA ");
Console.WriteLine("\tc. India \t\t d. Russia ");
answer = "c";
}
else if(n == 7)

{
line();
Console.WriteLine("\tWhat is the tallest mountain above sea
level in the world?\n");
line();
Console.WriteLine("\ta. Mauna Kea \t\t b. Mt. Everest ");
Console.WriteLine("\tc. K2 \t\t\t d. Makalu ");
answer = "b";
}
else if ( n == 8)
{
line();
Console.WriteLine("\tHow many states does the USA have?\n");
line();
Console.WriteLine("\ta. 53 \t\t\t b. 55 ");
Console.WriteLine("\tc. 50 \t\t\t d. 49 ");
answer = "c";
}
else if ( n == 9)
{
line();
Console.WriteLine("\tStatue of Liberty is a gift to USA of what
European country?\n");
line();
Console.WriteLine("\ta. France \t\t\t b. Russia ");
Console.WriteLine("\tc. Italy \t\t\t d. Germany ");
answer = "a";
}
} //end of 2
else if (b < 10)
{
if(n == 1)
{
line();
Console.WriteLine("\tWhat is the oldest University in the
Philippines?\n");
line();
Console.WriteLine("\ta. UST \t\t b. UP ");
Console.WriteLine("\tc. PUP \t\t d. PNU ");
answer = "a";
}
else if ( n == 2)
{
line();
Console.WriteLine("\tWho holds the fastest record in 100m dash
in the Olympics?\n");
line();
Console.WriteLine("\ta. George Gelvin \t\t b. Michael Pelps ");
Console.WriteLine("\tc. Usain Bolt \t\t\t d. Lionnel Messi ");
answer = "c";
}
else if ( n ==3)
{
line();
Console.WriteLine("\tWhat is the international name of the
strongest typhoon to ever land in the Philippines on November 2013");
line();
Console.WriteLine("\ta. Ondoy \t\t b. Haiyan ");
Console.WriteLine("\tc. Katrina \t\t d. Veloso ");
answer = "b";
}
else if(n == 4)
{
line();
Console.WriteLine("\tWhat is the first computing device?\n");
line();
Console.WriteLine("\ta. Computer \t\t b. Calculator ");
Console.WriteLine("\tc. Abacus \t\t d. Cellphone ");

answer = "c";
}
else if ( n == 5)
{
line();
Console.WriteLine("\tWhere can we find the deepest part of the
earth?\n");
line();
Console.WriteLine("\ta. Indian Ocean \t\t b. Antarctica ");
Console.WriteLine("\tc. Great Barrie Reef \t\t d. Mariana
Trench ");
answer = "d";
}
else if ( n == 6)
{
line();
Console.WriteLine("\tWho is the player who holds the record for
most points scored in a single game in basketball?\n");
line();
Console.WriteLine("\ta. Wilt Chamberlain \t\t b. Michael Jordan
");
Console.WriteLine("\tc. Kobe Bryant \t\t\t d. Lebron James ");
answer = "a";
}
else if(n == 7)
{
line();
Console.WriteLine("\tWhere can we find the smallest fish in the
world");
line();
Console.WriteLine("\ta. Philippines \t\t b. Malaysia ");
Console.WriteLine("\tc. China \t\t d. Singapore ");
answer = "a";
}
else if ( n == 8)
{
line();
Console.WriteLine("\tPineapple shrimp, and lemon shrimp,
coconut shrimp, pepper shrimp is a line from what hit film?\n");
line();
Console.WriteLine("\ta. Foot Lose \t\t\t b. Crazy You ");
Console.WriteLine("\tc. Forrest Gump \t\t d. Monaco ");
answer = "c";
}
else if ( n == 9)
{
line();
Console.WriteLine("\tIn Greek mythology,who is the goddess of
the rainbow?\n");
line();
Console.WriteLine("\ta. Magenta \t\t b. Alps ");
Console.WriteLine("\tc. Ikea \t\t d. Iris ");
answer = "d";
}
} //end of 3
else if (b < 13)
{
if(n == 1)
{
line();
Console.WriteLine("\tWhat is the name of the first dog to reach
the space?\n");
line();
Console.WriteLine("\ta. Hachiko \t\t b. Brown ");
Console.WriteLine("\tc. Micah \t\t d. Laika ");
answer = "d";
}
else if ( n == 2)

{
line();
Console.WriteLine("\tWhich king was married to Eleanor of
Aquitaine?\n");
line();
Console.WriteLine("\ta. Henry I \t\t\t b. King Louis VI ");
Console.WriteLine("\tc. King Louis IV \t\t d. Henry II ");
answer = "b";
}
else if ( n == 3)
{
line();
Console.WriteLine("\tWhat is the largest bone of the human
body?\n");
line();
Console.WriteLine("\ta. Femur \t\t b. Skull ");
Console.WriteLine("\tc. Fibula \t\t d. Spinal Column ");
answer = "a";
}
else if(n == 4)
{
line();
Console.WriteLine("\tWhat is the name of the Emperor of China
who ordered the construction of the Great Wall of China?\n");
line();
Console.WriteLine("\ta. Kublai Khan \t\t b. Qin Shi Huang ");
Console.WriteLine("\tc. Taizong \t\t d. Kangxi ");
answer = "b";
}
else if ( n == 5)
{
line();
Console.WriteLine("\tWhat is the heaviest naturally occuring
element?\n");
line();
Console.WriteLine("\ta. Gold \t\t b. Uranium ");
Console.WriteLine("\tc. Tellerium \t\t d. Americium ");
answer = "b";
}
else if ( n == 6)
{
line();
Console.WriteLine("\tAs specified on his twitter page,Barbies
boyfriend Ken has what last name?\n");
line();
Console.WriteLine("\ta. Carrey \t\t b. Greenspan ");
Console.WriteLine("\tc. Crystal \t\t d. Carson ");
answer = "d";
}
else if(n == 7)
{
line();
Console.WriteLine("\tWhen did the Pearl Harbor Bombing
happen?\n");
line();
Console.WriteLine("\ta. November 4, 1942 \t\t b. December 7,
1942 ");
Console.WriteLine("\tc. December 7, 1941 \t\t d. December 9,
1941 ");
answer = "c";
}
else if ( n == 8)
{
line();
Console.WriteLine("\tWhich cartoon character has the reputation
of being the fastest mouse in all of Mexico?\n");
line();
Console.WriteLine("\ta. Zippy Zapata \t\t b. Speedy Gonzales

");
Console.WriteLine("\tc. Pacey Pepe \t\t\t d. Hasty Hernandez
");
answer = "b";
}
else if ( n == 9)
{
line();
Console.WriteLine("\tWhich of these is a three-stringed musical
instrument?\n");
line();
Console.WriteLine("\ta. Balaclava \t\t b. Balakirev ");
Console.WriteLine("\tc. Balalaika \t\t d. Balanchine ");
answer = "c";
}
} //end of 4
else if (b < 16)
{
if(n == 1)
{
line();
Console.WriteLine("\tOn November 22, 1963, President John F.
Kennedy is assinated by the man named _______?\n");
line();
Console.WriteLine("\ta. Robert Luketic \t\t b. Lee Harvey
Orwald ");
Console.WriteLine("\tc. Tom Selleck \t\t\t d. Ted Bundy ");
answer = "b";
}
else if ( n == 2)
{
line();
Console.WriteLine("\tWhat word describes plants with thick
fleshy leaves which store water?\n");
line();
Console.WriteLine("\ta. Delicious \t\t b. Sumptuous ");
Console.WriteLine("\tc. Succulent \t\t d. Scrumptious ");
answer = "c";
}
else if ( n ==3)
{
line();
Console.WriteLine("\tWhich of these is a term for an
actor?\n");
line();
Console.WriteLine("\ta. Equestrian \t\t b. Thespian ");
Console.WriteLine("\tc. Pedestrian \t\t d. Martian ");
answer = "b";
}
else if(n == 4)
{
line();
Console.WriteLine("\tWhich NBA team has the most number of
Championship rings");
line();
Console.WriteLine("\ta. Boston Celtics \t\t b. Dallas Mavericks
");
Console.WriteLine("\tc. Chicago Bulls \t\t d. Los Angeles
Lakers ");
answer = "a";
}
else if ( n == 5)
{
line();
Console.WriteLine("\tWhich of these is a carnivorous
plant?\n");
line();
Console.WriteLine("\ta. Mars anteater \t\t b. Saturn spidernet

");
Console.WriteLine("\tc. Pluto bugsnare \t\t d. Venus flytrap
");
answer = "d";
}
else if ( n == 6)
{
line();
Console.WriteLine("\tWho was not a Roman emperor?\n");
line();
Console.WriteLine("\ta. Hadrian \t\t b. Parallax ");
Console.WriteLine("\tc. Claudius \t\t d. Tiberius ");
answer = "b";
}
else if(n == 7)
{
line();
Console.WriteLine("\tWhich novel by Charles Dickens was made
into a film in 2002?\n");
line();
Console.WriteLine("\ta. Danny Dimeby \t\t b. Nicholas Nickleby
");
Console.WriteLine("\tc. Quentin Quarterby \t\t d. Donald
Dollarby ");
answer = "b";
}
else if ( n == 8)
{
line();
Console.WriteLine("\tWhich of these is a Scottish district
council?\n");
line();
Console.WriteLine("\ta. Inverchristopher \t\t b. Inverclyde ");
Console.WriteLine("\tc. Inverclint \t\t\t d. Invercharles ");
answer = "b";
}
else if ( n == 9)
{
line();
Console.WriteLine("\tWhich aircraft was so named because of the
distinctive 'hump' in front of the pilot's cockpit?\n");
line();
Console.WriteLine("\ta. Vickers Vimy \t\t b. Sopwith Camel ");
Console.WriteLine("\tc. Bristol Bulldog \t\t d. Gloster
Gladiator ");
answer = "b";
}
}
return answer;
}//end of one
static void line()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(" ---------------------------------------------------------------------------------------\n");
Console.ResetColor();
}
static int chart(int b)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("\n\t\t\t
________________________________");
Console.WriteLine("\t\t\t
|\t\t\t\t
|");
Console.WriteLine("\t\t\t
| Who Wants to be a Millionaire? |");
Console.WriteLine("\t\t\t
|________________________________|");
Console.ResetColor();

int z = 0;
int [] currentprize
= new int[] {100,200,300,400,500,1000,2000,5000,8000,16000,32000,64000,250000,50000
0,1000000};
Console.WriteLine("\n\n\t\t\t\t Question # \t Value");
for (int i = 0; i < 15; i++)
{
if(i == (b-1))
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else
{
Console.ResetColor();
}
if (i == 0)
{
Console.WriteLine("\t\t\t\t -------------------------");
Console.WriteLine("\t\t\t\t|
{0}
| Php
{1}
|",i+1, currentprize[i]);
Console.WriteLine("\t\t\t\t -------------------------");
}
else if(i <9)
{
if(i <5)
{
{1}

Console.WriteLine("\t\t\t\t|
|",i+1, currentprize[i]);
Console.ResetColor();
}

{0}

Php

else
{
{1}

{1}

{1}

{1}

Console.WriteLine("\t\t\t\t|
{0}
| Php
|",i+1, currentprize[i]);
Console.ResetColor();
}
Console.WriteLine("\t\t\t\t|-------------------------|");
}
else
{
if(i<12)
{
Console.WriteLine("\t\t\t\t|
{0}
| Php
|",i+1, currentprize[i]);
Console.ResetColor();
Console.WriteLine("\t\t\t\t|-------------------------|");
}
else if(i ==14)
{
Console.WriteLine("\t\t\t\t|
{0}
| Php
|",i+1, currentprize[i]);
Console.ResetColor();
Console.WriteLine("\t\t\t\t -------------------------");
}
else
{
Console.WriteLine("\t\t\t\t|
{0}
| Php
|",i+1, currentprize[i]);
Console.ResetColor();
Console.WriteLine("\t\t\t\t|-------------------------|");
}
}
}
return z;
} //end of chart

}
}

Output:

3. MEMORY GAME PROGRAM


Source Code:
using
using
using
using
using

System;
System.Threading;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Memory_Game

{
class Program
{
static void prompt(char[,] Flipped,out int row,out int col)
{
Console.SetCursorPosition(0, 17);
Console.Write("Please enter row: ");
row = Check();
Console.SetCursorPosition(0, 17);
Console.Write("Please enter Col: ");
col = Check();
Console.SetCursorPosition(1 + (col * 3), 4 + (row * 2));
Console.Write(Flipped[row, col]);
}
static int Check()
{
int num;
again:
try
{
Console.Write(" ");
Console.SetCursorPosition(18, 17);
num = int.Parse(Console.ReadLine());
if (num < 0 || num > 4)
{
Console.SetCursorPosition(18, 17);
goto again;
}
}
catch (System.Exception )
{
Console.SetCursorPosition(18, 17);
Console.Write("");
goto again;
}
return num;
}
static Random rand = new Random();
static void Main(string[] args)
{
int n = 0, row = 0,col=0 ,temprow=0,tempcol=0,turn=0;
char[] Cards= new char[16] {'1','1','2','2','3','3','4','4','5','5','6','
6','7','7','8','8'};
char[] ShuffleCards
= new char[16]{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'};
foreach (char Card in Cards)
{
bool failed = true;
while (failed)
{
n=rand.Next(0,16);
if (ShuffleCards[n] == '*')
{
ShuffleCards[n] = Card;
failed = false;
}
}
}
char[,] Flipped = new char[5, 5];
n = 0;
for (int a = 1; a < 5; a++)
{

for (int b = 1; b < 5;b++ )


{
Flipped[a, b] = ShuffleCards[n];
//Console.Write(ShuffleCards[n]);
n++;
}
}
bool game = true;
Console.WriteLine("***Memory Game*** \n\n");
Console.WriteLine("
1 2 3 4 ");//10
Console.WriteLine(" -------------- ");//10
Console.WriteLine(" |
|");//17
Console.WriteLine("1| * * * * |"); //(8,4)
Console.WriteLine(" |
|");
Console.WriteLine("2| * * * * |");
Console.WriteLine(" |
|");
Console.WriteLine("3| * * * * |");
Console.WriteLine(" |
|");
Console.WriteLine("4| * * * * |");
Console.WriteLine(" |
|");
Console.WriteLine(" -------------- ");
while (game)
{
prompt(Flipped,out row,out col);
do
{
prompt(Flipped,out temprow,out tempcol);
} while (tempcol==col && temprow==row);
System.Threading.Thread.Sleep(2000);
if (Flipped[row, col] != Flipped[temprow, tempcol])
{
Console.SetCursorPosition(1 + (col * 3), 4 + (row * 2));
Console.Write('*');
Console.SetCursorPosition(1 + (tempcol * 3), 4 + (temprow * 2));
Console.Write('*');
}
}
Console.ReadKey(true);
}
}
}

Output:

4. BINGO CARD
Source Code:
using
using
using
using

System;
System.Linq;
System.Collections.Generic;
System.Threading;

namespace BingoCard
{
class Program
{
public static
public static
public static
public static
public static

string[] B1 = new string[25];


string[] B2 = new string[25];
int num;
Random randNum = new Random();
int chck;

public static void Main(string[] args)


{
List<int> list = new List<int>();
rndom(B1, 1, 26);
rndom(B2, 1, 26);
do
{
do
{
num = randNum.Next(1,26);
}while (list.Contains(num));
list.Add(num);
Console.WriteLine("Random number is: {0}\n", num );
Display();
Fill();
chck = Check();
Console.ReadKey();
Console.Clear();
}while(chck != 1 && chck != 2);
Display();
switch (chck) {

case 1:
Console.WriteLine("\nPlayer 1 Wins");
Console.ReadKey();
break;
case 2:
Console.WriteLine("\nPlayer 2 Wins");
Console.ReadKey();
break;
}
}
public static void rndom (string[] letter, int min, int max)
{
int rand = 0;
for (int i = 0; i < letter.Length; i++)
{
do
{
rand = randNum.Next(min, max);
}
while(letter.Contains(rand.ToString()));
letter[i] = rand.ToString();
}
}

{4}\t",
{4}\t",
{4}\t",
{4}\t",
{4}\t",

{4}\t",
{4}\t",
{4}\t",
{4}\t",
{4}\t",

public static void Display()


{
Console.WriteLine("Player 1 Card:\n");
Console.WriteLine(" B \t I \t N \t G \t O\n");
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B1[0], B1[5], B1[10], B1[15], B1[20]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B1[1], B1[6], B1[11], B1[16], B1[21]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B1[2], B1[7], B1[12], B1[17], B1[22]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B1[3], B1[8], B1[13], B1[18], B1[23]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B1[4], B1[9], B1[14], B1[19], B1[24]);
Console.WriteLine("\nPlayer 2 Card:\n");
Console.WriteLine(" B \t I \t N \t G \t O\n");
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B2[0], B2[5], B2[10], B2[15], B2[20]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B2[1], B2[6], B2[11], B2[16], B2[21]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B2[2], B2[7], B2[12], B2[17], B2[22]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B2[3], B2[8], B2[13], B2[18], B2[23]);
Console.WriteLine("{0}\t {1}\t {2}\t {3}\t
B2[4], B2[9], B2[14], B2[19], B2[24]);
}
public static void Fill()
{
if(B1.Contains(num.ToString()) || B2.Contains(num.ToString()))
{
int posB1 = Array.IndexOf(B1, num.ToString());
int posB2 = Array.IndexOf(B2, num.ToString());
B1[posB1] = "X";
B2[posB2] = "X";
}
}
public static int Check()
{
if (B1[0] == B1[5] && B1[5] == B1[10] && B1[10] == B1[15] && B1[15] ==

B1[20])

B1[16] &&
B1[17] &&
B1[18] &&
B1[19] &&

return 1;
else if (B1[1] ==
B1[16] == B1[21])
return 1;
else if (B1[2] ==
B1[17] == B1[22])
return 1;
else if (B1[3] ==
B1[18] == B1[23])
return 1;
else if (B1[4] ==
B1[19] == B1[24])
return 1;
else if (B1[0] ==

B1[6] && B1[6] == B1[11] && B1[11] ==


B1[7] && B1[7] == B1[12] && B1[12] ==
B1[8] && B1[8] == B1[13] && B1[13] ==
B1[9] && B1[9] == B1[14] && B1[14] ==
B1[1] && B1[1] == B1[2] && B1[2] == B1[3] && B1[3] ==

B1[4])
return 1;
else if (B1[5] == B1[6] && B1[6] == B1[7] && B1[7] == B1[8] && B1[8] ==
B1[9])
return 1;
else if (B1[10] == B1[11] && B1[11]
B1[13] && B1[13] == B1[14])
return 1;
else if (B1[15] == B1[16] && B1[16]
B1[18] && B1[18] == B1[19])
return 1;
else if (B1[20] == B1[21] && B1[21]
B1[23] && B1[23] == B1[24])
return 1;
else if (B1[0] == B1[6] && B1[7] ==
B1[12] && B1[18] == B1[24])
return 1;
else if (B1[20] == B1[16] && B1[16]
B1[8] && B1[8] == B1[4])
return 1;
else if (B2[0] == B2[5] && B2[5] ==
B2[15] && B2[15] == B2[20])
return 2;
else if (B2[1] == B2[6] && B2[6] ==
B2[16] && B2[16] == B2[21])
return 2;
else if (B2[2] == B2[7] && B2[7] ==
B2[17] && B2[17] == B2[22])
return 2;
else if (B2[3] == B2[8] && B2[8] ==
B2[18] && B2[18] == B2[23])
return 2;
else if (B2[4] == B2[9] && B2[9] ==
B2[19] && B2[19] == B2[24])
return 2;
else if (B2[0] == B2[1] && B2[1] ==
B2[4])
return 2;
else if (B2[5] == B2[6] && B2[6] ==
B2[9])
return 2;
else if (B2[10] == B2[11] && B2[11]
B2[13] && B2[13] == B2[14])
return 2;
else if (B2[15] == B2[16] && B2[16]
B2[18] && B2[18] == B2[19])
return 2;
else if (B2[20] == B2[21] && B2[21]
B2[23] && B2[23] == B2[24])
return 2;
else if (B2[0] == B2[6] && B2[7] ==
B2[12] && B2[18] == B2[24])
return 2;
else if (B2[20] == B2[16] && B2[16]
B2[8] && B2[8] == B2[4])
return 2;

== B1[12] && B1[12] ==


== B1[17] && B1[17] ==
== B1[22] && B1[22] ==
B1[6] && B1[12] ==
== B1[12] && B1[12] ==
B2[10] && B2[10] ==
B2[11] && B2[11] ==
B2[12] && B2[12] ==
B2[13] && B2[13] ==
B2[14] && B2[14] ==
B2[2] && B2[2] == B2[3] && B2[3] ==
B2[7] && B2[7] == B2[8] && B2[8] ==
== B2[12] && B2[12] ==
== B2[17] && B2[17] ==
== B2[22] && B2[22] ==
B2[6] && B2[12] ==
== B2[12] && B2[12] ==

else
return 0;
}
}
}

Output:

5. BATTLESHIPS GAME
Source Code:
using System;
namespace Battleship
{
class Program
{
static string[,] board = new String[8,8];
static string[,] board2 = new String[8,8];
static string[,,] checkBoard = new String[8,8,1];
static Random row = new Random();
static Random col = new Random();
static Random number = new Random();
static int a=0, b=0, c=0, score1=0, score2=0, ctr=0;
static bool finish = false;
public static void Main()
{
if(finish == false){
setBoard();
show();
play();
}
else if(finish == true){
}
Console.ReadKey(true);
}
public static void setBoard(){
for(c=0; c<8; c++){
for(a=0; a<8; a++){
board[a, col.Next(0,8)] = "x";
}

}
for(c=0; c<3; c++){
for(a=0; a<8; a++){
board[a, col.Next(0,8)] = ".";
}
}
for(a=0; a<8; a++){
for(b=0; b<8; b++){
if(board[a,b] == null){
board[a,b] = "*";
}
else if((board[a,b] == "x")||(board[a,b] == ".")){
goto skip;
}
skip:
Console.Write("");
}
}
for(a=0; a<8; a++){
for(b=0; b<8; b++){
board2[a,b]="?";
}
}
}
public static void show(){
for(a=0; a<8; a++){
for(b=0; b<8; b++){
Console.Write("{0} ", board2[a,b]);
}
Console.WriteLine();
Console.WriteLine();
}
}
public static void play(){
go:
Console.WriteLine(">>Player 1");
again:
Console.Write("Choose row: ");
a = int.Parse(Console.ReadLine())-1;
Console.Write("Choose column: ");
b = int.Parse(Console.ReadLine())-1;
if((a>8) || (a<0) || (b>8) || (b<0)){
Console.WriteLine("Row and column not existing.");
goto again;
}
else if(checkBoard[a,b,0] == "1"){
Console.WriteLine("Row and column has already been selected.");
goto again;
}
check(a,b);
show();
Console.WriteLine(">>Player 2");
again2:
Console.WriteLine("Choose row: ");
a = int.Parse(Console.ReadLine())-1;
Console.WriteLine("Choose column: ");
b = int.Parse(Console.ReadLine())-1;
if((a>8) || (a<0) || (b>8) || (b<0)){
Console.WriteLine("Row and column not existing.");
goto again2;
}
else if(checkBoard[a,b,0] == "1"){
Console.WriteLine("Row and column has already been selected.");
goto again2;
}
check(a,b);
show();

for(a=0; a<8; a++){


for(b=0; b<8; b++){
if(checkBoard[a,b,0] == "1"){
ctr++;
}
else
Console.Write("");
}
if(ctr==64){
goto end;
}
else
goto go;
}
end:
Console.WriteLine("***THE SCORE***");
Console.WriteLine("Player 1: {0}", score1);
Console.WriteLine("Player 2: {0}", score2);
finish = true;
Main();
}
public static void check(int rw, int cl){
if(board[rw,cl]=="."){
Console.WriteLine("OWWW! That's a miss!");
board2[rw,cl] = board[rw,cl];
checkBoard[rw,cl,0] = "1";
}
else if(board[rw,cl]=="x"){
Console.WriteLine("BANG! You've hit a battleship! +1 point");
board2[rw,cl] = board[rw,cl];
checkBoard[rw,cl,0] = "1";
}
else if(board[rw,cl]=="*"){
Console.WriteLine("BOOM! That's a bomb! -1 point");
board2[rw,cl] = board[rw,cl];
checkBoard[rw,cl,0] = "1";
}
}
}
}

Output:

Object Oriented Programming

Midterm Practical Exam

Submitted by:
Adique, Jeadalyn P.
Largo, Jeff Ray L.
Varias, Ervin Miguel L.
BSCpE V-3
Submitted to:
Engr. Julius S. Cansino

Vous aimerez peut-être aussi