Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 monopoly help >.>
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JustTrying2GetBy




PostPosted: Tue Jan 25, 2005 12:55 pm   Post subject: monopoly help >.>

i have gotten player one to make the first move successfully. now i am wondering how I would get player two to make his move....

code:

setscreen ( "graphics:940;1100" )

var num1, num2 : int
var Players : int
var x, y, button, button2 : int
var b, counter, counter2 : int := 0
var player1x : int := 710
var player1y : int := 290
var player2x : int := 720
var player2y : int := 290


%Player1

drawfilloval (710, 290, 5, 5, 6)

%Player2

drawfilloval (720, 290, 5, 5, 3)

procedure board

    % Monopoly Board

    drawbox (10, 270, 820, 1080, 2)
    drawbox (698, 391, 132, 959, 2)

    %GO
    drawbox (698, 270, 820, 391, 2)
    %Square1
    drawbox (635, 270, 698, 391, 2)
    %Square2
    drawbox (572, 270, 635, 391, 2)
    %Square3
    drawbox (509, 270, 572, 391, 2)
    %Square4
    drawbox (446, 270, 509, 391, 2)
    %Square5
    drawbox (383, 270, 446, 391, 2)
    %Square6
    drawbox (320, 270, 383, 391, 2)
    %Square7
    drawbox (257, 270, 383, 391, 2)
    %Square8
    drawbox (194, 270, 383, 391, 2)
    %Square9
    drawbox (131, 270, 383, 391, 2)
    %Jail
    drawbox (10, 270, 132, 391, 2)
    %Square10
    drawbox (10, 391, 132, 454, 2)
    %Square11
    drawbox (10, 454, 132, 517, 2)
    %Square12
    drawbox (10, 517, 132, 580, 2)
    %Square13
    drawbox (10, 580, 132, 643, 2)
    %square14
    drawbox (10, 643, 132, 706, 2)
    %Square15
    drawbox (10, 706, 132, 769, 2)
    %Square16
    drawbox (10, 769, 132, 832, 2)
    %Square17
    drawbox (10, 832, 132, 895, 2)
    %Square18
    drawbox (10, 895, 132, 958, 2)
    %Free Parking
    drawbox (10, 1080, 132, 959, 2)
    %square19
    drawbox (132, 1080, 195, 959, 2)
    %Square22
    drawbox (195, 1080, 258, 959, 2)
    %Square23
    drawbox (258, 1080, 321, 959, 2)
    %Square24
    drawbox (321, 1080, 384, 959, 2)
    %Square25
    drawbox (384, 1080, 447, 959, 2)
    %Square26
    drawbox (447, 1080, 510, 959, 2)
    %Square27
    drawbox (510, 1080, 573, 959, 2)
    %Square28
    drawbox (573, 1080, 636, 959, 2)
    %Go to jail
    drawbox (698, 1080, 820, 959, 2)
    %square 29
    drawbox (698, 896, 820, 959, 2)
    %Square 30
    drawbox (698, 896, 820, 833, 2)
    %Square 31
    drawbox (698, 833, 820, 770, 2)
    %Square 32
    drawbox (698, 770, 820, 707, 2)
    %Square 33
    drawbox (698, 707, 820, 644, 2)
    %Square 34
    drawbox (698, 644, 820, 581, 2)
    %Square 35
    drawbox (698, 581, 820, 518, 2)
    %Square 36
    drawbox (698, 518, 820, 455, 2)
    %Square 37
    drawbox (698, 455, 820, 392, 2)
end board

%Dice
drawbox (850, 1030, 900, 1080, 7)
drawbox (850, 950, 900, 1000, 7)

function die1 : int
    loop
        var num1 : int := 0
        Mouse.Where (x, y, button)
        if button = 1
                then
            if x > 850 and x < 900 and y > 1030 and y < 1080 then
                randint (num1, 1, 6)
                if num1 = 1 then
                    drawfilloval (875, 1055, 5, 5, brightred)
                elsif num1 = 2 then
                    drawfilloval (875, 1068, 4, 4, brightred)
                    drawfilloval (875, 1042, 4, 4, brightred)
                elsif num1 = 3 then
                    drawfilloval (875, 1068, 4, 4, brightred)
                    drawfilloval (875, 1055, 4, 4, brightred)
                    drawfilloval (875, 1042, 4, 4, brightred)
                elsif num1 = 4 then
                    drawfilloval (862, 1068, 4, 4, brightred)
                    drawfilloval (887, 1068, 4, 4, brightred)
                    drawfilloval (862, 1042, 4, 4, brightred)
                    drawfilloval (887, 1042, 4, 4, brightred)
                elsif num1 = 5 then
                    drawfilloval (862, 1068, 4, 4, brightred)
                    drawfilloval (887, 1068, 4, 4, brightred)
                    drawfilloval (862, 1042, 4, 4, brightred)
                    drawfilloval (887, 1042, 4, 4, brightred)
                    drawfilloval (875, 1055, 4, 4, brightred)
                elsif num1 = 6 then
                    drawfilloval (862, 1068, 3, 3, brightred)
                    drawfilloval (887, 1068, 3, 3, brightred)
                    drawfilloval (862, 1042, 3, 3, brightred)
                    drawfilloval (887, 1042, 3, 3, brightred)
                    drawfilloval (862, 1055, 3, 3, brightred)
                    drawfilloval (887, 1055, 3, 3, brightred)
                end if
                counter := counter + 1
                result num1
            end if
            exit when counter = 1
        end if
    end loop
end die1

