Oxygene for Java version of RockPaperScissors
Pascal version by Hasaan Ausat: Y12 Age ~16
We supply below the Oxygene for Java code (in rps.pas) adapted from the original Pascal, a slimmed-down xml project file (rps.oxygene) to be used by the Oxygene compiler following the command line instruction Oxygene rps.oxygene. Afterwards, run the program with java -jar rps.jar. Alternatively, open the project file in Visual Studio and click on the green arrow.
We copied the file to a memory stick, plugged the memory stick into the Pi (with automatic USB mounting enabled), and typed commands as shown in this screenshot.
Rock Paper Scissors on the PiThis conversion shows how to use System.out.println instead of writeln and System.in.read instead of read in Oxygene for Java console applications. It also demonstrates the use of Maths.random.
Oxygene for Java code of rps.pas
namespace RockPaperScissors; { Copyright (c) 2010 Hasaan Ausat Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License, as described at http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/ Converted to Oxygene for Java by PPS. } interface type ConsoleApp = class public class method Main(args : array of String); end; implementation class method ConsoleApp.Main(args : array of String); var playcount, playercount, compcount, tiecount, number, answer : Integer; input_chars : array[0 .. 255] of byte; begin System.out.println('|-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*|'); System.out.println('| |'); System.out.println('| WELCOME TO ROCK PAPER SCISSORS |'); System.out.println('| |'); System.out.println('|*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-|'); System.out.println; playcount := 0; compcount := 0; playercount := 0; tiecount := 0; repeat System.out.println('Rock is 0, Paper is 1, Scissors is 2'); System.out.println; System.in.read(input_chars); number := input_chars[0] - 48; // Zero is ASCII 48 if number > 2 then begin repeat System.out.println('Rock is 0, Paper is 1, Scissors is 2'); System.in.read(input_chars); number := input_chars[0] - 48; until number < 3; end; answer := Integer(Math.random() * 3); //answer will be 0, 1, or 2 System.out.println; System.out.println('I have picked ' + answer.ToString); System.out.println; if (answer = 0) and (number = 0) then begin System.out.println('|-------|'); System.out.println('| Tie!! |'); System.out.println('|-------|'); System.out.println; playcount := playcount + 1; tiecount := tiecount + 1; end; if (answer = 0) and (number = 1) then begin System.out.println('|------------|'); System.out.println('| You win :) |'); System.out.println('|------------|'); System.out.println; playcount := playcount + 1; playercount := playercount + 1; end; if (answer = 1) and (number = 0) then begin System.out.println('|--------------|'); System.out.println('| You lose :( |'); System.out.println('|--------------|'); System.out.println; playcount := playcount + 1; compcount := compcount + 1; end; if (answer = 1) and (number = 1) then begin System.out.println('|-------|'); System.out.println('| Tie!! |'); System.out.println('|-------|'); System.out.println; playcount := playcount + 1; tiecount := tiecount + 1; end; if (answer = 1) and (number = 2) then begin System.out.println('|------------|'); System.out.println('| You win :) |'); System.out.println('|------------|'); System.out.println; playercount := playercount + 1; playcount := playcount + 1; end; if (answer = 2) and (number = 1) then begin System.out.println('|--------------|'); System.out.println('| You lose :( |'); System.out.println('|--------------|'); System.out.println; playcount := playcount + 1; compcount := compcount + 1; end; if (answer = 2) and (number = 2) then begin System.out.println('|-------|'); System.out.println('| Tie!! |'); System.out.println('|-------|'); System.out.println(); playcount := playcount + 1; tiecount := tiecount + 1; end; if (answer = 2) and (number = 0) then begin System.out.println('|------------|'); System.out.println('| You win :) |'); System.out.println('|------------|'); System.out.println; playercount := playercount + 1; playcount := playcount + 1; end; if (answer = 0) and (number = 2) then begin System.out.println('|--------------|'); System.out.println('| You lose :( |'); System.out.println('|--------------|'); System.out.println; playcount := playcount + 1; compcount := compcount + 1; end; System.out.println('Would you like to play again? y/n'); System.out.println; System.in.read(input_chars); until input_chars[0] = 110; //ASCII n = 110 System.out.println('You have played ' + playcount.toString + ' times'); System.out.println; System.out.println('You won ' + playercount.toString + ' times'); System.out.println; System.out.println('You lost ' + compcount.toString + ' times'); System.out.println; System.out.println('We drew ' + tiecount.toString + ' times'); System.out.println; System.in.read; if compcount < playercount then begin System.out.println(' _'); System.out.println(' ( (('); System.out.println(' \ =\'); System.out.println(' __\_ `-\'); System.out.println('(____))( \----'); System.out.println('(____)) _'); System.out.println('(____))'); System.out.println('(____))____/----'); System.out.println; end; if compcount > playercount then begin System.out.println(' _____'); System.out.println('((____ \----'); System.out.println('((____'); System.out.println('((____'); System.out.println('((____ ----'); System.out.println(' / /'); System.out.println(' (_(('); System.out.println; end; if compcount = playercount then begin System.out.println(' _'); System.out.println(' ( (('); System.out.println(' \ =\'); System.out.println(' __\_ `-\'); System.out.println('(____))( \----'); System.out.println('(____)) _'); System.out.println('(____))'); System.out.println('(____))____/----'); System.out.println(' _____'); System.out.println('((____ \----'); System.out.println('((____'); System.out.println('((____'); System.out.println('((____ ----'); System.out.println(' / /'); System.out.println(' / =/'); System.out.println(' (_(('); System.out.println(); end; System.out.println('Goodbye, Hope you had fun!!!!!!!!!'); System.out.println; System.in.read; System.out.println('RockPaperScissors (c) 2009 - Huskimo'); System.in.read; end; end.
Project file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Reference Include="rt.jar" />
</ItemGroup>
<ItemGroup>
<Compile Include="rps.pas" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Oxygene\RemObjects.Oxygene.Java.targets" />
</Project>



dita powered.