I finally have enough knowledge to put together simple games.
I made this program last night. the random method is working nicely with the RPG I am working on. anyway here is the code hope I am doing the code tacs right :P
Code:
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include <ctime>
int User_Score, Comp_Score;
int User_Option, Comp_Option;
char name[15];
int Q = 0;
int RandInt(int a,int b)
{
return a + rand() % (b - a + 1);
}
int main()
{
cout << "Paper/Scissor/Rock 0.1\n\n";
cout << "Please enter name: ";
cin >> name;
cout << "\n";
do
{
srand(time(NULL));
int x = RandInt(1,3);
system("pause");
system("cls");
cout << "Scoreboard:\t\t Q-uit\n\n"<<name<<": "<<User_Score;
cout << "\nComputer: "<<Comp_Score<<"\n\n";
cout << "Please select one of the following:\n\n";
cout << "1)Paper\n2)Scissors\n3)Rock\n\n";
cin >> User_Option;
cout << "\n";
Comp_Option = x; //Assigning Comp_Options value as x, the value of x
//changes between 1 and 3 every loop
//Here are all the possible out comes, relevant messages and variable updates
if(User_Option == 1 && Comp_Option == 1)
{
cout << "This round is a draw.\n";
}
else if(User_Option == 1 && Comp_Option == 2)
{
cout << "You lose try again.\n";
Comp_Score++;
}
else if(User_Option == 1 && Comp_Option == 3)
{
cout << "Congratulations you win.\n";
User_Score++;
}
else if(User_Option == 2 && Comp_Option == 1)
{
cout << "Congratulations you win.\n";
User_Score++;
}
else if(User_Option == 2 && Comp_Option == 2)
{
cout << "This round is a draw.\n";
}
else if(User_Option == 2 && Comp_Option == 3)
{
cout << "You lose try again.\n";
Comp_Score++;
}
else if(User_Option == 3 && Comp_Option == 1)
{
cout << "You lose try again.\n";
Comp_Score++;
}
else if(User_Option == 3 && Comp_Option == 2)
{
cout << "Congratulations you win.\n";
User_Score++;
}
else if(User_Option == 3 && Comp_Option == 3)
{
cout << "This round is a draw.\n";
}
else if(User_Option == Q)
{
Q = 1;
}
else
{
cout << "Invaild input.\n";
}
} //End Do
while(Q != 1); //The loop breaks
system("cls"); //Take the ingame data off
cout << "Goodbye\n\n";
system("pause"); //Pause so Goodbye msg is viewable
return 0;
} //End Int main()
Tell me what you think, it's my first "complete" game.
sorry I could get the file up on the net I am having probs with my comp.