Jython Slot machine: making the game loop - jython

I am writing a slot machine game for my intro to programming class. I can make the game procure 5 random images from a file containing 6, arrange them on a blank canvas and compare the pictures to see if there are 3-in-a-row. It will tell you if you win or not and ask you to play again. I need to loop the game so that it runs again after the user selects "y/n". here is my code so far.
from random import *
def main():
pictureList = setMediaPath("F:\Class Stuff\INF 120\Project X\gamepics")
s = 1 # requestInteger("Slot machine image numbering begins at:")
e = 6 # requestInteger("Slot maching image numbering ends at:")
ext = "jpg" #requestString("Enter the extension ofthe slot machine image files (without a dot):")
mypic = []
for num in range(s, e+1):
mypic = mypic + [(makePicture("smImage" + str(num) + "." + ext))]
#set up the "game board" in a blank window
w = getWidth(mypic[0])
h = getHeight(mypic[0])
ePic = makeEmptyPicture(w*5, h)
show(ePic)
# start the actual game
win = False
inRow = 1
last = -1
#loop through all five slots and set pic for each one a new, random picture. Form list of pictures.
#make a loop to run through the game until win = true.
for i in range(0,5):
imgIndex = randrange(0,len(mypic))
copyInto(mypic[imgIndex], ePic, i*w, 0)
repaint(ePic)
if imgIndex == last:
inRow = inRow + 1
else:
inRow = 1
last = imgIndex
if inRow >= 3:
win = true
if win == true:
showInformation("YOU WIN!!")
rePlay = requestString("Would you like to play again? (y/n)")
else:
showInformation("You Lose...")
requestString("Play again? (y/n)")
the media path is set to the directory on my machine with the images. here is a link to my google drive with the images. https://drive.google.com/folderview?id=0B_ZDD1CZGQYlYjFQWEpjR0NzMGs&usp=sharing .If you are going to run this, you need to change the media path in my code to correspond with where you have the pictures.
I appreciate any and all help with this. Thanks!

I dont know any jython but the pseudo code should be
var continue = true
while(continue) {
[[play game, set continue based on user input]]
}

Related

Make a fun minigame on roblox

So I made a script on ROBLOX so whenever you touch the part it puts you name in chat as first place. I want it to teleport that 1st player to the lobby and say 2nd or 3rd depending on who else touched the part at what times. here's what I got so far:
local mytab = {'player1', 'player2', 'player3'}
local RESET_TIME = 1
local part = game.Workspace.Part
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
if not part:GetAttribute("Touched") then
part:SetAttribute("Touched", true)
task.wait(RESET_TIME)
part:SetAttribute("Touched", false)
for i, v in ipairs(mytab) do
local function chat(message)
game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = message, colour = Color3.fromRGB(255, 255, 255), Font = Enum.Font.Arial})
end
chat("The " ..i.. 'st Winner is ' ..v.Name)
end
end
end
end)
its a work in progress
I tried to make the first second and third players to replace the strings on the table but it did not work.

Make the grid of chart control to begin at an even hour

I am using a chart control which in x axis displays time, initialized as follows:
With Chart1.ChartAreas(0)
.AxisX.Minimum = 0
.AxisX.LabelStyle.Format = "HH:mm"
.AxisX.IntervalType = DateTimeIntervalType.Hours
.AxisX.Interval = 2
.AxisY.Minimum = 0
End With
Chart1.Series(0).IsXValueIndexed = True
Sometimes the data points start at an odd hour like the picture bellow
My question is how can I make the grid and labels begin at an even hour instead.
Thanks in advance.
OK I got it. I just removed the commands
.AxisX.Minimum = 0 in With...End With statement and
Chart1.Series(0).IsXValueIndexed = True
and now the grid always begins at an even hour automatically.

How to plot a polyline between multiple points with vba

I am trying to plot a polyline between multiple points in vba into autocad. I have almost finished my code, but the thing is that the points may repeat themselves, as 2 lines can have the same starting point, and the points are nor in a sorted way.
I need to be able to addd all points even if they aren't sorted, cause I have to keep the order of the points I am tryint to plot.
I am getting this error:
Invalid Procedure or argument call
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(Points)
This is my code:
Points(1)=9736.242889: Points(2)=9954.553808
Points(3)=9718.429708: Points(4)=9936.874562
If acadDoc.ActiveSpace = acModelSpace Then
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(Points)
Else
Set acadPol = acadDoc.PaperSpace.AddLightWeightPolyline(Points)
End If
acadPol.Closed = False
acadPol.Update
End If
End If
Your code is incomplete but I notice you have started your coordinates list at index 1.
There are plenty of examples on the internet
Sub Example_AddLightWeightPolyline()
' This example creates a lightweight polyline in model space.
Dim plineObj As AcadLWPolyline
Dim points(0 To 9) As Double
' Define the 2D polyline points
points(0) = 1: points(1) = 1
points(2) = 1: points(3) = 2
points(4) = 2: points(5) = 2
points(6) = 3: points(7) = 2
points(8) = 4: points(9) = 4
' Create a lightweight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
ZoomAll
End Sub
As you can see, you need to start your coordinates array at index 0 and not 1.
Does this help?

