hyperic
+ Reply to Thread
Results 1 to 6 of 6

Thread: Rock Paper Scissors in C++

  1. #1
    Join Date
    Sep 2006
    Posts
    1,649

    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)+*;
        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();
    }

  2. #2
    Join Date
    Jan 2005
    Posts
    623
    I rewrote your program in 6 lines of code:
    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]];
    [url=http://boninroad.com/syntax******/rockpaperscissors.php]My Program[/url] - Hope its not to intense!
    Last edited by SyntaXmasteR; 09-27-2006 at 07:06 PM.
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  3. #3
    Join Date
    Jan 2005
    Posts
    623
    Ohhhh Here is [url=http://boninroad.com/syntax******/games/rockpaperscissors.php]Rock - Paper - Scissors : V*.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', "*"=> '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>
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  4. #4
    Join Date
    Sep 2006
    Posts
    1,649

    but

    But I wrote it in C++, so it took a few more lines

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

  5. #5
    Join Date
    Jan 2005
    Posts
    623
    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.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

  6. #6
    Join Date
    Sep 2006
    Posts
    1,649

    ok

    Oh, ok, thanks

+ Reply to Thread

Similar Threads

  1. share Rock pictures Sexboy-*
    By nanogy in forum Internet Privacy
    Replies: 1
    Last Post: 10-23-2009, 06:35 AM
  2. Between an encryption rock and data loss hard place
    By phantomplay in forum Security & Encryption
    Replies: 0
    Last Post: 01-23-2007, 11:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts