+ Reply to Thread
Results 1 to 6 of 6
Thread: Rock Paper Scissors in C++
-
09-27-2006, 05:53 PM #1
Rock Paper Scissors in C++
It's basically Rock Paper Scissors
Code://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)+1; 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, 1 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 == 1) 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 == 1) { if (compchoice == 0) cout << "It's a tie!\n\n\n\n"; else if (compchoice == 1) 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 == 1) 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(); }
-
09-27-2006, 07:03 PM #2
I rewrote your program in 6 lines of code:
[url=http://boninroad.com/syntaxmaster/rockpaperscissors.php]My Program[/url] - Hope its not to intense!Code:$class = array("0"=>'rock', "1"=> 'paper', "2"=> 'scissors'); $stats = array("00"=>'0', "01"=>'1', "02"=>'2', "10"=>'2', "11"=>'0', "12"=>'1', "20"=>'1', "21"=>'2', "22"=>'0'); $message=array("It's a tie!","You loose!","You Win!"); $player1=rand(0,2); $player2=rand(0,2); echo $class[$player1] . " VS " . $class[$player2] . "<br>" . $message[$stats[$player1 . $player2]];Last edited by SyntaXmasteR; 09-27-2006 at 07:06 PM.
[url=http://www.syntaxmaster.info/tools/services.php]Speed Up Windows XP[/url]
[url=http://www.syntaxmaster.info/tools/ip.php]Get An Ip Address[/url]
[url=http://www.syntaxmaster.info/tools/base_converter.php]Base Converter[/url]
--------------------------------
[URL=http://www.boninroad.com/syntaxmaster/]Old Site[/URL]
[URL=http://www.syntaxmaster.info]Comming Soon[/URL]
-
09-27-2006, 07:48 PM #3
Ohhhh Here is [url=http://boninroad.com/syntaxmaster/games/rockpaperscissors.php]Rock - Paper - Scissors : V1.0[/url]
This was a little more than 6 lines but its mixed with html:
Code:if(isset($_GET['weapon'])) { if($_GET['weapon'] >= 0 && $_GET['weapon'] <= 2) { $class = array("0"=>'rock', "1"=> 'paper', "2"=> 'scissors'); $stats = array("00"=>'0', "01"=>'1', "02"=>'2', "10"=>'2', "11"=>'0', "12"=>'1', "20"=>'1', "21"=>'2', "22"=>'0'); $message=array("It's a tie!","You loose!","You Win!"); $player1=$_GET['weapon']; $player2=rand(0,2); ?> <img src="images\<? echo $player1; ?>.jpg" /> <b>VS</b> <img src="images\<? echo $player2; ?>.jpg" /> <font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="#FF0000"><? echo $message[$stats[$player1 . $player2]] ?></font> <? } else echo "<h1>INVALID WEAPON BIOTCH!</h1>"; } ?> <p> <font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="#333333">Choose Your Weapon:</font><br /> <a href="rockpaperscissors.php?weapon=0" target="_self"><img src="images\0.jpg" /></a> <a href="rockpaperscissors.php?weapon=1" target="_self"><img src="images\1.jpg" /></a> <a href="rockpaperscissors.php?weapon=2" target="_self"><img src="images\2.jpg" /></a> </p>[url=http://www.syntaxmaster.info/tools/services.php]Speed Up Windows XP[/url]
[url=http://www.syntaxmaster.info/tools/ip.php]Get An Ip Address[/url]
[url=http://www.syntaxmaster.info/tools/base_converter.php]Base Converter[/url]
--------------------------------
[URL=http://www.boninroad.com/syntaxmaster/]Old Site[/URL]
[URL=http://www.syntaxmaster.info]Comming Soon[/URL]
-
09-28-2006, 12:09 AM #4
but
But I wrote it in C++, so it took a few more lines
Maybe you could add a "Code" section to the forums?
-
09-28-2006, 12:25 AM #5
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.
[url=http://www.syntaxmaster.info/tools/services.php]Speed Up Windows XP[/url]
[url=http://www.syntaxmaster.info/tools/ip.php]Get An Ip Address[/url]
[url=http://www.syntaxmaster.info/tools/base_converter.php]Base Converter[/url]
--------------------------------
[URL=http://www.boninroad.com/syntaxmaster/]Old Site[/URL]
[URL=http://www.syntaxmaster.info]Comming Soon[/URL]
-
09-28-2006, 06:20 PM #6
ok
Oh, ok, thanks



Reply With Quote