function die2 : int
    loop
        Mouse.Where (x, y, button2)
        var num2 : int := 0
        if button2 = 1 then
            if x > 850 and x < 900 and y > 950 and y < 1000 then
                randint (num2, 1, 6)
                if num2 = 1 then
                    drawfilloval (875, 975, 5, 5, brightred)
                elsif num2 = 2 then
                    drawfilloval (875, 988, 4, 4, brightred)
                    drawfilloval (875, 962, 4, 4, brightred)
                elsif num2 = 3 then
                    drawfilloval (875, 988, 4, 4, brightred)
                    drawfilloval (875, 975, 4, 4, brightred)
                    drawfilloval (875, 962, 4, 4, brightred)
                elsif num2 = 4 then
                    drawfilloval (862, 988, 4, 4, brightred)
                    drawfilloval (887, 988, 4, 4, brightred)
                    drawfilloval (862, 962, 4, 4, brightred)
                    drawfilloval (887, 962, 4, 4, brightred)
                elsif num2 = 5 then
                    drawfilloval (862, 988, 4, 4, brightred)
                    drawfilloval (887, 988, 4, 4, brightred)
                    drawfilloval (862, 962, 4, 4, brightred)
                    drawfilloval (887, 962, 4, 4, brightred)
                    drawfilloval (875, 975, 4, 4, brightred)
                elsif num2 = 6 then
                    drawfilloval (862, 988, 3, 3, brightred)
                    drawfilloval (887, 988, 3, 3, brightred)
                    drawfilloval (862, 962, 3, 3, brightred)
                    drawfilloval (887, 962, 3, 3, brightred)
                    drawfilloval (862, 975, 3, 3, brightred)
                    drawfilloval (887, 975, 3, 3, brightred)
                end if
                counter2 := counter2 + 1
                result num2
            end if
            exit when counter2 = 1
        end if
    end loop
end die2

procedure move1 (num1, num2 : int)
    var pixels_2_move : int := 0

    pixels_2_move := (num1 + num2) * 68 - 30
    %clear pervious circle

    drawfilloval (player1x, player1y, 5, 5, white)

    if pixels_2_move >= 680 then
        pixels_2_move := pixels_2_move - 680
        player2y := pixels_2_move + 388
        drawfilloval (30, player2y, 5, 5, 3)
    else
        player1x := player1x - pixels_2_move + 20
        drawfilloval (player1x, player1y, 5, 5, 6)
    end if
end move1

procedure move2 (num1, num2 : int)

    var pixels_2_move : int := 0

    pixels_2_move := (num1 + num2) * 68 - 30

    drawfilloval (player2x, player2y, 5, 5, white)

    if pixels_2_move >= 680 then
        pixels_2_move := pixels_2_move - 680
        player2y := pixels_2_move + 388
        drawfilloval (35, player2y, 5, 5, 3)
    end if

    player2x := player2x - pixels_2_move
    drawfilloval (player2x, player2y, 5, 5, 3)
end move2

board
move1 (die1, die2)


I am wondering how to reset the values in my function so i can use new the dice again for player 2. Also, how would i be able to save the location of player one so player1 can make a 2nd move and continue from where he/she leftoff.
Sponsor
Sponsor
Sponsor
sponsor
ste_louis26




PostPosted: Tue Jan 25, 2005 1:06 pm   Post subject: (No subject)

Sometimes simplier is better. You don't need functions when you could make it simplier by just using procedures
JustTrying2GetBy




PostPosted: Tue Jan 25, 2005 1:16 pm   Post subject: (No subject)

arent the two the same...basically? and could u help with my problem? sum1? Rolling Eyes

edit: i was told that i needed the function to call on the data of the dice so i could use that information to move teh pieces....
cycro1234




PostPosted: Tue Jan 25, 2005 1:17 pm   Post subject: (No subject)

You could a global variable called "playerTurn" That controls then turns. Then make an if statement checking if playerTurn = 1 or 2 .
JustTrying2GetBy




PostPosted: Tue Jan 25, 2005 1:31 pm   Post subject: (No subject)

more detail please
Tony




PostPosted: Tue Jan 25, 2005 2:35 pm   Post subject: (No subject)

you're not suppost to leave any data inside of a function. They are suppost to be clean. Value goes in, value goes out. Nothing gets left inside.

as for the player flag, it's really simple. For 2 player game I like to use the following trick.
Turing:

var playerTurn :int := 1

loop
put "it is now player #", playerTurn,"'s turn"
playerTurn *= -1
end loop

as you can see, each time though the loop the variable flips between 1 and -1, representing two different players. If you have more players, you can use a similar approach, where you increment the player ID by 1 each time untill you get to the last player.

this way when a function affect the player, you just check your global variable to see which player is to be affected.
basketball4ever




PostPosted: Wed Jan 26, 2005 1:20 am   Post subject: (No subject)

code:
var playerturn : int :=1
%ur code
if playerturn =1 then
playerturn :=2
elsif playerturn = 2 then
playerturn :=1
end if
Drakain Zeil




PostPosted: Wed Jan 26, 2005 1:10 pm   Post subject: (No subject)

tony wrote:
you're not suppost to leave any data inside of a function. They are suppost to be clean. Value goes in, value goes out. Nothing gets left inside.

as for the player flag, it's really simple. For 2 player game I like to use the following trick.
Turing:

var playerTurn :int := 1

loop
put "it is now player #", playerTurn,"'s turn"
playerTurn *= -1
end loop

as you can see, each time though the loop the variable flips between 1 and -1, representing two different players. If you have more players, you can use a similar approach, where you increment the player ID by 1 each time untill you get to the last player.

this way when a function affect the player, you just check your global variable to see which player is to be affected.
I did somthing like that for a toggle option, but instead of integers, I used boolean. So it would be something like this...

Turing:

var option : boolean:=true

loop
locate( 1,1)
put "The option is "..

if option then
put "on."
else
put "off."
end if

if (some input value equals a specific key) then
option ~=option
end if

exit when (whatever)
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: