ANDRANT Δημοσ. 11 Ιουνίου 2003 Δημοσ. 11 Ιουνίου 2003 PSAXNO TON KODIKA TOU PAIXNIDIOU MASTERMIND SE C OPOIOS TIN EXEI PARAKALO NA MOU TIN STEILEI <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/wink.gif" alt="" />
kyriakidis Δημοσ. 11 Ιουνίου 2003 Δημοσ. 11 Ιουνίου 2003 File sou stelno ton kodika, gia to masterimind pou eixa kanei gia ena practical sto CITY. Ta grafika einai Text
kyriakidis Δημοσ. 11 Ιουνίου 2003 Δημοσ. 11 Ιουνίου 2003 #include <iostream> #include <cstdlib> using namespace std; void graph2() { cout<<" ))) ___ >X< '*` +++ "<<endl; cout<<" (o o) (o o) (o o) (o o) (o o) "<<endl; cout<<" ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-"<<endl; cout<<endl; cout<<"\t\t# # # ## ### ### ## # # ### ### ## "<<endl; cout<<"\t\t### # # # # # # # ### # # # # # "<<endl; cout<<"\t\t### ### # # ## ## ### # # # # # "<<endl; cout<<"\t\t# # # # # # # # # # # # # # # # "<<endl; cout<<"\t\t# # # # ## # ### # # # # ### # # ## "<<endl; }; void graph() { cout<<" :::: :::: ::: :::::::: ::::::::::: :::::::::: ::::::::: "<<endl; cout<<" +:+:+: :+:+:+ :+: :+: :+: :+: :+: :+: :+: :+: "<<endl; cout<<" +:+ +:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ "<<endl; cout<<" +#+ +:+ +#+ +#++:++#++: +#++:++#++ +#+ +#++:++# +#++:++#: "<<endl; cout<<" +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ "<<endl; cout<<" #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# "<<endl; cout<<" ### ### ### ### ######## ### ########## ### ### "<<endl; cout<<" :::: :::: ::::::::::: :::: ::: ::::::::: "<<endl; cout<<" +:+:+: :+:+:+ :+: :+:+: :+: :+: :+: "<<endl; cout<<" +:+ +:+:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ "<<endl; cout<<" +#+ +:+ +#+ +#+ +#+ +:+ +#+ +#+ +:+ "<<endl; cout<<" +#+ +#+ +#+ +#+ +#+#+# +#+ +#+ "<<endl; cout<<" #+# #+# #+# #+# #+#+# #+# #+# "<<endl; cout<<" ### ### ########### ### #### ######### "<<endl; cout<<endl<<"\t\t\t BY THEODOROS KYRIAKIDIS"<<endl; }; void clear() { int i; for(i=0;i<=80;i++)puts(""); }; class Inside { protected: int list[4]; int len; public: Inside() { len = 0; for (int i=0;i<=4;i++) list=0; } int returnNumber(int x); bool contains(int n); void remove(int n); void add(int n); int getlen(); }; int Inside::returnNumber(int x) { return list[x]; }; int Inside::getlen(){return len;}; bool Inside::contains(int n) { int counter=0; for(int i=0;i<len;i++) { if(list == n && list>0) counter++; } if (counter!=0) return true; else return false; } void Inside::remove(int n) { for(int i=0;i<=len;i++) { if(list == n) { list = list[len-1]; // swap with the last element len--; // record new list length return; } } }; void Inside::add(int n) { list[len] = n; len++; }; class Eval { int black; // How many pegs were in the correct place, correct color int white; // How many pegs were the correct color only. public: int getblack(); void AddBlack(){black++;} void AddWhite(){white++;} Eval(){black=0; white=0;} void get(){cout<<" BLACK:"<<black<<" WHITE:"<<white;} }; int Eval::getblack() { return black; }; class Row { private: int store[6][4]; // In heare program will store all guesses // Total 6 rows and 4 pegs int currentrow; public: Row(); void add(); void display(int x); void nextrow(); int getrow(); int rowget(int x, int ; // Will return the number of Store }; void Row::add() { cout<<"YOUR GUESS IS ______ :"<<endl; for (int i=0;i<4;i++) { do{ cout<<"PEG("<<i<<")"; cin>>store[currentrow]; if (store[currentrow]<1 || store[currentrow]>6) cout<<"\a\aNOT CORRECT TRY AGAIN :"<<endl; }while(store[currentrow]<1 || store[currentrow]>6); } }; void Row::display(int x) { cout<<"\t\t\t\t| "; for (int l=0; l<4; l++) { cout<<"("; if (store[x][l]==0) cout<<" "; else cout<<store[x][l]; cout<<") "; } cout<<" | "; }; Row::Row() { for (int i=0; i<=5;i++) { for (int f=0; f<=3; f++) store[f]=0; } currentrow=0; }; void Row::nextrow() { currentrow++; }; int Row::getrow() { return currentrow; }; int Row::rowget(int x, int { return store[x]; }; class Code { private: int code[3]; // Total number is 4 public: void Randomize(); void Evaluate(int row, Row store); int Evalu2(int row, Row store); void getCode(); }; int Code::Evalu2(int row, Row store) { int counter=0; //Eval one; for (int i=0; i<=3; i++) { if (code==store.rowget(row,i)) { counter++; // one.AddBlack(); } } return counter; // return one.getblack(); }; void Code::getCode() { cout<<"CODE WAS : "; for (int i=0;i<=3;i++) cout<<code; }; void Code::Randomize() { for (int i=0;i<=3;i++) code=1+rand()%6; }; void Code::Evaluate(int row, Row store) { Eval one; Inside A; Inside B; for (int i=0; i<=3; i++) { if (code==store.rowget(row,i)) { one.AddBlack(); } else { A.add(code); B.add(store.rowget(row,i)); } } for (int y=0;y<=3;y++) { if (B.contains(A.returnNumber(y))==true) { int b; b=A.returnNumber(y); A.remove(; B.remove(; y--; one.AddWhite(); } } one.get(); }; class Game { private: Code newf; Row row; public: Game(){newf.Randomize();} bool winofgame(); bool endofgame(); void startgame(); void display(); }; bool Game::winofgame() { if (row.getrow()==0) { if (newf.Evalu2(row.getrow(),row)==4) return true; else return false; } else if (newf.Evalu2(row.getrow()-1,row)==4) return true; else return false; }; void Game::startgame() { clear(); do { graph2(); cout<<endl<<"***TRY TO FIND THE CODE. PRESS 1,2,3,4,5,6 FOR YOUR CHOISE."<<endl; display(); cout<<endl; row.add(); cout<<endl; row.nextrow(); }while(winofgame()==false && endofgame()==false ); clear(); graph2(); if(endofgame()==true) { cout<< "\t\t\a\t**********************"<<endl; cout<<"\t\t\a\t****TO BAD YOU LOST*** "<<endl; cout<< "\t\t\a\t****** YOU LOST *****"<<endl; cout<< "\t\t\a\t**********************"<<endl; cout<< "\t\t\a\t****** CODE WAS *****"<<endl; cout<< "\t\t\a\t****";newf.getCode();cout<<"***"<<endl; cout<< "\t\t\a\t**********************"<<endl; cout<< "\t\t\a\t**********************"<<endl; } else { cout<< "\t\t\a\t**********************"<<endl; cout<<"\t\t\a\t**WELL DONE YOU FIND** "<<endl; cout<< "\t\t\a\t****** THE CODE *****"<<endl; cout<< "\t\t\a\t**********************"<<endl; cout<< "\t\t\a\t****** YOU WIN *****"<<endl; cout<< "\t\t\a\t**********************"<<endl; cout<< "\t\t\a\t****** CODE WAS *****"<<endl; cout<< "\t\t\a\t****";newf.getCode();cout<<"***"<<endl; cout<< "\t\t\a\t**********************"<<endl; cout<< "\t\t\a\t**********************"<<endl; } cout<<"Press Any Key and then Enter to Continue..."; char a; cin>>a; }; void Game::display() { cout<<"\t\t\t\t********************\n"; for (int i=0;i<=5;i++) { row.display(i); newf.Evaluate(i,row); cout<<endl; } cout<<"\t\t\t\t********************\n"; }; bool Game::endofgame() { if (row.getrow()<=5) return false; else return true; }; class UI { Game *Mastermind; public: UI() { start(); } void start(); void help(); }; void UI::help() { cout<<endl<<endl; cout<<"Mastermind is an old board stratedy game. The scope of the game is to find the "; cout<<"secret code. A secret code of four pegs has been randomly generated from a "; cout<<"combination of the following six colors: green, blue, red, yellow, black, "; cout<<"and white. Your job is to guess those four peg colors in the proper order."; cout<<"You can choise The color by pressing 1,2,3,4,5,6. Total number of colors is 6."; cout<<"When you Find a peg in the write possition They will going to Display 1 Black "; cout<<"If you find a peg that is not in the right possition They program will display 1 White"; cout<<"You must find the code in 6 total guesses."<<endl; cout<<"Good Luck"<<endl; char f; cout<<endl<<endl<<"\t\t\tPress key to continue"; cin>>f; }; void UI::start() { char x; do { clear(); graph(); cout<<endl<<endl; cout<<" *************************"<<endl; cout<<" *** 1. PLAY THE GAME ****"<<endl; cout<<" ***** ******"<<endl; cout<<" ***** 2. INFO ******"<<endl; cout<<" *** 3. EXIT ****"<<endl; cout<<" *************************"<<endl; cin>>x; switch (x) { case 49: Mastermind=new Game; Mastermind->startgame() ; delete Mastermind; break; case 50: help(); break; } }while(x!=51); }; int main() { UI newgame; return 0; }
UNPAIKTABLE Δημοσ. 11 Ιουνίου 2003 Δημοσ. 11 Ιουνίου 2003 Dranidis kai ksero pswmi? <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/tongue.gif" alt="" /> lol
Dionisos Δημοσ. 11 Ιουνίου 2003 Δημοσ. 11 Ιουνίου 2003 8a sas parakalousa otan vazete kwdika sto post sas na ton perikleiete mesa se tags code. Filika Dionisos
kyriakidis Δημοσ. 12 Ιουνίου 2003 Δημοσ. 12 Ιουνίου 2003 Katalaba CITY eee? Ase teliosa tin diplomatiki mou kai ksekourazoume. Supervisor Dranidis an kai den boithise katholou afou ton ida olo kai olo 2 fores. <img src="http://www.insomnia.gr/ubbthreads/images/graemlins/smile.gif" alt="" /> lol e?
kyriakidis Δημοσ. 14 Ιουνίου 2003 Δημοσ. 14 Ιουνίου 2003 Balto san ena arxeio. PX allclasses.cpp se periptosi pou ta baleis se ksexorista kane ta analoga #difine
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.