Algorithm for finding end of a list (SAP GUI)

I'm writing a script that adds elements to a list in a SAP GUI screen. Now, it seems that when using SAP GUI, nothing "exists" unless it is actually on screen, so the first step involves finding the end of the list.
I accomplished this by scrolling though each element, and checking if it was blank.
Do While Not blank
If session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = "" Then blank = True
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = i
i = i + 1
Loop
However, for very large existing lists, this takes a long time. I'm trying to figure out a way to find the end more quickly. Some truths/limitations I know:
I'm assuming I have no knowledge of the list length.
I cannot command the verticalScrollbar.position too far beyond the end of
the list. For ex. if the list contains 62 elements, .verticalScrollbar.Position = 100 will not work.
In the case of the above example, SAP does NOT throw an error. Nothing happens at all, and then next line of code executes.
All references to elements are with respect to their position on the screen. Ex, if I scroll down 5 positions, the 6th element of the overall list would actually indexed as 1.
On the other hand, verticalScrollbar.Position is absolute
I'm thinking of doing the following (in very psuedocode):
i = 0
do while scrolled = true
scrolled = false
a = GUIlist[0]
verticalScrollbar.Position = i + 1000
b = GUIlist[0]
'check to see the first element shown has changed
if a <> b then
scrolled = true
i = i + 1000
end if
loop
do while scrolled = true
scrolled = false
a = GUIlist[0]
verticalScrollbar.Position = i + 500
b = GUIlist[0]
if a <> b then
scrolled = true
i = i + 500
end if
loop
...and so on until I'm iterating i by one.
Is there a generally accepted better way of doing this kind of 'search'?
Any input is appreciated.
Thanks
My suggestion:
session.findById("wnd[0]").sendVKey 83
myPosition = session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position
do
if session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010/ctxtMAPL-MATNR[2,0]").Text = "" then exit do
myPosition = myPosition + 1
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = myPosition
loop
msgbox myPosition
Regards,
ScriptMan
Just to go to the end
max_scrollbar = session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Maximum ' Get the maximum scrollbar value
session.findById("wnd[1]/usr/tblSAPLCZDITCTRL_4010").verticalScrollbar.Position = max_scrollbar ' Go to the end

access swf text field through visual basic

we have an .swf flash animation embedded into a visual basic application.
I am trying to read the contents of a text field in the animation called 'bob' using the following code;
TextBox1.Text = AxShockwaveFlash1.GetVariable("bob")
When executed the output in textbox1 is "_level0.bob" ???
This is different to the actual text in the animation, and idea how I can access it?
Have tried bob.text etc.
Thanks
Phil
Right found a solution that works with as3 and VB cobbled from a few other solutions, you need to use external interface in action script here is the code in AS3 and VB. Sends two strings hours and mins across.
AS3
function TimeUpdate(o:Object)
{
var r:String = "";
for (var v in o)
//Move the values from visual basic to mins and hours
if (v = "mins") mins = o[v];
if (v = "hours") hours = o[v];
time.text = hours + ":" + mins;
return "TimeUpdate was called";
}
if (ExternalInterface.available)
ExternalInterface.addCallback('TimeUpdate', TimeUpdate);
Visual Basic
Dim x As String
x = "<invoke name=""TimeUpdate"" returntype=""xml"">"
x = x & "<arguments>"
x = x & "<object>"
x = x & "<property id='hours'><string>2</string></property>"
x = x & "<property id='mins'><string>33</string></property>"
x = x & "</object>"
x = x & "</arguments>"
x = x & "</invoke>"
Dim responce As String
responce = AxShockwaveFlash1.CallFunction(x)
MsgBox(responce )
hope this is of use to people.
Phil
I think the problem you have is twofold. First, you need to be able to know somehow that the swf is ready. I tried to get this to work in a VBA app once (Access), and I never could reliably get this to work.
The second thing you need to realize is that the TextField is of type TextField, not String.