## 220 Digital Portfolio

Pig dice game is a game that I made that user plays it against computer
it gives the user to either roll or pass

and the computer will try to roll until they’re  more than 20

The program works this way

get random number and seed it

then get random start for who will start first and seed

if  who ever rolled ‘1’ will lose his points and starts again at ‘0’

if other than ‘0’ it will keep adding points

who ever reach 100 is the winner

let us look at the code and then I will be including screenshots of the game

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;

int player1 (int & playerscore );//to declare the player function
int player2(int & computerscore);//Player 2 function declartion
int again();
bool holded = false; // boolean to use when hold
int rolled(); /// declaration of a random roll (get random number between 1 to 6
int main(){ //// The main function to run the functions
int max = 100;
int playerscore = 0;
int computerscore= 0;

randomplayer = rand() % 2 +1;

while((playerscore != max) && (computerscore != max)){
if (randomplayer ==1){ // do the random player
player1(playerscore);
randomplayer =2;
}
else if (randomplayer==2){
player2(computerscore);
randomplayer = 1;
cout<<“You want to (R)oll or (H)old : “<<endl;
}
if (playerscore >= max){
cout<<“PLAYER WON”<<endl;
break;
}
else if (computerscore >= max){
cout<< “COMPUTER WON”<<endl;
break;
}
}
cout<<“You wana again?????????”<<endl;
char yes = ‘y’;
cin>>yes;
if (yes == ‘y’ or yes == ‘Y’){
cout<<“You want to (R)oll or (H)old : “<<endl;
return main();
}
return 0;
}

int rolled()/// roll function
{
int roll;
roll = rand()% 6 + 1; // get random numbers between 1 to 6

return roll;
}

int player1 (int & playerscore){ // player 1 function
char user; // do char to get the letter ‘r’ or ‘h’
cin>>user; // get the input
int player1roll; // declare the roll and assign it to the roll function
while (user==’r’or user == ‘R’){ // if user input is ‘R’ or ‘r’ do the below
player1roll = rolled();
cout<<“The Player roll is : “<<player1roll<<endl;
if (player1roll == 1){ // if roll is ‘1’ it user will lose all points
cout<<“You rolled 1 you lost your points!”<<endl;
playerscore =0;
holded = true; // and is holded
break;

}

else if (player1roll != 1){ // if it is not then add the socres and move on
playerscore += player1roll;
cout<<“You have a score of : “<<playerscore<<endl;
cout<<“You want to (R)oll or (H)old : “;
cin>>user;
}
}

while (user== ‘h’ or user == ‘H’){// if user hold then just hold and break and go to the computer turn
holded = true;
break;
}

return playerscore;
}

int player2 (int & computerscore){

int computeroll;
computeroll = rolled();
if (computeroll != 1){
computerscore += computeroll; /// add the computer roll to the computer score
cout<<“The computer rolled : “<<computeroll<<endl; /// cout it
cout<< “Computer score is : “<<computerscore<<endl;// cout the score
while (computerscore < 20){ // if the computer score is less than 20 it will keep rolling, this should be a bad practice, and I think I need
// to find a better way, because once the computer score is ’20’ it will no longer do anything
cout<<“The computer rolled again : “<<computeroll<<” the score of the computer is now : “<<computerscore<<endl;
if (computerscore >= 20){// other wise ‘if its 20’ then do nothing give player chance
break;
}
}
while ((holded == true) && (computerscore >=20)){
computerscore+=computeroll;
cout<<“The computer rolled again : “<<computeroll<<” the score of the computer is now : “<<computerscore<<endl;
if( computerscore >= 40){
break;
}
}

}
else if (computeroll == 1){/// if computer roll is 1, then computer loses all points
cout<<“The computer rolled ‘1’ it lost all its points, its your turn now : “<<endl;
computerscore = 0;
}

return computerscore;
}

This is how the game looks like

## 220 Digital Portfolio

I have always liked playing with graphics, but never that how to animate them using code, even though I have used 3d max or blender or maya, but never delved to the point that I had to use code to animate them, the only thing I did is just animating a ball without even using a single code. But I had the opportunity to use the SFML library and did a bouncing ball

