Dont be discourage by how long this message is. I explain my problem very clearly (Personally its kind of annoying to help someone when they give very little detail, but sorry in advance if this is to much info.)
I am currently working on a game called
Enigma
Quote:
You start with 5 dice, which are rolled repeatedly. Each roll, the player arranges the dice in to 2 pairs a single. The pairs are added to the lower table and the single is added to the upper table. Only 3 different numbers can be selected for the upper (single) table. Every roll you must place 1 dice in the upper (single) table. (if no dice is any of those numbers you 'throw away' any dice you want) The game ends when you place the 8th of a number into the single table. For the doubles: if you have used a number (8 for example) 0 times, you get no points, if you have used if 1 to 4 times you get -20 points, and past that you get more points based on rarity of that num (7 is worth little, 2 and 12 are most) So you want to use as few numbers as possible and as often as possible.
Hope that makes sense...
Anyways, in beta programming I am at the following status:
I launch the program, click Roll Dice, and then WOULD drag and drop the dice to pair them, but cant get that to work at all...So as a workaround i placed buttons next to all the rows in the tables to add to the rows. (to test the scoring code)
Heres the problem:
When i pick up the picture it pickes up everything next to it for the drag, AND loses its Background transparency for the drag. But when i set the dice down it behaves normally, at least until i pick it up again. And on top of that it doesnt go where the mouse is, but instead it goes down below it. ARGH!!
I cant make heads or tails for why any of this would happen...
What i will eventually do is make some code that will test to see if you dropped a dice onto another one and pair them by setting them next to each other.
What i might end up doing is having a different pic (an outline of the dice) that is used for dragging purposes.
Anyways, my main problems are:
1-Why does the background transparency die when i drag? (Bug in AHK or my code?)
2-why does the drag pick up other stuff? (Bug in AHK or my code?)
3-Why does the drag not stay on the mouse? (bug in my code for sure)
Heres a Zip with the script and pics:
sigma.zip
Heres the code:
(its very ugly, being in beta, way to many unclear varaibles...)
Code:
;===========================
;------Initialization-------
;===========================
#singleinstance force
;-= create menus
Menu, FileMenu, add, &New`tCtrl-N, MenuFileNew
Menu, FileMenu, add, &Quit`tAlt-F4, MenuFileQuit
Menu, HelpMenu, add, &Rules`tCtrl-H, MenuHelpRules
Menu, HelpMenu, add, &About, MenuHelpAbout
Menu, MenuBar, add, &File, :FileMenu
Menu, MenuBar, add, &Help, :HelpMenu
Gui, Menu, MenuBar
;-=draw single buttons
gui, margin, 10,5
gui, add, button, section x10 y10 gAddSingle vSingle1, ?
gui, add, button, gAddSingle vSingle2, ?
gui, add, button, gAddSingle Vsingle3, ?
;-=draw single bars
gui, margin, 3,13
gui, add, pic, ys+6 ,singleback.png
gui, add, pic, yp xp w0 h15 vsingle1bar,blue.bmp
gui, add, pic, w0 h15 vsingle2bar,blue.bmp
gui, add, pic, w0 h15 vsingle3bar,blue.bmp
;-=draw 5 dice
gui, margin, 25, 20
gui, add, pic, xm vDice1Pic BackgroundTrans gDiceClick section, dice1.png
gui, add, pic, ys vDice2Pic BackgroundTrans gDiceClick, dice2.png
gui, add, pic, ys vDice3Pic BackgroundTrans gDiceClick, dice3.png
gui, add, pic, ys vDice4Pic BackgroundTrans gDiceClick, dice4.png
gui, add, pic, ys vDice5Pic BackgroundTrans gDiceClick, dice5.png
;-=draw double buttons
gui, margin, 0,0
gui, add, button, x10 yp+100 section gAddDouble, 2
gui, add, button, gAddDouble, 3
gui, add, button, gAddDouble, 4
gui, add, button, gAddDouble, 5
gui, add, button, gAddDouble, 6
gui, add, button, gAddDouble, 7
gui, add, button, gAddDouble, 8
gui, add, button, gAddDouble, 9
gui, add, button, gAddDouble, 10
gui, add, button, gAddDouble, 11
gui, add, button, gAddDouble, 12
;-=draw double bars
gui, margin, 10,13
gui, add, pic, ys+6 section BackgroundTrans,back.png
gui, add, pic, ys xs w450 h10 vbar2,red.bmp
gui, add, pic, w0 h10 vbar3,red.bmp
gui, add, pic, w0 h10 vbar4,red.bmp
gui, add, pic, w0 h10 vbar5,red.bmp
gui, add, pic, w0 h10 vbar6,red.bmp
gui, add, pic, w0 h10 vbar7,red.bmp
gui, add, pic, w0 h10 vbar8,red.bmp
gui, add, pic, w0 h10 vbar9,red.bmp
gui, add, pic, w0 h10 vbar10,red.bmp
gui, add, pic, w0 h10 vbar11,red.bmp
gui, add, pic, w0 h10 vbar12,red.bmp
;-=draw score, reset button, roll button,
gui, font, s20
gui, add, text, vScore xs+435 ys+105, -999
guicontrol, ,Score,0
gui, add, button, x365 y20 w180 h60 gRollDice vButtonRollDice, Roll Dice
gui, font, s12
;-=set initial states of double bars to -5
loop, 11
{
loopindex := A_index+1
double%loopindex%val = -5
guicontrol,move,bar%loopindex%, w0
}
guicontrolget, doublebar,pos,bar2
loop, 5
{
guicontrolget, currentpos, pos, Dice%A_index%Pic
Dice%A_index%StandardX = %currentposX%
Dice%A_index%StandardY = %currentposY%
}
gui, show
Gosub, RollDice
return
;=============================
;-------Games Controls--------
;=============================
MenuFileNew:
loop, 11
{
loopindex := A_index+1
double%loopindex%val = -5
RedrawDoubleBar(loopindex)
}
loop, 3
{
single%A_index%val = 0
temp = single%A_index%
RedrawSingleBar(temp)
}
guicontrol, ,score,% TotalScores()
return
RollDice:
Gosub, ResetDice
loop, 5
{
random, random, 1, 6
dice%A_index%val := random
guicontrol, , dice%A_index%,dice%random%.png
}
;guicontrol, disable, ButtonRollDice
return
ResetDice:
loop, 5
{
currentx := dice%A_index%standardx
currenty := dice%A_index%standardy
guicontrol, move, dice%A_index%pic, x%currentx% y%currenty%
}
return
DiceClick:
stringmid, dicenum, A_guicontrol, 5,1
diceval := % dice%dicenum%val
loop
{
;if mod(A_index, 5) = 0
; guicontrol, ,%A_guicontrol%, dice%diceval%.png
GetKeyState, mouseisdown, LButton
if mouseisdown = u
break
mousegetpos, mousex, mousey
guicontrol, move, %A_guicontrol%, x%mousex% y%mousey% BackgroundTrans
sleep 100
}
guicontrol, ,%A_guicontrol%, dice%diceval%.png
guicontrol, move, %A_guicontrol%, x%mousex% y%mousey% BackgroundTrans
return
TotalScores()
{
total = 0
loop, 12
{
if A_index = 1
continue
x := double%A_index%val
if (x = -5) or (x = 0)
continue
else if x > 0
if (A_index = 2) or (A_index = 12)
Total += x*10
else
total += x*(abs(7-A_index)+3)
else
total -= 20
}
return %total%
}
;=============================
;-----Control Single Bars-----
;=============================
AddSingle:
%A_guicontrol%val += 1
RedrawSingleBar(A_guicontrol)
return
SubtractSingle:
return
RedrawSingleBar(bar)
{
newbarW := %bar%val * 40
guicontrol, move, %bar%bar, w%newbarW%
if %bar%val = 8
guicontrol, ,%bar%bar, red.bmp
else
guicontrol,,%bar%bar, blue.bmp
}
;=============================
;-----Control Double Bars-----
;=============================
AddDouble:
double%a_guicontrol%val += 1
RedrawDoubleBar(A_guicontrol)
guicontrol, ,score,% TotalScores()
return
SubtractDouble:
return
RedrawDoubleBar(bar)
{
global doublebarx
if double%bar%val < 0
{
newbarX := doublebarX
newbarW := 100 -(double%bar%val * -20)
guicontrol, ,bar%bar%,red.bmp
}else if double%bar%val = 0
{
newbarX := doublebarX+80
newbarW = 20
guicontrol, ,bar%bar%,blue.bmp
}else if (double%bar%val > 0) and (double%bar%val < 10)
{
newbarX := doublebarX +100
newbarW := double%bar%val*(abs(7-bar)+3)*4
if (bar = 2) or (bar = 12)
newbarW := double%bar%val*10*4
}else if double%bar%val >= 10
{
double%bar%val = 10
newbarX := doublebarX +100
newbarW := double%bar%val*(abs(7-bar)+3)*4
if (bar = 2) or (bar = 12)
newbarW := double%bar%val*10*4
}
guicontrolget, currentbar,pos,bar%bar%
if currentbarW <> newbarW
guicontrol, move, bar%bar%, w%newbarW% x%newbarX%
}
;=============================
;-------Other Functions-------
;=============================
MenuFileQuit:
GuiClose:
ExitApp
MenuHelpRules:
msgbox, <welcome to beta, this will be made later>
return
MenuHelpAbout:
msgbox, <welcome to beta, this will be made later>
/*
;=============================
;----------TO DO List---------
;=============================
dice:
- drag and drop pairs
- drag drop single dice
- code to unpair dice
- code to add and SUBTRACT to tables when you pair (or unpair) the dice
rules:
- make game end when you hit the 8th single
add RULES and HELP sections
preferences?
High scores:
80 - Geneuis
50 - excellent
30 - good
0 - beginner
-25 - try again
-50 - noob!