![]() |
![]() |
#21 | |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,658
|
Quote:
![]() The issue is with the code, you have to analyze it and learn from what you have done, do not quit, keep at it, find the mistakes, get better, make your projects! Something that usually helps me is to follow the code step by step by hand. Keep a paper by your side with a pen/pencil and make the math necessary. Keep track of your loop points, where they begin and where they end. Throw test data at it by hand. Try doing this exercise slowly and with patience and see what is happening. Sure, pain in the ass, but best way to learn IMO. |
|
![]() |
![]() |
#22 | |
Registered User
Join Date: Dec 2012
Location: Vancouver/Canada
Posts: 678
|
Quote:
|
|
![]() |
![]() |
#23 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,381
|
Right, I've tried to keep as much of your code as I could, but lots of it was just rewritten so that it made sense. This should be much easier to follow as well as being shorter and simpler than your original
Code:
#ANY=0 #CHIP=2 #FAST=4 #CLEAR=$10000 #LARGE=$20000 #TOTAL=$80000 #FLAGNOTHING=$0 #FLAGDRAGONLY=$2 #FLAGDRAGDEPTHGADGET=$3 #FLAGALL=$F #WINDOWCLOSE=512 WBStartup ; Run through double clicking NEWTYPE.Players PlayerName$ Score.l Turn.b End NEWTYPE Dim List CurrentPlayer.Players(1) Dim Sound_$(1):Sound_$(0)="On ":Sound_$(1)="Off" ; The "On" string needed a space to overwrite all of the "Off" string Dim GridSize_(3):GridSize_(0)=3:GridSize_(1)=6:GridSize_(2)=9:GridSize_(3)=12 Dim Mode_$(1):Mode_$(0)="Classic":Mode_$(1)="Disco " ; Extra spaces added here too for the same reason Dim SA$(9) GameOver=0 Gosub Initialize ; Put your main loop here instead of a subroutine that never returns Gosub Title quit.b = False currentselection.b = 0 prevjy.b = 0 ; Previous joystick state prevjb.b = 0 ; Previous joystick button state Repeat VWait jy.b = Joyy(1) If jy AND jy <> prevjy ; Joystick moved and has changed WLocate 240, 100 + currentselection * 15:Print " "; clear it so no ghosting happens WLocate 332, 100 + currentselection * 15:Print " " currentselection + jy currentselection = QWrap(currentselection, 0, 4) ; Wrap around at top and bottom WLocate 240, 100 + currentselection * 15:Print "*" WLocate 332, 100 + currentselection * 15:Print "*" ;If currentselection < 0 Then currentselection End If prevjy = jy jb.b = Joyb(1) If jb AND prevjb = 0 ; Fire has been pressed AND it wasn't pressed before Select currentselection Case 0 ; New Game Gosub Game Case 1 ; Options Gosub Options Case 2 ; Network Gosub Network Case 3 ; Quit quit = True End Select End If prevjb = jb Until quit CloseWindow 0 CloseScreen 0 End .Network ; If Gameb(1)=16 AND normal=0 ; WLocate 80,80:Print "N e t w o r k N o t A v a i l a b l e!!" ; EndIf Return .Options S5$="Sound "+Str$(Sound_$(b)):S6$=Str$(GridSize_(iGrid)) WLocate 260,100:Print S5$ WLocate 260,115:Print "Grid "+S6$+"x"+S6$+"" WLocate 260,130:Print Mode_$(x) WLocate 260,145:Print "Return" ret.b = False currentoption.b = 0 WLocate 240, 100 + currentselection * 15:Print " "; clear it so no ghosting happens WLocate 332, 100 + currentselection * 15:Print " " WLocate 240, 100:Print "*" WLocate 332, 100:Print "*" Repeat VWait jy.b = Joyy(1) If jy AND jy <> prevjy ; Joystick moved and has changed WLocate 240, 100 + currentoption * 15:Print " "; clear it so no ghosting happens WLocate 332, 100 + currentoption * 15:Print " " currentoption + jy currentoption = QWrap(currentoption, 0, 4) ; Wrap around at top and bottom WLocate 240, 100 + currentoption * 15:Print "*" WLocate 332, 100 + currentoption * 15:Print "*" ;If currentselection < 0 Then currentselection End If prevjy = jy jb.b = Joyb(1) If jb AND prevjb = 0 ; Fire has been pressed AND it wasn't pressed before Select currentoption Case 0 ; Sound b=1-b S5$="Sound "+Str$(Sound_$(b)) WLocate 260,100:Print S5$ Case 1 ; Grid size iGrid=iGrid+1 S6$=Str$(GridSize_(iGrid)) WLocate 260,115:Print "Grid "+S6$ + " " ; +"x"+S6$+"" This line was too long and overwrote the second * so shortened it. If iGrid = 3 Then iGrid = 0 normal=1:Y=15 Case 2 ; Mode WLocate 260,130:Print Mode_$(x) x=1-x Case 3 ; Return ret = True End Select End If prevjb = jb Until ret WLocate 240, 100 + currentoption * 15:Print " "; clear it so no ghosting happens WLocate 332, 100 + currentoption * 15:Print " " Gosub Title ; Redraw previous menu Return ; Adding a . before the name of a label adds it to the list on the right so it's easier to find later .Game: ;CloseWindow 1 ;Window 1,0, 12, 640, 185, #FLAGNOTHING, "", 1,2 ;RGB 0,0,0,0 ;RGB 1,0,6,5 ;You don't need to close the window to erase it. Do this instead: InnerCls Repeat ;WLine 120, (640/2)*1, 240, (640/2)*1,1 ;WLine 120, (640/2)*2, 240, (640/2)*2,1 WLocate 0,0:Print iGrid For Y=0 To GridSize_(iGrid)-1 For X=0 To GridSize_(iGrid)-1 If iGrid=0 Then IsNum=0 Else IsNum=GridSize_(iGrid) WLocate 0,0:Print iGrid:WLocate 0,10:Print GridSize_(iGrid) Wline 111+(23*Y)*1.5,25,111+(23*Y)*1.5,142+(15*IsNum),2 Wline 25, 45+(23*X)*1.5,215+(15*IsNum),45+(23*X)*1.5,2 Next X Next Y ;WLine 282,25,282,142,2 Delay_ 1 Until GameOver=1 ;Goto Title ; Don't do this! If you must use Goto, never jump out of a subroutine, loop or any other block construct! Return ; Place to initialize all variables, screen, blitz, etc. ; Anything that needs one time initialization goes here .Initialize: ; Initialize player 1 setting If AddItem(CurrentPlayer()) CurrentPlayer()\PlayerName="Player 1" CurrentPlayer()\Score=0 CurrentPlayer()\Turn=0 End If ; Initialize player 2 setting If AddItem(CurrentPlayer()) CurrentPlayer()\PlayerName="Player 2" CurrentPlayer()\Score=0 CurrentPlayer()\Turn=0 End If ; Initialize screen, resolution, windows and background color Screen 1,11,"Tic Tac Toe" Window 1,0, 12, 640, 185, #FLAGNOTHING, "", 1,2 RGB 0,0,0,0 RGB 1,0,6,5 WindowOutput 1 Return .Title: Wline 65,30, 148,30,4:Wline 106,30,106,75,4:Wline 170,30,170,75,4 S$="C l a s s i c E d i t i o n " SA$(0)="New Game ":SA$(1)="Options ":SA$(2)="Networks ":SA$(3)="Exit " WLocate 80,80:Print S$ WLocate 260,100:Print SA$(0) WLocate 260,115:Print SA$(1) WLocate 260,130:Print SA$(2) WLocate 260,145:Print SA$(3) currentselection.b = 0 WLocate 240, 100:Print "*" WLocate 332, 100:Print "*" Return ; Don't get carried away putting stuff in subroutines |
![]() |
![]() |
#24 | |
Registered User
Join Date: Dec 2012
Location: Vancouver/Canada
Posts: 678
|
Quote:
Thank you so much! Today when I go home I will implement this code back and post the flow chart for posting! ![]() |
|
![]() |
![]() |
#25 |
Registered User
Join Date: Dec 2012
Location: Vancouver/Canada
Posts: 678
|
I have one question to ask. When I go to the option menu and select the return button t goes to title but instantly it also executes the new game and start the game immediately. What do I need to do to make t stay in title and wait for user to select new game before it start the game?
By the way I have attached my schematic. Any advice? |
![]() |
![]() |
#26 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,381
|
Hmmm, it worked fine here - the jb and prevjb variables are shared between the main menu and the options menu so that you need to release the fire button before it will let you select something in the previous menu. Perhaps your joystick button is slightly "bouncy" - issuing multiple signals that the program is then interpreting as separate presses. I would suggest inserting a VWait 5 or something after the main menu is drawn (perhaps at the end of the Title subroutine), which will give a small delay before looking for input again.
As for the flowchart, it looks good to me. If a box gets complicated (as it will for the Game subroutine), you can use a separate diagram just for that box, rather than trying to squeeze it all into one page. Having diagrams like that as you code will help greatly when it comes to keeping your program flow in order. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[blitz basic] How much amiga-blitz friendly is this? | saimon69 | Coders. Blitz Basic | 105 | 21 April 2022 19:45 |
Blitz basic 2 Help | Havie | Coders. Blitz Basic | 30 | 08 September 2013 09:15 |
blitz basic | petza | request.Apps | 11 | 08 April 2007 01:49 |
Blitz Basic 2 anyone? | jobro | request.Apps | 12 | 28 November 2005 18:15 |
Blitz Basic 2 | LaundroMat | Retrogaming General Discussion | 5 | 24 July 2001 08:10 |
|
|