#include <SFML/Graphics.hpp>
using namespace sf;

int main( ) {
int size = 500; this is the size of the window
int hight = 500; the height of the window
/* open the window with size 50×500 and title “My Window” */
RenderWindow window(VideoMode(size, hight), “ball bouncing”);
int xspeed = 1;
int yspeed = 1;
CircleShape circle(100);
circle.setFillColor(Color::Red);
circle.setPosition(0,0);
while (window.isOpen( )) {

//run the program as long as the window is open
window.draw(circle);
circle.move(xspeed,yspeed);
window.display( );
window.clear();
if(circle.getPosition().y> 400){/// if the ball is bigger than 400 it will bounce and will move back
yspeed=-yspeed;
circle.setFillColor(Color::Blue);/// it will change the color! to give it more better look
}
if (circle.getPosition().y < 0){
yspeed++;/// if it is less than zero then will go bigger and will go bigger
circle.setFillColor(Color::Yellow);
}

if(circle.getPosition().x > 350 ){
xspeed=-xspeed;// if it is bigger than 350 then it will reduce it which will make it bounce
circle.setFillColor(Color::White);
}
if (circle.getPosition().x < 0 ){
circle.setFillColor(Color::Red);
xspeed++;
}
Event event;
while (window.pollEvent(event)) {
if (event.type == Event::Closed) {/// this will handle the close event so that when click at the “x” on the window it will close the windo
window.close( );
}
}
}
return 0;
}

here is screen shots of the ball bouncing

## 220 Digital Portfolio

Encode or Decode:

Creating a program that encode and decode could be frustrating at first, but once you get the idea it will be fun!

When I did this assignment I had to search for the ASCII table and take a deep look at it, and write down my thoughts about how to approach this program,

# include <iostream>
# include <sstream>
# include <string>
#include <locale>
# include <ctype.h>
using namespace std;
int main(){
string message;
string key;
int nkey;
string convert;
char input;
cout<<” You want to Encode or Decode?”<<endl;
cin>>input;
cin.ignore();
bool wrong;
if ((input != ‘e’ or input != ‘E’)&&( input != ‘d’ or input!= ‘D’)){ // this is to make sure that the user entered ‘e’ or ‘E’ or ‘d’ or’D’ to encode or decode
wrong = true; // if this the user entered other than that then it will return true for the wrong

}
else {
wrong = false;// here wrong will be false
}
while ( wrong == true){
if ((input == ‘e’ or input == ‘E’) or (input == ‘D’ or input == ‘d’)){
wrong = false;/// here to make sure if the program dedicated  the right keys
}
else {
cout<<“Please choose ‘E’ for encode OR ‘D for decode’”<<endl;

cin>>input;
cin.ignore();
}
}

while ( (input == ‘E’ or input == ‘e’) && (wrong == false)){
wrong = false;
cout<<“Enter the message you want to encoded here :” <<endl;
getline(cin,message);// get the message
cout << “Enter key”<<endl;
getline (cin,key);
cin.ignore();
for ( unsigned int b = 0 ; b <= message.size(); b++){
if (key.size()!= message.size()){
key += key[b]; // if the key is less then the message size then repeat that this will make sure that the key size is the same size as the message
}
}
for (unsigned int j= 0, h = 0 ; j < message.size(); j++,h++){ // loop through the message and get the number that represents each letter
nkey = key[h];
nkey = message[j] + key[h];
if (message[j] == ‘ ‘ ){
key[h–];
continue;
}
while (nkey > 126 ) {
nkey = nkey – 93;// to make sure that the numbers will stay in printable characters we do 126 -33
}
convert += static_cast<char>(nkey);

}
cout<<“The Encoded Message is – > “<<convert<<endl;
input++;
}

// so here if we enter the message “hello” to be encoded and use the keys “abc” it will result in

So hello rotated with the key abc will be ljrpt

while ((input == ‘d’ or input == ‘D’) && (wrong == false)){
wrong = false;
string dmessage;
string dkey;
int dnkey;
string dconvert;
cout<<“Enter decoded message here :” <<endl;
getline(cin,dmessage);
cin.ignore();
cout << “Enter key”<<endl;
getline (cin,dkey);
cin.ignore();
for ( unsigned int m = 0 ; m <= dmessage.size(); m++){
if (dkey.size()!= dmessage.size()){
dkey += dkey[m];
}
}
for (unsigned int o = 0, n= 0 ; o < dkey.size();o++,n++){
dnkey = dkey[n];
if (dmessage[o] == ‘ ‘){
dkey[n–];
continue;
}
dnkey = dmessage[o] – dkey[n];
while (dnkey < 33){
dnkey = dnkey + 93;
}
dconvert += static_cast<char>(dnkey);

}
cout<<“decoded text out of loop is – > “<<dconvert<<endl;
input++;

}

and then here is the decoded “hello” using the key “abc” we will be back

return 0;

}

## Presentation update “Xbox, the surveillance device!” How? Why?

I was searching on the internet to answer the question “why and how Xbox can be used to spy on you” and I what I found was really impressive and very bad. One thing that Microsoft made on the Xbox is the camera that is being active even when your console is off and can listen to your commands and even can read your heart beats with the right software Sean Hollister  stated. Sean Hollister  also stated that “Microsoft says it doesn’t plan to abuse that power, and claims it couldn’t even if it tried. The company told us that the Kinect’s cameras and microphones aren’t actually recording or transmitting any audio or video data back to Microsoft’s servers without the user’s explicit consent, and all ambiently collected data is anonymized. While some voice commands are processed at Microsoft’s servers, they’re converted to text before they ever leave the machine, and biometric data is translated into numerical values that simply indicate, say, where a player’s limbs are during online multiplayer games. While Microsoft says the Kinect is an “integral part” of the new Xbox, it also claims that sensing”(Could the NSA use Microsoft’s Xbox One to spy on you?)

Why would a company like Microsoft spy on people?

Although Microsoft stated that they are not going to spy on people, but Sean brought an example of Skype giving access to private Skype video and audio calls, years before, Skype assured that it is impossible to do such a request like “giving access to private Skype video and audio calls, and now…?

Would Microsoft help the government to spy on people?

Xbox One by Moo Jay

## Media impact on politics

One fact makes the social media strong when it comes to the topic of politics, is how it changed Arabs from being with to against their government. This does not makes me agree with what Arabs doing today in their countries, in fact I disagree with all of it for the fact that what they did is wrong, actually it was wrong from the start, because it just produced more anger and hate. The issue that the Arabs facing is the impact of Social Media in which they see for example videos or words that produces anger without knowing why they are even doing this. For instance if we delve more into this topic you will find out that Arabs always throws their own issues to Americans meaning that “America is the problem with everything” so this makes it even worse, if someone fail his course then yeah it is “Americans”

Now let us turn back to what I have said at first, when I stated that “bad people” used the social media to do bad things and brainwash the good guys, here I mean the bad guys who came from the government itself this is what destroyed the Arab dream and turned “Arabs spring” to “Arabs hill”.

This is my opinion and my opinion does not mean I am with either side, I am just arguing questions have been asked through the last 4 years, this is not meant to be disrespectful, instead it is for education.

## Cyberbullying

When I first watched the video that the group presented I thought that it was so bad that people were running away and leaving the guy alone and not even try to save him. The fact that people were leaving him and not helping him is so bad to us, and I agree, but what about if we take the other side of it, and answer the question why people tried to avoid involving to help that guy? Well the answer could be many, and one can be “I do not want to get into trouble!” this means that “LEAVE ME ALONE” which means “I only care about myself” this is a hard fact to except but nowadays, we can not trust people and if you look deep into it, you will find that avoiding it would be better for you I will include more than one situation

1- what about if the guy is holding a gun or knife or anything that might hurt you?

2- what about if they were friends joking?

3 – what about if actually they were doing it so that they get you into trouble?

This can be different from country to country , and I thought that it would’ve been more interesting to know what other countries have.