Jump to content

Working with images


Recommended Posts

Hi, I am trying to make a game of Reversi.

I am getting pretty far, But I've run into a problem and I can't seem to fix it...

here is my code:

CODE
#include <GUIConstants.au3>
HotKeySet ("{F3}", "myfunc1")

Global $squares[65]
For $i = 1 To 64
    $squares[$i] = ""
Next
Global $MarblePics[65]
$gui = GUICreate ("AutoIt Reversi", 490, 695)
$board = GUICtrlCreatePic ("board.bmp", 5, 5, 480, 480)
PlaceMarble ("white", 3, 3)
PlaceMarble ("black", 3, 4)
PlaceMarble ("black", 4, 3)
PlaceMarble ("white", 4, 4)
GUISetState ()

While 1
    $msg = GUIGetMsg ()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func coord($num)
    If $num < 1 Or $num > 8 Then
        SetError (1)
        Return 0
    EndIf
    Return ($num*60)+5
EndFunc

Func PlaceMarble ($color, $x, $y)
    Local $square = (8*$y)+$x
    If $square < 1 Or $square > 64 Then Return 0
    If $squares[$square] <> "" Then
        GUICtrlDelete ($MarblePics[$square])
        $squares[$square] = ""
    EndIf
    $MarblePics[$square] = GUICtrlCreatePic ($color&".bmp", coord($x), coord($y), 59, 59)
    $squares[$square] = $color
    Return 1
EndFunc

Func ReverseMarble ($x, $y)
    Local $square = (8*$y)+$x
    If $squares[$square] = "" Then Return 0
    Switch $squares[$square]
        Case "white"
            PlaceMarble ("black", $x, $y)
        Case "black"
            PlaceMarble ("white", $x, $y)
    EndSwitch
EndFunc

Func myfunc1 ()
    PlaceMarble ("black", 3, 3)
EndFunc

Ok, so, it creates the board and the first four marbles fine.

Here is where the problem comes in. When I press F3, it should set the marble at 3, 3 to black.

Well, PlaceMarble first checks to see if there is an existing marble in place, and if there is, deletes it. Then it creates the new marble.

PlaceMarble obviously works fine if the square is empty at first, as I created the first 4 marbles.

But, When I press F3, it should delete the white marble already there, and create the black marble. Well, it deletes it just fine, But it doesn't recreate the black marble, so square 3, 3 just becomes empty.

I have looked at the code for a long time, but I just can't figure out why it's doing that...

The images can be found at http://www.theguy0000.com/reversi

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

#include <GUIConstants.au3>
HotKeySet ("{F3}", "myfunc1")

Global $squares[65]
For $i = 1 To 64
    $squares[$i] = ""
Next
Global $MarblePics[65]
$gui = GUICreate ("AutoIt Reversi", 490, 595)
$board = GUICtrlCreatePic ("C:\Temp\board.bmp", 5, 5, 480, 480)
GUICtrlSetState( $board, $GUI_DISABLE)
PlaceMarble ("C:\Temp\white", 3, 3)
PlaceMarble ("C:\Temp\black", 3, 4)
PlaceMarble ("C:\Temp\black", 4, 3)
PlaceMarble ("C:\Temp\white", 4, 4)
GUISetState ()

While 1
    $msg = GUIGetMsg ()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func coord($num)
    If $num < 1 Or $num > 8 Then
        SetError (1)
        Return 0
    EndIf
    Return ($num*60)+5
EndFunc

Func PlaceMarble ($color, $x, $y)
    Local $square = (8*$y)+$x
    If $square < 1 Or $square > 64 Then Return 0
    If $squares[$square] <> "" Then
        GUICtrlDelete ($MarblePics[$square])
        $squares[$square] = ""
    EndIf
    $MarblePics[$square] = GUICtrlCreatePic ($color&".bmp", coord($x), coord($y), 59, 59)
    GUICtrlSetState ( -1, $GUI_SHOW)
    $squares[$square] = $color
    Return 1
EndFunc

Func ReverseMarble ($x, $y)
    Local $square = (8*$y)+$x
    If $squares[$square] = "" Then Return 0
    Switch $squares[$square]
        Case "white"
            PlaceMarble ("black", $x, $y)
        Case "black"
            PlaceMarble ("white", $x, $y)
    EndSwitch
EndFunc

Func myfunc1 ()
    $ret = PlaceMarble ("C:\Temp\black", 3, 3)
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

CODE
#include <GUIConstants.au3>
HotKeySet ("{F3}", "myfunc1")

Global $squares[65]
For $i = 1 To 64
    $squares[$i] = ""
Next
Global $MarblePics[65]
$gui = GUICreate ("AutoIt Reversi", 490, 595)
$board = GUICtrlCreatePic ("C:\Temp\board.bmp", 5, 5, 480, 480)
GUICtrlSetState( $board, $GUI_DISABLE)
PlaceMarble ("C:\Temp\white", 3, 3)
PlaceMarble ("C:\Temp\black", 3, 4)
PlaceMarble ("C:\Temp\black", 4, 3)
PlaceMarble ("C:\Temp\white", 4, 4)
GUISetState ()

While 1
    $msg = GUIGetMsg ()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func coord($num)
    If $num < 1 Or $num > 8 Then
        SetError (1)
        Return 0
    EndIf
    Return ($num*60)+5
EndFunc

Func PlaceMarble ($color, $x, $y)
    Local $square = (8*$y)+$x
    If $square < 1 Or $square > 64 Then Return 0
    If $squares[$square] <> "" Then
        GUICtrlDelete ($MarblePics[$square])
        $squares[$square] = ""
    EndIf
    $MarblePics[$square] = GUICtrlCreatePic ($color&".bmp", coord($x), coord($y), 59, 59)
    GUICtrlSetState ( -1, $GUI_SHOW)
    $squares[$square] = $color
    Return 1
EndFunc

Func ReverseMarble ($x, $y)
    Local $square = (8*$y)+$x
    If $squares[$square] = "" Then Return 0
    Switch $squares[$square]
        Case "white"
            PlaceMarble ("black", $x, $y)
        Case "black"
            PlaceMarble ("white", $x, $y)
    EndSwitch
EndFunc

Func myfunc1 ()
    $ret = PlaceMarble ("C:\Temp\black", 3, 3)
EndFunc
8)
awsome! thanks! ;)

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...