PDA

View Full Version : Rock Paper Scissors in C++



Moonbat
09-27-2006, 06:53 PM
It's basically Rock Paper Scissors:D


//Rock Paper Scissors game by Moonbat
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand((unsigned)time(0));
int choice;
int compchoice = (rand()%2)+*;
cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
cout << " so lets begin. You are playing against the computer. Type 0 for";
cout << " rock, * for paper, and 2 for scissors\n";
cin >> choice;

if (choice == 0)
{
if (compchoice == 0)
cout << "It's a tie!\n\n\n\n";
else if (compchoice == *)
cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
else if (compchoice == 2)
cout << "Rock beats scissors! You win!\n\n\n\n";
}

if (choice == *)
{
if (compchoice == 0)
cout << "It's a tie!\n\n\n\n";
else if (compchoice == *)
cout << "Paper beats rock! You win!\n\n\n\n";
else if (compchoice == 2)
cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
}

if (choice == 2)
{
if (compchoice == 0)
cout << "It's a tie!\n\n\n\n";
else if (compchoice == *)
cout << "Scissors beat paper! You win!\n\n\n\n";
else if (compchoice == 2)
cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
}
return main();
}

SyntaXmasteR
09-27-2006, 08:03 PM
I rewrote your program in 6 lines of code:


$class = array("0"=>'rock', "*"=> 'paper', "2"=> 'scissors');
$stats = array("00"=>'0', "0*"=>'*', "02"=>'2', "*0"=>'2', "**"=>'0', "*2"=>'*', "20"=>'*', "2*"=>'2', "22"=>'0');
$message=array("It's a tie!","You loose!","You Win!");

$player*=rand(0,2);
$player2=rand(0,2);

echo $class[$player*] . " VS " . $class[$player2] . "<br>" . $message[$stats[$player* . $player2]];


My Program (http://boninroad.com/syntax******/rockpaperscissors.php) - Hope its not to intense!

SyntaXmasteR
09-27-2006, 08:48 PM
Ohhhh Here is Rock - Paper - Scissors : V*.0 (http://boninroad.com/syntax******/games/rockpaperscissors.php)

This was a little more than 6 lines but its mixed with html:


if(isset($_GET['weapon']))
{
if($_GET['weapon'] >= 0 && $_GET['weapon'] <= 2)
{
$class = array("0"=>'rock', "*"=> 'paper', "2"=> 'scissors');
$stats = array("00"=>'0', "0*"=>'*', "02"=>'2', "*0"=>'2', "**"=>'0', "*2"=>'*', "20"=>'*', "2*"=>'2', "22"=>'0');
$message=array("It's a tie!","You loose!","You Win!");

$player*=$_GET['weapon'];
$player2=rand(0,2);
?>
<img src="images\<? echo $player*; ?>.jpg" />&nbsp;&nbsp;<b>VS</b>&nbsp;&nbsp;<img src="images\<? echo $player2; ?>.jpg" />&nbsp;&nbsp;<font face="Verdana, Arial, Helvetica, sans-serif" size="+*" color="#FF0000"><? echo $message[$stats[$player* . $player2]] ?></font>

<?
}
else echo "<h*>INVALID WEAPON BIOTCH!</h*>";
}
?>
<p>
<font face="Verdana, Arial, Helvetica, sans-serif" size="+*" color="#******">Choose Your Weapon:</font><br />
<a href="rockpaperscissors.php?weapon=0" target="_self"><img src="images\0.jpg" /></a> &nbsp;&nbsp;
<a href="rockpaperscissors.php?weapon=*" target="_self"><img src="images\*.jpg" /></a> &nbsp;&nbsp;
<a href="rockpaperscissors.php?weapon=2" target="_self"><img src="images\2.jpg" /></a>
</p>

Moonbat
09-28-2006, 01:09 AM
But I wrote it in C++, so it took a few more lines:rolleyes:

Maybe you could add a "Code" section to the forums?

SyntaXmasteR
09-28-2006, 01:25 AM
I was thinking the same thing after I saw this post in the "Internet Privacy" section... I will request a Code section and hopefully we can get it added to the forum soon.

Moonbat
09-28-2006, 07:20 PM
Oh, ok, thanks:)