Computer Science Canada

Rock Papers scissors

Author:  unknownturing123 [ Thu Jan 15, 2015 9:15 pm ]
Post subject:  Rock Papers scissors

I'm currently making a basic rock paper scissors game and so far I'm having trouble with the score counter that keeps track of your score. Specifically, it always keeps track of your score(good part) the bad part is it also adds the computer's score to yours. There are some other errors with my game I'm having difficulty figuring out.


%Screen Size & Background
setscreen ("graphics:max;max") %Screen Size
setscreen ("nocursor") %no cursor
colourback (3) %Colour Background
cls

%variables
var font : int
var key : string (1)
var countw : int := 0
var p : string (1) %Controls
var b : string (1)
var c : string (1)
var r, a : int
%Pictures used
var mypic1 : int := Pic.FileNew ("rock.jpg")
var mypic2 : int := Pic.FileNew ("scissor.jpg")
var mypic3 : int := Pic.FileNew ("paper.jpg")




%font
font := Font.New ("Copperplate Gothic Bold:20")

%Visuals
loop
%Title(first screen)
Font.Draw ("The Rock Paper Scissors Game. Press Any Key to continue.", 200, 600, font, black)
getch (key)
cls
loop
%Instructions
Font.Draw ("Instructions. Press any key to continue.", 200, 600, font, black)
Font.Draw ("1.Rock smashes scissors", 200, 500, font, black)
Font.Draw ("2.Scissors cut paper", 200, 450, font, black)
Font.Draw ("3.Paper covers rock", 200, 400, font, black)
getch (key)
cls
loop
%Words: Win and Lose and Options

Font.Draw ("Wins(You):", 0, 700, font, black)
Font.Draw ("Loses(You):", 0, 650, font, black)
Font.Draw ("You:", 100, 600, font, black)
Font.Draw ("Computer", 1140, 550, font, black)
drawfillbox (0, 220, 230, 200, white) %White Box over the word "Paper"
drawfillbox (0, 150, 265, 170, 8) %Grey Box over the word "Scissor"
drawfillbox (0, 250, 205, 270, yellow) %Yellow Box over the word "Rock"
Font.Draw ("Rock(Press1)", 0, 250, font, black)
Font.Draw ("Paper(Press2)", 0, 200, font, black)
Font.Draw ("Scissors(Press3)", 0, 150, font, black)



loop %Controls

%Player output
getch (p)

if p = "2" then
Font.Draw ("Paper", 100, 420, font, blue) %Pictures to be shown on screen
Pic.Draw (mypic3, 100, 450, 0)

elsif p = "1" then
Pic.Draw (mypic1, 100, 450, 0)
Font.Draw ("Rock", 100, 420, font, blue)

elsif p = "3" then
Font.Draw ("Scissors", 100, 420, font, blue)
Pic.Draw (mypic2, 100, 450, 0)
else
Font.Draw ("INVALID ENTRY", 550, 420, font, red) %INVALID ENTRY MESSAGE

end if
randint (r, 1, 3) %computer picks from one of the three pictures to be displayed on screen

if r = 2 then
Font.Draw ("Paper", 1150, 420, font, blue) %Pictures to be shown on screen
Pic.Draw (mypic3, 1150, 450, 0)
elsif r = 1 then
Pic.Draw (mypic1, 1150, 450, 0)
Font.Draw ("Rock", 1150, 420, font, blue)
elsif r = 3 then
Font.Draw ("Scissors", 1150, 420, font, blue)
Pic.Draw (mypic2, 1150, 450, 0)
end if
delay (1200)
drawfillbox (0, 550, 10000, 300, 3) %box that covers the previous pictures

if p = "1" then
a := 1
elsif p = "2" then
a := 2
elsif p = "3" then
a := 3


% Points scoring
if a = 2 and r = 1 then
countw := countw + 1
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 900, 900, 900, 3)
elsif a = 1 and r = 2 then
countw := countw + 1
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 1 and r = 3 then
countw := countw + 1
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 3 and r = 1 then
countw := countw + 1
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 2 and r = 3 then
countw := countw + 1
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 3 and r = 2 then
countw := countw + 1
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 3 and r = 3 then
Font.Draw ("TIE!", 500, 600, font, yellow)
countw := countw + 0
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 2 and r = 2 then
Font.Draw ("TIE!", 500, 600, font, yellow)
countw := countw + 0
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 900, 600, 3)
elsif a = 1 and r = 1 then
Font.Draw ("TIE!", 500, 600, font, yellow)
countw := countw + 0
Font.Draw (intstr (countw), 200, 700, font, black)
delay (1200)
drawfillbox (200, 800, 700, 600, 3)
end if
end if
end loop %Loops end
end loop
end loop
end loop
getch (key)



%End Game

Author:  Insectoid [ Thu Jan 15, 2015 9:22 pm ]
Post subject:  RE:Rock Papers scissors

Well, I'd say the reason that the CPU scores are being added to the player scores is that you're adding the CPU score to the player score. What is countw? It looks like whenever anyone wins you add one to it. You're gonna need an extra variable in there somewhere.


: