Checking my Progress in Game Programming

Started by
18 comments, last by Servant of the Lord 11 years, 7 months ago
Hello! Today I want to find out if I am ready to start moving along in my learning by showing you guys the coding of my 2 and a half games. Basically my "Question" is, am I ready to move on based on the style of programming in these games? Also, if not, then what kind of tips can you give me to push me in the direction of Industrial Qualified style of game programming? Thanks!

[source lang="cpp"]#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
using namespace std;

int number,guess=0,maximum=0,choice=0,restart=1,tries=0,gameRun=1,times=0,compare=0,go=0;

void personGuess(){
while(restart==1){
tries=0;
cout<<"\n\n\n\n\nWhat do you want the maximum number to be?\n";
cin>>maximum;
srand(time(0));
number=((rand()%maximum)+1);
cout<<"\n\nWhats your Guess?\n";
guess=-1;
while(guess!=number){
cin>>guess;
tries++;
cout<<"\n\n\n\n\n";
cout<<endl<<endl;
if(guess>number){cout<<"Too high, try again.\n";}
if(guess<number){cout<<"Too low, try again.\n";}
}
cout<<"You found the random number, "<<number<<"!!! Good job!!\n\nTries: "<<tries<<"\n\n\n\n\nWould you like to try again? 1} Yes 2} No\n\n";
restart=0;
while(restart!=1 and restart!=2){
cin>>restart;
}
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
}


void compGuess(){
restart=1;
while(restart==1){
times=1,compare=0,go=0,tries=0;
cout<<"Choose the number that your computer will have to guess.\n\n";
cin>>number;
cout<<"\n\n\n";
cout<<"\n\n\n\n\nAlso choose the number that will be the maximum number your computer can pick.\n\n";
cin>>maximum;
cout<<"\n\n\n";
srand(time(0));
guess=((rand()%maximum)+1);
cout<<guess<<endl;
tries++;
while(guess!=number){
if(guess>number){
if(times==1){
guess=guess-maximum/4;
}
if(times==2){
guess=guess-maximum/4/4;
}
if(times==3){
guess=guess-100;
}
if(times==4){
guess=guess-50;
}
if(times==5){
guess=guess-25;
}
if(times==6){
guess=guess-10;
}
if(times==7){
guess=guess-5;
}
if(times==8){
guess--;
}
compare=1;
tries++;
cout<<guess<<endl;
}
if(compare==1 and guess<number and times!=8){
times=times+1;
}
if(guess<number or go==2){
if(times==1){
guess=guess+maximum/4;
}
if(times==2){
guess=guess+maximum/4/4;
}
if(times==3){
guess=guess+100;
}
if(times==4){
guess=guess+50;
}
if(times==5){
guess=guess+25;
}
if(times==6){
guess=guess+10;
}
if(times==7){
guess=guess+5;
}
if(times==8){
guess++;
}
compare=2;
tries++;
cout<<guess<<endl;
}
if(compare==2 and guess>number and times!=8){
times=times+1;
}
}
cout<<"\n\n\n\aYour computer found your number, "<<number<<"!!! It found it in "<<tries<<" tries.\n\n\n";
cout<<"Would you like to restart? (1) for Yes and (2) for No.";
restart=0;
while(restart!=1 and restart!=2){
cin>>restart;
}
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
}
int main()
{
while(gameRun==1){
choice=0;
cout<<"Do you want to try and guess a computer generated number (1),\nor have the computer guess a number of your choice (2)?\n\n";
while(choice!=1 and choice!=2){
cin>>choice;
}
cout<<"\n\n\n\n\n";
if(choice==1){
personGuess();
}
if(choice==2){
compGuess();
}
cout<<"Do you want to repick the game type (1),\nor completely quit the game (2)?\n\n";
gameRun=0;
while(gameRun!=1 and gameRun!=2){
cin>>gameRun;
}
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
cout<<"Guessing Game script finished.\n\n";
system("pause");
}








\\\\This line is not part of the code, just me saying there is a total of 149 lines in my Guessing Game Program. :D \\\\[/source]

[source lang="cpp"]#include <iostream>
#include <cstdlib>
using namespace std;

int n=0,m=0;

int main()
{
cout << "Choose a number to run the Matrix.\n\n";
n=0;m=0;
while(n<100000 or n>999999998){
cin>>n;
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
if(n<100000){cout<<"Number is too small, try again.\n\n\n";}
if(n>999999998){cout<<"Number is too big try again.";}
if(n>999999999){cout<<"Number is so big you just crashed the Matrix. Just saying.";}
}
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMake sure to look for patterns!!! ;D";
while(m!=100000000){m++;}
while(1){cout<<n;}
cout<<"Matrix program script finished.\n\n";
system("pause");
}










\\\\This line is not part of the code, just me saying there is a total of 21 lines in my Matrix Program. :D \\\\[/source]

[source lang="cpp"]#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
using namespace std;

int topLeft=0,topCenter=0,topRight=0,middleLeft=0,middleCenter=0,middleRight=0,bottomLeft=0,bottomCenter=0,bottomRight=0,turn=0,restart=1,playerMove=0,compMove=0,playerMoveAccept=0,compMoveAccept=0,win=0,fourCorners=0,care=0,chance=0,difficulty=0,placement=0;


void compAI(){
care=1;
srand(time(0));
chance=((rand()%10)+1);
if(chance>=difficulty){
if(middleCenter==1 and topLeft==0 and topRight==0 and bottomLeft==0 and bottomRight==0){
srand(time(0));
placement=((rand()%4)+1);
if(placement==1){topLeft=2;care=0;}
if(placement==2){topRight=2;care=0;}
if(placement==3){bottomLeft=2;care=0;}
if(placement==4){bottomRight=2;care=0;}
}

if(fourCorners==1 and care==1){
if(topLeft==0 and topRight==2 and bottomLeft==2 and bottomRight==2 and care==1){topLeft=2;care=0;}
if(topLeft==2 and topRight==0 and bottomLeft==2 and bottomRight==2 and care==1){topRight==2;care=0;}
if(topLeft==2 and topRight==2 and bottomLeft==0 and bottomRight==2 and care==1){bottomLeft=2;care=0;}
if(topLeft==2 and topRight==2 and bottomLeft==2 and bottomRight==0 and care==1){bottomRight==2;care=0;}
}
if(topLeft==2 and topRight==2 and bottomLeft==2 and bottomRight==2 and middleCenter==0 and care==1){middleCenter=2;care=0;}
if(topCenter==2 and bottomCenter==2 and middleLeft==2 and middleRight==2 and middleCenter==0 and care==1){middleCenter=2;care=0;}
if(topLeft==2 and topCenter==0 and topRight==2 and middleCenter==2 and bottomCenter==2 and care==1){topCenter=2;care=0;}
if(bottomLeft==2 and bottomCenter==0 and bottomRight==2 and middleCenter==2 and topCenter==2 and care==1){bottomCenter=0;care=0;}
if(topLeft==2 and middleLeft==0 and bottomLeft==2 and middleCenter==2 and middleRight==2 and care==1){middleLeft=2;care=0;}
if(topRight==2 and middleRight==0 and bottomRight==2 and middleCenter==2 and middleLeft==2 and care==1){middleRight=2;care=0;}
if(topLeft==2 and middleLeft==0 and bottomLeft==2 and care==1){middleLeft=2;care=0;}
if(topCenter==2 and middleCenter==0 and bottomCenter==2 and care==1){middleCenter=2;care=0;}
if(topRight==2 and middleRight==0 and bottomRight==2 and care==1){middleRight=2;care=0;}
if(topLeft==0 and middleLeft==2 and bottomLeft==2 and care==1){topLeft=2;care=0;}
if(topCenter==0 and middleCenter==2 and bottomCenter==2 and care==1){topCenter=2;care=0;}
if(topRight==0 and middleRight==2 and bottomRight==2 and care==1){topRight=2;care=0;}
if(topLeft==2 and middleLeft==2 and bottomLeft==0 and care==1){bottomLeft=2;care=0;}
if(topCenter==2 and middleCenter==2 and bottomCenter==0 and care==1){bottomCenter=2;care=0;}
if(topRight==2 and middleRight==2 and bottomRight==0 and care==1){bottomRight=2;care=0;}
if(topLeft==2 and topCenter==2 and topRight==0 and care==1){topRight=2;care=0;}
if(middleLeft==2 and middleCenter==2 and middleRight==0 and care==1){middleRight=2;care=0;}
if(bottomLeft==2 and bottomCenter==2 and bottomRight==0 and care==1){bottomRight=2;care=0;}
if(topLeft==2 and topCenter==0 and topRight==2 and care==1){topCenter=2;care=0;}
if(middleLeft==2 and middleCenter==0 and middleRight==2 and care==1){middleCenter=2;care=0;}
if(bottomLeft==2 and bottomCenter==0 and bottomRight==2 and care==1){bottomCenter=2;care=0;}
if(topLeft==0 and topCenter==2 and topRight==2 and care==1){topLeft=2;care=0;}
if(middleLeft==0 and middleCenter==2 and middleRight==2 and care==1){middleLeft=2;care=0;}
if(bottomLeft==0 and bottomCenter==2 and bottomRight==2 and care==1){bottomLeft=2;care=0;}
if(topLeft==2 and middleCenter==0 and bottomRight==2 and care==1){middleCenter=2;care=0;}
if(topLeft==0 and middleCenter==2 and bottomRight==2 and care==1){topLeft=2;care=0;}
if(topLeft==2 and middleCenter==2 and bottomRight==0 and care==1){bottomRight=2;care=0;}
if(topRight==2 and middleCenter==0 and bottomLeft==2 and care==1){middleCenter=2;care=0;}
if(topRight==0 and middleCenter==2 and bottomLeft==2 and care==1){topRight=2;care=0;}
if(topRight==2 and middleCenter==2 and bottomLeft==0 and care==1){bottomLeft=2;care=0;}

if(fourCorners==1 and care==1){
if(topLeft==0 and topRight==1 and bottomLeft==1 and bottomRight==1 and care==1){topLeft=2;care=0;}
if(topLeft==1 and topRight==0 and bottomLeft==1 and bottomRight==1 and care==1){topRight==2;care=0;}
if(topLeft==1 and topRight==1 and bottomLeft==0 and bottomRight==1 and care==1){bottomLeft=2;care=0;}
if(topLeft==1 and topRight==1 and bottomLeft==1 and bottomRight==0 and care==1){bottomRight==2;care=0;}
}
if(topLeft==1 and topRight==1 and bottomLeft==1 and bottomRight==1 and middleCenter==0 and care==1){middleCenter=2;care=0;}
if(topCenter==1 and bottomCenter==1 and middleLeft==1 and middleRight==1 and middleCenter==0 and care==1){middleCenter=2;care=0;}
if(topLeft==1 and topCenter==0 and topRight==1 and middleCenter==1 and bottomCenter==1 and care==1){topCenter=2;care=0;}
if(bottomLeft==1 and bottomCenter==0 and bottomRight==1 and middleCenter==1 and topCenter==1 and care==1){bottomCenter=0;care=0;}
if(topLeft==1 and middleLeft==0 and bottomLeft==1 and middleCenter==1 and middleRight==1 and care==1){middleLeft=2;care=0;}
if(topRight==1 and middleRight==0 and bottomRight==1 and middleCenter==1 and middleLeft==1 and care==1){middleRight=2;care=0;}
if(topLeft==1 and middleLeft==0 and bottomLeft==1 and care==1){middleLeft=2;care=0;}
if(topCenter==1 and middleCenter==0 and bottomCenter==1 and care==1){middleCenter=2;care=0;}
if(topRight==1 and middleRight==0 and bottomRight==1 and care==1){middleRight=2;care=0;}
if(topLeft==0 and middleLeft==1 and bottomLeft==1 and care==1){topLeft=2;care=0;}
if(topCenter==0 and middleCenter==1 and bottomCenter==1 and care==1){topCenter=2;care=0;}
if(topRight==0 and middleRight==1 and bottomRight==1 and care==1){topRight=2;care=0;}
if(topLeft==1 and middleLeft==1 and bottomLeft==0 and care==1){bottomLeft=2;care=0;}
if(topCenter==1 and middleCenter==1 and bottomCenter==0 and care==1){bottomCenter=2;care=0;}
if(topRight==1 and middleRight==1 and bottomRight==0 and care==1){bottomRight=2;care=0;}
if(topLeft==1 and topCenter==1 and topRight==0 and care==1){topRight=2;care=0;}
if(middleLeft==1 and middleCenter==1 and middleRight==0 and care==1){middleRight=2;care=0;}
if(bottomLeft==1 and bottomCenter==1 and bottomRight==0 and care==1){bottomRight=2;care=0;}
if(topLeft==1 and topCenter==0 and topRight==1 and care==1){topCenter=2;care=0;}
if(middleLeft==1 and middleCenter==0 and middleRight==1 and care==1){middleCenter=2;care=0;}
if(bottomLeft==1 and bottomCenter==0 and bottomRight==1 and care==1){bottomCenter=2;care=0;}
if(topLeft==0 and topCenter==1 and topRight==1 and care==1){topLeft=2;care=0;}
if(middleLeft==0 and middleCenter==1 and middleRight==1 and care==1){middleLeft=2;care=0;}
if(bottomLeft==0 and bottomCenter==1 and bottomRight==1 and care==1){bottomLeft=2;care=0;}
if(topLeft==1 and middleCenter==0 and bottomRight==1 and care==1){middleCenter=2;care=0;}
if(topLeft==0 and middleCenter==1 and bottomRight==1 and care==1){topLeft=2;care=0;}
if(topLeft==1 and middleCenter==1 and bottomRight==0 and care==1){bottomRight=2;care=0;}
if(topRight==1 and middleCenter==0 and bottomLeft==1 and care==1){middleCenter=2;care=0;}
if(topRight==0 and middleCenter==1 and bottomLeft==1 and care==1){topRight=2;care=0;}
if(topRight==1 and middleCenter==1 and bottomLeft==0 and care==1){bottomLeft=2;care=0;}
}
}


void gameDisplay(){
if(topLeft==0){cout<<" ";}
if(topLeft==1){cout<<"X";}
if(topLeft==2){cout<<"O";}
cout<<"|";
if(topCenter==0){cout<<" ";}
if(topCenter==1){cout<<"X";}
if(topCenter==2){cout<<"O";}
cout<<"|";
if(topRight==0){cout<<" ";}
if(topRight==1){cout<<"X";}
if(topRight==2){cout<<"O";}
cout<<endl;
cout<<"_____"<<endl;
if(middleLeft==0){cout<<" ";}
if(middleLeft==1){cout<<"X";}
if(middleLeft==2){cout<<"O";}
cout<<"|";
if(middleCenter==0){cout<<" ";}
if(middleCenter==1){cout<<"X";}
if(middleCenter==2){cout<<"O";}
cout<<"|";
if(middleRight==0){cout<<" ";}
if(middleRight==1){cout<<"X";}
if(middleRight==2){cout<<"O";}
cout<<endl;
cout<<"_____"<<endl;
if(bottomLeft==0){cout<<" ";}
if(bottomLeft==1){cout<<"X";}
if(bottomLeft==2){cout<<"O";}
cout<<"|";
if(bottomCenter==0){cout<<" ";}
if(bottomCenter==1){cout<<"X";}
if(bottomCenter==2){cout<<"O";}
cout<<"|";
if(bottomRight==0){cout<<" ";}
if(bottomRight==1){cout<<"X";}
if(bottomRight==2){cout<<"O";}
cout<<endl<<endl<<endl<<endl<<endl;
}


void playerInput(){
playerMoveAccept=0;
while(playerMoveAccept==0){
playerMove=0;
while(playerMove!=1 and playerMove!=2 and playerMove!=3 and playerMove!=4 and playerMove!=5 and playerMove!=6 and playerMove!=7 and playerMove!=8 and playerMove!=9 and playerMove!=99){
cin>>playerMove;
if(playerMove==1 and topLeft==0){topLeft=1;playerMoveAccept=1;}
if(playerMove==1 and topLeft==1 and topLeft==2){playerMove=0;}
if(playerMove==2 and topCenter==0){topCenter=1;playerMoveAccept=1;}
if(playerMove==2 and topCenter==1 and topCenter==2){playerMove=0;}
if(playerMove==3 and topRight==0){topRight=1;playerMoveAccept=1;}
if(playerMove==3 and topRight==1 and topRight==2){playerMove=0;}
if(playerMove==4 and middleLeft==0){middleLeft=1;playerMoveAccept=1;}
if(playerMove==4 and middleLeft==1 and middleLeft==2){playerMove=0;}
if(playerMove==5 and middleCenter==0){middleCenter=1;playerMoveAccept=1;}
if(playerMove==5 and middleCenter==1 and middleCenter==2){playerMove=0;}
if(playerMove==6 and middleRight==0){middleRight=1;playerMoveAccept=1;}
if(playerMove==6 and middleRight==1 and middleRight==2){playerMove=0;}
if(playerMove==7 and bottomLeft==0){bottomLeft=1;playerMoveAccept=1;}
if(playerMove==7 and bottomLeft==1 and bottomLeft==2){playerMove=0;}
if(playerMove==8 and bottomCenter==0){bottomCenter=1;playerMoveAccept=1;}
if(playerMove==8 and bottomCenter==1 and bottomCenter==2){playerMove=0;}
if(playerMove==9 and bottomRight==0){bottomRight=1;playerMoveAccept=1;}
if(playerMove==9 and bottomRight==1 and bottomRight==2){playerMove=0;}
if(playerMove==99){cout<<"\n\nDo you want to Quit? 1} Yes 2} No\n\n";
while(playerMove!=1 and playerMove!=2){
cin>>playerMove;
}
if(playerMove==1){playerMove=99;win=8;}
if(playerMove==2){playerMove=0;cout<<"\n\n\n\n\n";gameDisplay();}
}
cout<<"\n\n\n\n\n";
}
}
}


void compInput(){
compAI();
compMoveAccept=0;
if(care==1){
while(compMoveAccept==0){
srand(time(0));
compMove=((rand()%9)+1);
if(compMove==1 and topLeft==0){topLeft=2;compMoveAccept=1;}
if(compMove==1 and topLeft==1 and topLeft==2){compMove=0;}
if(compMove==2 and topCenter==0){topCenter=2;compMoveAccept=1;}
if(compMove==2 and topCenter==1 and topCenter==2){compMove=0;}
if(compMove==3 and topRight==0){topRight=2;compMoveAccept=1;}
if(compMove==3 and topRight==1 and topRight==2){compMove=0;}
if(compMove==4 and middleLeft==0){middleLeft=2;compMoveAccept=1;}
if(compMove==4 and middleLeft==1 and middleLeft==2){compMove=0;}
if(compMove==5 and middleCenter==0){middleCenter=2;compMoveAccept=1;}
if(compMove==5 and middleCenter==1 and middleCenter==2){compMove=0;}
if(compMove==6 and middleRight==0){middleRight=2;compMoveAccept=1;}
if(compMove==6 and middleRight==1 and middleRight==2){compMove=0;}
if(compMove==7 and bottomLeft==0){bottomLeft=2;compMoveAccept=1;}
if(compMove==7 and bottomLeft==1 and bottomLeft==2){compMove=0;}
if(compMove==8 and bottomCenter==0){bottomCenter=2;compMoveAccept=1;}
if(compMove==8 and bottomCenter==1 and bottomCenter==2){compMove=0;}
if(compMove==9 and bottomRight==0){bottomRight=2;compMoveAccept=1;}
if(compMove==9 and bottomRight==1 and bottomRight==2){compMove=0;}
cout<<"\n\n\n\n\n";
}
}
}


void winCheck(){
if(topLeft==1 and topCenter==1 and topRight==1){win=1;}
if(middleLeft==1 and middleCenter==1 and middleRight==1){win=1;}
if(bottomLeft==1 and bottomCenter==1 and bottomRight==1){win=1;}
if(topLeft==1 and middleLeft==1 and bottomLeft==1){win=1;}
if(topCenter==1 and middleCenter==1 and bottomCenter==1){win=1;}
if(topRight==1 and middleRight==1 and bottomRight==1){win=1;}
if(topLeft==1 and middleCenter==1 and bottomRight==1){win=1;}
if(topRight==1 and middleCenter==1 and bottomLeft==1){win=1;}
if(topLeft==1 and bottomLeft==1 and topRight==1 and bottomRight==1 and middleCenter==1){win==5;}
if(topCenter==1 and bottomCenter==1 and middleLeft==1 and middleRight==1 and middleCenter==1){win=5;}
if(topLeft==1 and topCenter==1 and topRight==1 and middleCenter==1 and bottomCenter==1){win=5;}
if(bottomLeft==1 and bottomCenter==1 and bottomRight==1 and middleCenter==1 and topCenter==1){win=5;}
if(topLeft==1 and middleLeft==1 and bottomLeft==1 and middleCenter==1 and middleRight==1){win=5;}
if(middleLeft==1 and middleCenter==1 and middleRight==1 and topRight==1 and bottomRight==1){win=5;}
if(fourCorners==1){
if(topLeft==1 and bottomLeft==1 and topRight==1 and bottomRight==1){win=7;}
}

if(topLeft!=0 and topCenter!=0 and topRight!=0 and middleLeft!=0 and middleCenter!=0 and middleRight!=0 and bottomLeft!=0 and bottomCenter!=0 and bottomRight!=0){win==3;}

if(topLeft==2 and topCenter==2 and topRight==2){win=2;}
if(middleLeft==2 and middleCenter==2 and middleRight==2){win=2;}
if(bottomLeft==2 and bottomCenter==2 and bottomRight==2){win=2;}
if(topLeft==2 and middleLeft==2 and bottomLeft==2){win=2;}
if(topCenter==2 and middleCenter==2 and bottomCenter==2){win=2;}
if(topRight==2 and middleRight==2 and bottomRight==2){win=2;}
if(topLeft==2 and middleCenter==2 and bottomRight==2){win=2;}
if(topRight==2 and middleCenter==2 and bottomLeft==2){win=2;}
if(topLeft==2 and bottomLeft==2 and topRight==2 and bottomRight==2 and middleCenter==2){win=4;}
if(topCenter==2 and bottomCenter==2 and middleLeft==2 and middleRight==2 and middleCenter==2){win=4;}
if(topLeft==2 and topCenter==2 and topRight==2 and middleCenter==2 and bottomCenter==2){win=4;}
if(bottomLeft==2 and bottomCenter==2 and bottomRight==2 and middleCenter==2 and topCenter==2){win=4;}
if(topLeft==2 and middleLeft==2 and bottomLeft==2 and middleCenter==2 and middleRight==2){win=4;}
if(middleLeft==2 and middleCenter==2 and middleRight==2 and topRight==2 and bottomRight==2){win=4;}
if(fourCorners==1){
if(topLeft==2 and bottomLeft==2 and topRight==2 and bottomRight==2){win=6;}
}
}


int main(){
while (restart==1){
cout<<"What Difficulty do you want? 1} Easy 2} Medium 3} Hard\n\n";
difficulty=0;
while(difficulty!=1 and difficulty!=2 and difficulty!=3){
cin>>difficulty;
}
cout<<"\n\n";
if(difficulty==1){
difficulty=7;
}
if(difficulty==2){
difficulty=6;
}
if(difficulty==3){
difficulty=0;
}
cout<<"NOTE: Type 99 on your turn for an option to quit mid-game.\n\n\n\n\n";
cout<<"Do you want to play with the extra 'Four Corners' rule?\n(Press '1' for yes or '2' for no.)\n\n";
fourCorners=0;
while(fourCorners!=1 and fourCorners!=2){
cin>>fourCorners;
}
cout<<endl<<endl<<endl<<endl<<endl;
win=0;topLeft=0;topCenter=0;topRight=0;middleLeft=0;middleCenter=0;middleRight=0;bottomLeft=0;bottomCenter=0;bottomRight=0;
srand(time(0));
turn=((rand()%2)+1);
gameDisplay();
while(win==0){

while (turn==1 and win==0){
cout<<"Your turn!\n\n";
playerInput();
turn=2;
gameDisplay();
winCheck();
}

while (turn==2 and win==0){
cout<<"Computer's turn!\n\n\n\n\n";
compInput();
turn=1;
gameDisplay();
winCheck();
}

}
if(win==1){
cout<<"Hurrah!! You won against your computer!!!\n\n\n";
}

if(win==2){
cout<<"You lost against your own computer!!!\n\n\n";
}

if(win==3){
cout<<"Wow! You tied against your computer!!!!\n\n\n";
}

if(win==4){
cout<<"What the...... Your computer just owned you!!!!!! Your computer got a double win!!!!!!!!!!\n\n\n";
}

if(win==5){
cout<<"Dang! You just double beat your own computer!!! ppppsssshhh So much for Artificial Intelligence hahaha:)\n\n\n";
}

if(win==6){
cout<<"Woah!! Your computer used the Four Corners rule against you!!!\n\n\n";
}

if(win==7){
cout<<"Woah!! You used the Four Corners rule againt your computer!!!\n\n\n";
}

if(win==8){cout<<"You quit the game? Hopefully not because of a bug...;D\n\n\n";}

cout<<"Would you like to retart?\n(Press '1' for yes or '2' for no.)\n";
restart=0;
while(restart!=1 and restart!=2){cin>>restart;}
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

}
cout<<"Tic-Tac-Toe game script finished.\n\n";
system("pause");
}











\\\\This line is not part of the code, just me saying there is a total of 337 lines in my Tic-Tac-Toe Program. :D \\\\[/source]


Feel free to plug this into any compiler/debugger and check to see how it runs and plays.

P.S.~ I'm pretty sure you know which one of these games is the "Half Game":D

~Saint Squireen
Advertisement
[attachment=11019:Guessing Game Source Code.txt][attachment=11020:Matrix Source Code.txt][attachment=11021:Tic-Tac-Toe Source Code.txt]

~Saint Squireen
Your code is okay.

First of all, this is mostly basic C, not C++. You don't have any classes and use global variable. Learning object-oriented development would be the next logical step in your training. You do use std (cin and cout) but that's about it. Try using containers like list, map and vectors.
Your tictactoe source use a whole lot of "if" lines. I didn't analyse it, but I'm pretty sure it could be resumed to a clearer algorithm taking much less lines of code using mathematics and logic instead of handling every possible possibilities individually.
Also, I know it was not a need in these games, but you only used variables of type int. Always try to select the best type who use the less memory for the data you handle. Instead of validating maximum using a made-up value (99999999), try using constant that means something like INT_MAX available in <limits.h>

Also, what do you mean by "move on"? You always improve while programming, it never stop. If you mean learn new things, only you can answer that. Do you understand the code you wrote? If so, go ahead because it can only help learning new ways of thinking and doing that same thing in a more efficient manner.
I understand everything I wrote and yes i did mean lern new things. Thanks for the insight I really needed it!:)

~Saint Squireen
I don’t really get the point of this question.
What is the alternative to “moving on”? To not change how you write code? To not grow, learn, and develop your skills, but instead to just stay where you are?
Why would you even ask this?

I would say you have no choice but to “move on” because staying where you are would not be a good thing.
The code is convoluted and lacks comments. It is a mess.

As mentioned, you need to represent the logic of the game as mathematical algorithms, not if’s to represent every possible state of the game.
An alternative to that is to use data structures that can be processed by “mini-engines”.

Next, where is the whitespace?
Have you ever heard the term, “Wall of Text”? It appears on forums when people write long diatribes without breaking things into paragraphs.
Whitespace in code exists for a reason—it helps people break the text into readable segments.
Here are 2 examples of different styles that people might use:
number = ((rand() % maximum) + 1);
number = ((rand()%maximum)+1);

While no one can agree on what the best style is, everyone can agree that the worst style is to use no whitespace at all. It is not a disease. Stop avoiding it.

Then you need comments. This is one of the biggest differences between a pro and a beginner, yet is the easiest thing to get right.

Then there is your use of globals. As mentioned above, this is C++. You don’t have a single local variable. Where did you learn to code like this? Are you coming from another language? I have never seen this before.
If you have any intentions of getting anywhere with programming, this is the most critical thing to unlearn. There is virtually no need for globals ever in any code, though how pedantic you go with this concept is up to you. Some people refuse to use any globals of any kind for any reason, while some use them just sparingly for what they consider to be exceptional cases.
But your use of globals is simply criminal.


Creating algorithms to express your logic takes time to learn.
Adding whitespace and comments, and using locals instead of globals do not. These are over-the-night things you can do to improve the quality of your code, so there is no excuse not be be incorporating these things into the code that you will be writing starting from tomorrow.


Moving on is your only choice. And always will be.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Your code is kinda bad.

Why are you seeding rand multiple times?
In the first code, you are calling srand in a loop and in the third one, you are calling srand twice.
And there is something wrong with your excessive use of if statements.
Even such heavy if statements were necessary, you should always comment the code so that you don't have to waste time figuring out what you intended in your code.
An invisible text.
Don't be so hard on him.

Saint Squireen, What is your goal?
What would you like to program? I assume games? Do you want to work in a game company?

I'm not trying to be rude but I'll give you an honest answer:
Am I ready to move on based on the style of programming in these games?[/quote]
Answer: No, you are not ready to move on with that style of programming. It is bad coding.

What kind of tips can you give me to push me in the direction of Industrial Qualified style of game programming[/quote]
The tips I can give is: Write neat. Use classes, tons of methods, etc.
Also learn the theory about everything.

In your response I want 2 answers from you:
Could you explain me, in a neat/technical sentence, how a pointer works?
Could you explain me what the difference is between a local, global, member variable? Also in in neat sentence.

These things you are supposed to know as programmer. Knowing what you are writing.

I've found this pdf yesteday, I recommend you to have a look at this:
http://www.angelfire...lusin21days.pdf


~EngineProgrammer
The last block of code makes my eyes bleed, but let's all be honest - most of us also started like this, hardcoding every possible state with a bunch of if/then's. Then we noticed/got told that these states could be logically grouped into categories, and eventually you end up with beautiful code with only a couple conditionals per line and no more than two nested loops, all isolated in a single flexible method that you can put into a code library for easy reuse in your other projects.

However, it takes time, experience, and practice to discover, identify, and make use of these patterns, so the only advice I could give you is, pick one your more harder games, and try and rewrite it more elegantly. You'll instinctively know when you're doing it right: good code should be beautiful to read.

----------

If you would like more specific feedback, look at your "guess the number" game. First, lay off the \n's! If you really need formatting, try and group these into some form of constant. And instead of the fifteen or so newlines at the end of the PersonGuess() method, why not just erase the console screen to start over? That would make more sense in my opinion, it would be more intuitive. That's just a detail though, console formatting is always a bit of a pain using only standard output.

Secondly, your "computer AI" for this game is... defective. The (provably) fastest way for the computer to guess the number is by binary search, which can be concisely implemented in about ten lines of code. I don't C++ so I don't know the exact syntax, but the pseudocode goes like this:

1. Let Lo = 0, Hi = maxNumber. (Lo and Hi are variables)
2. Repeat forever steps 3 to 6.
... 3. Let computerGuess = (Lo + Hi) / 2
... 4. If actualGuess = computerGuess, the computer wins, break out of the loop.
... 5. If actualGuess < computerGuess, then let Hi = computerGuess - 1 and go to step 3.
... 6. If actualGuess > computerGuess, then let Lo = computerGuess, and go to step 3.

This is called binary search and the computer will guess your number in about log2(n) steps on average, where n is the maximum number he can guess. So for n = 100, it'll take the computer about 6-7 steps. For n = 1 million, it'll take it roughly 20 guesses. No need for some strange series of conditions (which, by the way, appear to be a hardcoded form of binary search...)

Unless, of course, you were trying to model a "bad AI" which made bad guesses, but even then you could've just used a variation of the binary search which wouldn't use the midpoint of Lo and Hi at each guess, but a random guess within the search interval for instance, which can end up being faster or slower (but on average the same speed). This way the computer will appear to actually "guess" instead of making mechanical choices. If that makes sense.

----------

Now, this might seem harsh, but you need to learn to code elegantly before moving on to more complex stuff, because, well, it's pretty simple why: you won't be able to get away with your current method in more complex games. You will simply have too many conditions and variables to keep track of. So, no, you are not ready to move on, you need to step back and improve your coding skills. All three games you have attached to this topic are in dire need of rewriting, and you would benefit immensely from doing just that. Though don't hesitate to create new topics if you need specific coding advice while doing this, I'm sure many people would be happy to guide you.

Also, reflect on this quote, which I find to be extremely true to programming in general:
Perfection is achieved, not when there is nothing left to add, but when there is nothing left to take away.[/quote]

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


In your response I want 2 answers from you:
Could you explain me, in a neat/technical sentence, how a pointer works?
Could you explain me what the difference is between a local, global, member variable? Also in in neat sentence.


I'm not him but I couldn't resist this little challenge. Always fun to see if I've listened closely enough during my school lessons.
Actually created a user here on the awesome GD.net to post this tongue.png

Pointer: A pointer work in the way that it gives you direct access to the memorybank/memoryspace in which a variable is stored on your computer. Meaning the chunk of memory that is reserved for this variable. Meaning if you forget to *pointer=0 before reassigned it another value you will create memory leaks as the memorybank is still "locked".

Variables:
Local - Local variables are variables accessible by all functions within the class where it is created.
Example:
int main{
int a;
}
//Destroyed when the block/function/class ends

Member - Member variables are only accessible within the scope where they are created meaning inside a function for instance
Example:
int main{
void randomName(){
int a;
}
}
//Destroyed when the block/function ends

Global - Global variables are accessible from everywhere in your program, hence the name global.
Example:

int a;
int main(){
}
//Destroyed when the program terminates


Wow that was more than a sentence, sorry.

Of course I would appriciate it a lot if you would confirm if I have indeed been listening or need to redo my last semester ;)

You are of course welcome to PM me the answer as to not spoil it completely.

And sorry for hijacking/butting in on the post smile.png
Your response to pointers is wrong in concept.
Your response to members is wrong entirely.

As for pointers, you gave basically a textbook definition of how they are used, but not really what they are. They are nothing but integers whose values can be interpreted as an address. Their sizes change between platforms but to keep things simple we should assume Windows x86 (32-bit pointers).
0x00000100 can’t be a pointer but 0x00400000 is. It is simply a value that points to valid memory. Though some values that are meant to be pointers could point to invalid memory if your program has errors.


Members are “attributes” of classes. You posted an example in which a function was declared inside another function. This is entirely illegal.
For this, you need to redo some of your learning.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement