4 Replies - 1124 Views - Last Post: 14 July 2009 - 05:42 PM Rate Topic: -----

#1 hoyle144  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-July 09

Suspend program flow

Posted 14 July 2009 - 01:20 PM

Iím programming a card game where the players bid in turn. Three of the players are controlled by the computer the last is human controlled. The players can bid as many times as they want. The language is VB.net. This has to be in a loop but I need to temporarily suspend the program flow so that the human player can click the bid, pass, or raise button and then continue on as necessary. My question is what command do I need to use to suspend the loop, handle the button click properly and then pick up where it left off. I suppose I could use a message box if I have to, but I really donít want to.

Thanks in advance,
Wag

Is This A Good Question/Topic? 0
  • +

Replies To: Suspend program flow

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Suspend program flow

Posted 14 July 2009 - 02:53 PM

1) show us some of your code - I suspect that you have the wrong design based on the question you are asking. You should do the three bids and then you are done that until the human enters their choice - no specific waiting. Sounds like poker, so it does terminate order certain conditions.
Was This Post Helpful? 0
  • +
  • -

#3 LoveIsNull  Icon User is offline

  • Recovering D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 646
  • Joined: 10-March 09

Re: Suspend program flow

Posted 14 July 2009 - 02:54 PM

This really depends on exactly how you're implementing the solution. Is this a single assembly or is there some kind of client\server relationship? Are there multiple human players on different computers playing over a network?
I know you said that three players are computer controlled and only one is human, so I am assuming you're developing a single assembly that handles everything and only one human will ever play at a time.
There are different kinds of conditional loops for different purposes, besides standard Do loops you can utilize Do While, Do Until (also Loop While, Loop Until) keywords and While-End While conditional loops.
The more complicated scenario is multi-threading, with the human player logic running on one thread and the computers on another. But again, it depends wildly on what your specific plans were.
Was This Post Helpful? 0
  • +
  • -

#4 hoyle144  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-July 09

Re: Suspend program flow

Posted 14 July 2009 - 04:50 PM

View Postmark.bottomley, on 14 Jul, 2009 - 01:53 PM, said:

1) show us some of your code - I suspect that you have the wrong design based on the question you are asking. You should do the three bids and then you are done that until the human enters their choice - no specific waiting. Sounds like poker, so it does terminate order certain conditions.


Thanks that's really about the only way I could do it. I guess I needed somebody to point out the obvious. The game is pinochle, if you've ever played and know all of the rules you understand how large the code can get. My code is pretty sloppy so I probably won't post any for fear of getting too many critics. I'm really just a hobbyist trying to keep my skills as sharp as possible.

Thanks again,
Wag
Was This Post Helpful? 0
  • +
  • -

#5 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Suspend program flow

Posted 14 July 2009 - 05:42 PM

Something like...

Dim PassCount As Integer = 0
Dim Bidder As Integer = 0 ' in range 0..3
Dim Human As Integer = 2 ' in range 0..3 - chose 2 for kicks here
Dim Dealer As Integer = 3 ' in range 0..3 - chose 3 for same reason
Dim HumanPassed as boolean = false

Sub StartGameClick
(Deal cards)
BidSequencer(Dealer) ' I think they start???
end sub

Sub BidSequencer(FirstBidder)
CurrentBidder = FirstBidder
while PassCount < 4
if currentBidder = Human then
if not HumanPassed then
(enable human bid controls)
exit sub
else
' auto skip human once passed
currentBidder = next bidder
end if
endif
PassCount += BidCalculation(CurrentBidder)
CurrentBidder = next bidder
end while
end sub

Function BidCalculation(CurrentBidder) as integer
(calculate bid)
(return 1 if pass else return 0)
end if
end function

Sub HumanBid(buttonCode)
' called from all buttons that are human bid result
HumanPassed = (buttonCode = PassPressed)
Bid = HumanBid
disable human inputs
CurrentBidder = next bidder
BidSequencer(CurrentBidder)
if PassCount = 4 then
(time to start the game)
end if
end sub

this will call back and forth until everyone passes then terminate

quick guess on my part - there is probably a better idea

p.s. don't be embarrassed about your code - consider it a learning experience, I haven't seen any inappropriate/disrespectful comments on anyone's code on this forum - except some random scoldings for things that are the result of laziness (My personal favourites - not using readable variable names and using the default control names).

This post has been edited by mark.bottomley: 14 July 2009 - 05:51 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1