You are on page 1of 11

ACTIVITY

5
CPEPROGLA1
JACK AND POY GAME

GRADE

NAME: MARIA KRISTEL ZAIRA MACA SIGNATURE:

DATE PERFORMED: OCTOBER 14, 2016

DATE SUBMITTED: OCTOBER 28, 2016

PROFESSOR HONEYLET GRIMALDO

Professor

CODE COMPILATION:
// This programs shows a Jack and Poy game.
#include<iostream>
#include<string.h>
#include<windows.h>
using namespace std;
WORD GetConsoleTextAttribute (HANDLE hCon)
{
CONSOLE_SCREEN_BUFFER_INFO con_info;
GetConsoleScreenBufferInfo(hCon, &con_info);
return con_info.wAttributes;
}
int main ()
{
// Personal information of the programmer
cout << "Maria Kristel Zaira G. Maca" << endl;
cout << "BSME K-23" << endl;
char X; // Rock
char Y; // Paper
char W; // Scissors
char P1; // Player one
char P2; // Player two
int a=0; // Score 1
int b=0; // Score 2
int c; // Rounds
char choice[10];
cout << "Choose player number: \nPlayer 1 or Player 2?" <<endl;
cin.getline(choice,10);
for (c=1;c<=10;c++)
{
m:
cout << "Player 1: ";
cin >> P1;
cout << "Player 2: ";
cin >> P2;
// Applicable for small letters only.
if ((P1=='y') && (P2=='x') || (P1=='y') && (P2=='w') || (P1=='w') && (P2=='x'))
{
a++;
cout << "Player 2 WINS" << endl;
cout << "Score " << a << endl;
}
else if ((P1=='x') && (P2=='y') || (P1=='w') && (P2=='y') || (P1=='x') &&
(P2=='w'))
{
b++;
cout << "Player 1 WINS" << endl;

cout << "Score " << b << endl;


}
else if ((P1=='x') && (P2=='x') || (P1=='w') && (P2=='w') || (P1=='y') &&
(P2=='y'))
{
cout << "DRAW" << endl;
}
else if (!((P1=='x') || (P2=='x') || (P1=='w') || (P2=='w') || (P1=='y') || (P2=='y')))
{
cout << "INVALID" << endl;
goto m;
}
}
system("cls");
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
const int saved_colors = GetConsoleTextAttribute(hConsole);
if (b>a)
{
cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE |
FOREGROUND_INTENSITY);
cout << "Player 1 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED |
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_RED |
FOREGROUND_INTENSITY);
cout << "Player 1 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE |
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN |
FOREGROUND_INTENSITY);

cout << "Player 1 WINS!" << endl;


SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE |
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE |
FOREGROUND_INTENSITY);
cout << "Player 1 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED |
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE |
FOREGROUND_INTENSITY);
cout << "Player 1 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED |
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");
}
if (b<a)
{
cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|
FOREGROUND_INTENSITY);
cout << "Player 2 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE|
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");

cout << "PLAYER 1 FINAL SCORE: " << b << endl;


cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|
FOREGROUND_INTENSITY);
cout << "Player 2 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE|
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");
cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|
FOREGROUND_INTENSITY);
cout << "Player 2 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE|
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");
cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|
FOREGROUND_INTENSITY);
cout << "Player 2 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|
FOREGROUND_INTENSITY);
cout << "CONGRATULATIONS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");
cout << "PLAYER 1 FINAL SCORE: " << b << endl;
cout << "PLAYER 2 FINAL SCORE: " << a << endl;
cout << "Rounds: " << c-1 << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE|
FOREGROUND_INTENSITY);
cout << "Player 2 WINS!" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|
FOREGROUND_INTENSITY);

cout << "CONGRATULATIONS!" << endl;


SetConsoleTextAttribute(hConsole, saved_colors);
Sleep(2500);
system("cls");
}
if (b==a)
{
cout << "FINAL SCORE: " << b << endl;
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|
FOREGROUND_INTENSITY);
cout << "DRAW" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
}
}

You might also like