Rock-paper-scissors: Difference between revisions

Line 1,846:
Bye!
</pre>
 
=={{header|TorqueScript}}==
 
Rock Paper Scissors in TorqueScript:
 
<lang TorqueScript>
while(isobject(RockPaperScissors))
RockPaperScissors.delete();
 
new scriptObject(RockPaperScissors);
 
function RockPaperScissors::startGame(%this)
{
%this.idle = true;
echo("Starting rock paper scissors, please type choose(\"choice\"); to proceed!");
}
 
function RockPaperScissors::endGame(%this)
{
%this.idle = true;
}
 
function RockPaperScissors::main(%this)
{
%this.idle = 0;
if(getRandom(1,2) == 1)
{
%result = %this.getChoiceByUserFrequency();
}
else
{
%c[0] = "rock";
%c[1] = "paper";
%c[2] = "scissors";
%result = %c[getRandom(0,2)];
}
%userChoice = %this.current;
%winner = thisVSthat(%userChoice,%result);
if(%winner == 0)
{
echo("You both chose "@%userChoice@", tie!");
}
else
if(%winner == 1)
{
echo("You chose "@%userChoice@" computer chose "@%result@", you win!");
}
else
if(%winner == 2)
{
echo("You chose "@%userChoice@" computer chose "@%result@", you lose!");
}
%this.idle = true;
}
 
function RockPaperScissors::getChoiceByUserFrequency(%this)
{
%weakness["rock"] = "paper";
%weakness["paper"] = "Scissors";
%weakness["scissors"] = "rock";
%a[0] = %this.choice["rock"];
%a[1] = %this.choice["paper"];
%a[2] = %this.choice["Scissors"];
%b[0] = "rock";
%b[1] = "paper";
%b[2] = "scissors";
for(%i=0;%i<3;%i++)
{
%curr = %a[%i];
if(%temp $= "")
{
%temp = %curr;
%tempi = %i;
}
else
if(%curr > %temp)
{
%temp = %curr;
%tempi = %i;
}
}
return %weakness[%b[%tempi]];
}
 
function choose(%this)
{
%rps = rockPaperScissors;
if(!%rps.idle)
{
return 0;
}
else
if(%this !$= "rock" && %this !$= "paper" && %this !$= "scissors")
{
return 0;
}
 
%rps.choice[%this]++;
%rps.current = %this;
%rps.main();
return %this;
}
 
function thisVSthat(%this,%that)
{
if(%this !$= "rock" && %this !$= "paper" && %this !$= "scissors")
{
return 0;
}
else
if(%that !$= "rock" && %that !$= "paper" && %that !$= "scissors")
{
return 0;
}
%weakness["rock"] = "paper";
%weakness["paper"] = "Scissors";
%weakness["scissors"] = "rock";
if(%weakness[%this] $= %that)
{
%result = 2;
}
else
if(%weakness[%that] $= %this)
{
%result = 1;
}
else
%result = 0;
return %result;
}
</lang>
 
To begin do:
 
<lang TorqueScript>
RockPaperScissors.startGame();
</lang>
 
Choose and play!
 
<lang TorqueScript>
choose("Rock");
</lang>
 
=> You chose rock computer chose paper, you lose!
 
=={{header|TI-83 BASIC}}==
Anonymous user