Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int randomCard=rand()%11+1, again=1;
- do{
- int computer=randomCard, player=randomCard, play, turnCount=1;
- system("cls");
- do{
- computer+=randomCard;
- turnCount++;
- }while(computer<=16&&turnCount<=5);
- randomCard=(rand()%11)+1;
- turnCount=2;
- do{
- player+=randomCard;
- if(player>=22)break;
- cout<<"Your cards add up to: "<<player<<" | Card number "<<turnCount<< endl;
- cout<<"1=hit 0=stay" <<endl;
- cin>>play;
- turnCount++;
- system("cls");
- }while(play!=0&&turnCount<=5);
- if(player==computer&&player<=21&&computer<=21)cout<<"You had "<<player<<"\nThe computer had "<<computer<<"\tIT'S A TIE!"<<endl;
- if(player>=22&&computer>=22)cout<<"You both went over 21,\nIT'S A TIE!"<<endl;
- if(player>=22&&computer<=21)cout<<"You went over 21, you had "<<player<<"\nYOU LOST!"<<endl;
- if(computer>=22&&player<=21)cout<<"The computer has gone over 21 \nYOU WIN!"<<endl;
- if(computer<player&&player<=21&&computer<=21)cout<<"You had "<<player<<"\nThe computer had "<<computer<<"\nYOU WIN!"<<endl;
- if(computer>player&&player<=21&&computer<=21)cout<<"You had "<<player<<"\nThe computer had "<<computer<<"\nYOU LOST!"<<endl;
- cout<<"Play Again?"<<endl;
- cout<<"1=Yes 0=No"<<endl;
- cin>>again;
- }while(again==1);
- cout<<"Thanks for playing!"<<endl;
- return 0;
- }
- -------------------------------------------------------------
- #include <iostream>
- #include <windows.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sstream>
- using namespace std;
- string code;
- string codeArr[9];
- int gameLength=10;
- int array[9];
- void color(int num)
- {
- HANDLE color=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(color,num);
- }
- void explain()
- {
- color(13);
- system("cls");
- cout<<"Welcome to Mastermind!"<<endl;
- cout<<"----------------------"<<endl;
- cout<<"The computer will generate a random 4 digit number with NO repeating digits."<<endl;
- cout<<"The objective of the game is for you to guess that 4 digit number."<<endl;
- cout<<"The computer responds with how close your guess is to the number."<<endl;
- cout<<"Red = Number of correct digits in the correct place."<<endl;
- cout<<"White = Number of correct digits in the wrong place."<<endl;
- cout<<"Good luck! Press any key to return to the menu."<<endl;
- color(7);
- system("pause>nul");
- }
- int changeLength()
- {
- system("cls");
- cout<<"How many turns do you want the game to last?"<<endl;
- cin>>gameLength;
- }
- void generateNumber()
- {
- srand(time(NULL));
- int temp;
- string tempString;
- for(int c=0;c<9;c++)array[c]=c+1;
- for(int c=0;c<9;c++)
- {
- int x=rand()%4+1;
- temp=array[c];
- array[c]=array[x];
- array[x]=temp;
- }
- for(int c=0;c<4;c++)
- {
- ostringstream convert;
- convert<<array[c];
- tempString=convert.str();
- code+=tempString;
- }
- for(int c=0;c<4;c++)
- {
- ostringstream convert;
- convert<<array[c];
- codeArr[c]=convert.str();
- }
- }
- int game()
- {
- int turnCount=1;
- for(int c=0;c<gameLength;c++)
- {
- string guess="";
- int bullCount=0, cowCount=0;
- cout<<"Attempt "<<turnCount<<endl;
- cout<<"Enter your guess: "<<endl;
- cin>>guess;
- while(guess[0]==guess[1]||guess[0]==guess[2]||guess[0]==guess[3]||guess[1]==guess[2]||guess[1]==guess[3]||guess[2]==guess[3])
- {
- cout<<"Your guess should not have repeating digits! Try again."<<endl;
- cout<<"Enter your guess: ";
- cin>>guess;
- }
- if(c==gameLength-1&&guess!=code)
- {
- color(8);
- cout<<"You ran out of attempts! Better luck next time! The code was "<<code<<endl;
- cout<<"Press any key to return to the main menu."<<endl;
- color(7);
- system("pause>nul");
- }
- if(guess==code)
- {
- cout<<"Congratulations! You got the code in "<<turnCount<<" attempts! You win!"<<endl;
- cout<<"Press any key to return to the main menu."<<endl;
- system("pause>nul");
- return 0;
- }
- turnCount++;
- for(int c=0;c<4;c++)
- {
- if(guess[c]==code[c])
- bullCount++;
- int num=guess.find(codeArr[c]);
- if(num!=-1)cowCount++;
- }
- color(12);
- cout<<"Red: "<<bullCount<<endl;
- color(15);
- cout<<"White: "<<cowCount<<endl;
- color(7);
- cout<<"-----------------"<<endl;
- }
- return 0;
- }
- int main()
- {
- int choice;
- do{
- system("cls");
- cout<<"Welcome to MasterMind"<<endl;
- cout<<" 1) Play"<<endl;
- cout<<" 2) Instructions"<<endl;
- cout<<"3) Change Game Length"<<endl;
- cout<<" (Currently "<<gameLength<<")"<<endl;
- cout<<" 4) Exit"<<endl;
- cin>>choice;
- if(choice==1)
- {
- system("cls");
- generateNumber();
- game();
- }
- if(choice==2)explain();
- if(choice==3)changeLength();
- if(choice==4)break;
- code="";
- }while(true);
- return 0;
- }
- ------------------------------------------------------
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- string word;
- void hangman0();
- void hangman1();
- void hangman2();
- void hangman3();
- void hangman4();
- void hangman5();
- void hangman6();
- void hangman7();
- void randomWord()
- {
- srand(time(NULL));
- int num=rand()%27+1;
- string words[43];
- string text;
- ifstream file("words.txt");
- for(int c=0;file>>text;c++)words[c]=text;
- word=words[num];
- }
- int main()
- {
- randomWord();
- int count=0;
- string text;
- string theWord[word.length()];
- string guessedLetters="";
- for(int c=0;c<word.length();c++)theWord[c]+="?";
- int hangman=0;
- while(hangman!=7)
- {
- if(count==0)
- {
- cout<<"Your word is "<<word.length()<<" letters long!"<<endl;
- for(int c=0;c<word.length();c++)cout<<theWord[c]<<" ";
- cout<<endl;
- hangman0();
- }
- else
- {
- for(int c=0;c<word.length();c++)cout<<theWord[c]<<" ";
- cout<<"\t\tGuessed letters: ";
- for(int c=0;c<count;c++)cout<<guessedLetters[c];
- }
- cout<<endl;
- if(count==0)cout<<"If you would like to guess a letter, type in a letter,\nif you would like to guess the word, type 'guess' ";
- else cout<<"Enter your guess: "<<endl;
- cin>>text;
- while(text.length()>1&&text!="guess")
- {
- cout<<"Invalid input! Please enter a character or 'guess': ";
- cin>>text;
- }
- while(guessedLetters.find(text)!=string::npos)
- {
- cout<<"You already guessed this letter! Enter another one: ";
- cin>>text;
- }
- system("cls");
- guessedLetters+=text;
- if(text=="guess")
- {
- string guess;
- cout<<"What do you think the word is? ";
- cin>>guess;
- if(guess==word)
- {
- cout<<"Congratulations! You guessed the word correctly!"<<endl;
- return 0;
- }
- else
- {
- cout<<"Sorry! That's incorrect! The word was "<<word<<". Better luck next time."<<endl;
- return 0;
- }
- }
- if(word.find(text)!=string::npos)
- {
- int num=word.find(text);
- theWord[num]=text;
- int num2=word.rfind(text);
- theWord[num2]=text;
- cout<<"Letter found!"<<endl;
- }
- else
- {
- cout<<"Letter not found!"<<endl;
- hangman++;
- }
- if(hangman==0)hangman0();
- else if(hangman==1)hangman1();
- else if(hangman==2)hangman2();
- else if(hangman==3)hangman3();
- else if(hangman==4)hangman4();
- else if(hangman==5)hangman5();
- else if(hangman==6)hangman6();
- else if(hangman==7)hangman7();
- count++;
- }
- cout<<"Sorry! You lost! The word was "<<word<<". Better luck next time."<<endl;
- return 0;
- }
- void hangman0()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman1()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman2()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman3()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t -| |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman4()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t -|- |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman5()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t -|- |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman6()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t -|- |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t / |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- void hangman7()
- {
- cout<<"\t\t\t\t +------+"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t O |"<<endl;
- cout<<"\t\t\t\t -|- |"<<endl;
- cout<<"\t\t\t\t | |"<<endl;
- cout<<"\t\t\t\t / \\ |"<<endl;
- cout<<"\t\t\t\t |"<<endl;
- cout<<"\t\t\t\t ==========="<<endl;
- }
- -----------------------------------------------------
- #include <iostream>
- #include <windows.h>
- using namespace std;
- char spots[]{'1','2','3','4','5','6','7','8','9'};
- bool hasWon=false, hasFound=false;
- char p1input, p2input;
- char nums[]{'1','2','3','4','5','6','7','8','9'};
- void color(int num)
- {
- HANDLE color=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(color, num);
- }
- void board()
- {
- system("cls");
- cout<<endl;
- cout<<"\t\t "<<spots[0]<<" | "<<spots[1]<<" | "<<spots[2]<<" "<<endl;
- cout<<"\t\t---+---+---"<<endl;
- cout<<"\t\t "<<spots[3]<<" | "<<spots[4]<<" | "<<spots[5]<<" "<<endl;
- cout<<"\t\t---+---+---"<<endl;
- cout<<"\t\t "<<spots[6]<<" | "<<spots[7]<<" | "<<spots[8]<<" "<<endl;
- cout<<endl;
- }
- void winCheck()
- {
- if(spots[0]=='X'&&spots[1]=='X'&&spots[2]=='X')hasWon=true;
- if(spots[3]=='X'&&spots[4]=='X'&&spots[5]=='X')hasWon=true;
- if(spots[6]=='X'&&spots[7]=='X'&&spots[8]=='X')hasWon=true;
- if(spots[0]=='X'&&spots[3]=='X'&&spots[6]=='X')hasWon=true;
- if(spots[1]=='X'&&spots[4]=='X'&&spots[7]=='X')hasWon=true;
- if(spots[2]=='X'&&spots[5]=='X'&&spots[8]=='X')hasWon=true;
- if(spots[2]=='X'&&spots[4]=='X'&&spots[6]=='X')hasWon=true;
- if(spots[0]=='X'&&spots[4]=='X'&&spots[8]=='X')hasWon=true;
- if(spots[2]=='X'&&spots[4]=='X'&&spots[6]=='X')hasWon=true;
- if(spots[0]=='O'&&spots[1]=='O'&&spots[2]=='O')hasWon=true;
- if(spots[3]=='O'&&spots[4]=='O'&&spots[5]=='O')hasWon=true;
- if(spots[6]=='O'&&spots[7]=='O'&&spots[8]=='O')hasWon=true;
- if(spots[0]=='O'&&spots[3]=='O'&&spots[6]=='O')hasWon=true;
- if(spots[1]=='O'&&spots[4]=='O'&&spots[7]=='O')hasWon=true;
- if(spots[2]=='O'&&spots[5]=='O'&&spots[8]=='O')hasWon=true;
- if(spots[2]=='O'&&spots[4]=='O'&&spots[6]=='O')hasWon=true;
- }
- void p1move()
- {
- for(int c=0;c<9;c++)
- {
- for(int x=0;x<9;x++)
- {
- if(p1input==nums[x])hasFound=true;
- if(x==8&&hasFound==false)
- {
- cout<<"That is not a choice! Please pick a number on the board!"<<endl;
- cin>>p1input;
- }
- }
- hasFound=false;
- while(p1input==nums[c]&&spots[c]!=nums[c])
- {
- cout<<"Someone has already taken this spot! Please pick another!"<<endl;
- cin>>p1input;
- }
- if(p1input==nums[c]&&spots[c]!='X'&&spots[c]!='O')spots[c]='X';
- }
- }
- void p2move()
- {
- for(int c=0;c<9;c++)
- {
- for(int x=0;x<9;x++)
- {
- if(p2input==nums[x])hasFound=true;
- if(x==8&&hasFound==false)
- {
- cout<<"That is not a choice! Please pick a number on the board!"<<endl;
- cin>>p2input;
- }
- }
- hasFound=false;
- while(p2input==nums[c]&&spots[c]!=nums[c])
- {
- cout<<"Someone has already taken this spot! Please pick another!"<<endl;
- cin>>p2input;
- }
- if(p2input==nums[c]&&spots[c]!='X'&&spots[c]!='O')spots[c]='O';
- }
- }
- int main()
- {
- cout<<"Welcome to Tic Tac Toe!"<<endl;
- cout<<"-----------------------"<<endl;
- cout<<"In order to play, you need two players!"<<endl;
- cout<<"Player one is 'X', and player two is 'O'"<<endl;
- cout<<"Press any key to begin!"<<endl;
- system("pause>null");
- board();
- int winner=2, round=0;
- while(hasWon==false)
- {
- cout<<"Player 1, where would you like to move?"<<endl;
- cin>>p1input;
- p1move();
- system("cls");
- board();
- winCheck();
- if(hasWon==true)
- {
- winner=1;
- break;
- }
- round++;
- if(round==9&&hasWon==false)break;
- cout<<"Player 2, where would you like to move?"<<endl;
- cin>>p2input;
- p2move();
- system("cls");
- board();
- winCheck();
- round++;
- if(round==9&&hasWon==false)break;
- }
- if(round!=9)cout<<"Player "<<winner<<" is the winner!"<<endl;
- else cout<<"It's a tie!"<<endl;
- }
- -------------------------------------------------------------
- #include <iostream>
- #include <windows.h>
- using namespace std;
- void color(int num)
- {
- HANDLE color=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(color, num);
- }
- void menu()
- {
- color(15);
- cout<<"\n\t\t +-----------+ "<<endl;
- cout<<"\t\t+----------=~| ";
- color(13);
- cout<<"Main Menu";
- color(15);
- cout<<" |~=----------+"<<endl;
- cout<<"\t\t| +-----------+ |"<<endl;
- cout<<"\t\t| |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| | ";
- color(10);
- cout<<"Tic Tac Toe";
- color(15);
- cout<<" | |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| | ";
- color(12);
- cout<<"Master ";
- color(9);
- cout<<"Mind";
- color(15);
- cout<<" | |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| | ";
- color(11);
- cout<<"Blackjack";
- color(15);
- cout<<" | |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| | ";
- color(14);
- cout<<"Hangman";
- color(15);
- cout<<" | |"<<endl;
- cout<<"\t\t| +-------------+ |"<<endl;
- cout<<"\t\t| |"<<endl;
- cout<<"\t\t+-------------------------------------+"<<endl;
- }
- int main()
- {
- menu();
- }
- ---------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment