Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: ThinSweeper Game (1)

  1. #1

    Post ThinSweeper Game (1)

    Hi, I'm trying to get to know and have some fun with thinBasic.
    I downloaded thinBasic couple days ago and join the forum yesterday.
    This is a test code displaying the Mine Cells of the ThinSweeper Game.

    Uses "console"
    	
    Dim i As Integer
    Dim hbuffer As Long
    Dim B(25) As String
    	
    B(1) = "ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
    B(2) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
    B(3) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´ THINSWEEPERô"
    B(4) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÔÍÍÍÍÍÍÍÍÍÍÍ;³"
    B(5) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´              ³"
    B(6) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
    B(7) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´     By     ô"
    B(8) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ ChandraMDE ³³"
    B(9) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´ Thin Basic ô"
    B(10) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÔÍÍÍÍÍÍÍÍÍÍÍ;³"
    B(11)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´              ³"
    B(12)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
    B(13)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´   STATUS   ô"
    B(14)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÆÍÍÍÍÍÍÍÍÍÍÍ͵³"
    B(15)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´³ Mines (  ) ³³"
    B(16)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ Found (  ) ³³"
    B(17)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´³ Left  (  ) ³³"
    B(18)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ Skor(    ) ³³"
    B(19)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÅÄÄÄÄÄÄÄÄÄÄÄÄÅ´"
    B(20)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ ÛÛÛÛÛÛÛÛÛÛ ³³"
    B(21)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ³"
    B(22)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³  MY WEBSITE  ³"
    B(23)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´   /telinks   ³"
    B(24)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³  @wordPress  ³"
    B(25)= "ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
                                                            
    hbuffer = Console_CreateScreenBuffer
    Console_SetActiveScreenBuffer(hbuffer)
    Console_SetTitle("THINSWEEPER - Chandra MDE, http://teknikelektrolinks.com")
    Console_HideCursor
    
    For i=1 To 25
      Console_PrintAt_Buffer(B(i), 1, i, 8, hbuffer)
    Next                                             
    
    Console_PrintAt_Buffer("THINSWEEPER", 68, 3, 14, hbuffer)
    Console_PrintAt_Buffer("By", 72, 7, 14, hbuffer)
    Console_PrintAt_Buffer("ChandraMDE", 68, 8, 12, hbuffer)
    Console_PrintAt_Buffer("Thin Basic", 68, 9, 15, hbuffer)
    Console_PrintAt_Buffer("STATUS", 70, 13, 14, hbuffer)
    Console_PrintAt_Buffer("Mines (  )", 68, 15, 12, hbuffer)
    Console_PrintAt_Buffer("Found (  )", 68, 16, 10, hbuffer)
    Console_PrintAt_Buffer("Left  (  )", 68, 17, 11, hbuffer)
    Console_PrintAt_Buffer("Skor(    )", 68, 18, 13, hbuffer)
    Console_PrintAt_Buffer("MY WEBSITE", 68, 22, 14, hbuffer)
    Console_PrintAt_Buffer(" /telinks ", 68, 23, 10, hbuffer)
    Console_PrintAt_Buffer("@wordpress", 68, 24, 11, hbuffer)
    
    Console_WaitKey()
    
    Complete code is coming soon. Hopefully got more spare time for learning thinBasic.

    thinsweeper.jpg

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Dear ChandraMDE welcome to thinBasic community forum.
    Hope you will have nice time with us and thinBasic Programming Language.

    Sorry about your posts where initially put into "moderation" status and were not visible into the forum.
    This is done by forum protection system for all new users until each user has a minimum of 4 posts approved.
    So if you will make other posts (I hope) please be patience till I will approve.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3

    Red face

    Thank you for your reply, Eros.
    I wasn't reading thoroughly the post-submit notification, that's why I submitted this post twice.

    Btw, I do a little kinda campaign about using an interpreter over a compiler in the learning process of programming.
    And thinBasic is one of the interpreter I recommend to my readers. The others are Python, Ch, and Lua.
    I am no expert, but doing a lots of programming about simple tasks.
    And yes I will be patience to get my 4th post get through.

    Best regards.

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    Great idea, use Console to it's full powers - Eros- is there a way to detect Mouseinput to console-window? I might squeeze some Gadgets in
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Console_InKey
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    ReneMiner << I just think that Console is a great place to start and get closer to thinBasic.

    ErosOlmi << What a quick response. I believe Console_Inkey is using this function:

    BOOL ReadConsoleInput(
    HANDLE hConsoleInput,    // handle of a console input buffer
    PINPUT_RECORD lpBuffer,    // address of the buffer for read data
    DWORD nLength,    // number of records to read
    LPDWORD lpNumberOfEventsRead     // address of number of records read
    );
    
    from Kernel32.Dll... Am I right?

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by ChandraMDE View Post
    ErosOlmi << What a quick response. I believe Console_Inkey is using this function:

    BOOL ReadConsoleInput(
    HANDLE hConsoleInput,    // handle of a console input buffer
    PINPUT_RECORD lpBuffer,    // address of the buffer for read data
    DWORD nLength,    // number of records to read
    LPDWORD lpNumberOfEventsRead     // address of number of records read
    );
    
    from Kernel32.Dll... Am I right?
    More or less yes: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8

    Cool

    Good day, Eros.

    I was a bit curious for getting "More or less yes" instead of straight "Yes" about the ReadConsoleInput() function,
    but then, I found out that thinBasic was created using PowerBasic.

  9. #9

    ThinSweeper: InitBoard, InitCell, PrintStatus, PrintCell, PrintClosedCell

    Good day,

    Add some functions to the first posted code.
    Here is the code for ThinSweeper with following functions:
    1. InitBoard() - drawing ThinSweeper Board
    2. InitCell() - Cells initialization (Mines number, neighbours, and random positioning)
    3. PrintStatus() - Print Mines Number, Mines Found, Mines Left, and Score
    4. PrintCell() - Reveal all Cells
    5. PrintClosedCell() - Unreveal all cells

    Sometimes the program is crashed unexpectedly... I wonder why...?
    Please advice...

    'Program thinsweeper
    Uses "console"
    	
    Global i, j, x, y As Integer
    Global hbuffer As Long
    Global Cell(17, 13) As Integer
    Global CellStatus(17, 13) As Integer
    Global Mines As Integer
    Global Score As Integer
    Global Found As Integer
    Global MinesLeft As Integer
    
    Sub InitBoard()
      Dim B(25) As String
      B(1) = "ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
      B(2) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
      B(3) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´ THINSWEEPERô"
      B(4) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÔÍÍÍÍÍÍÍÍÍÍÍ;³"
      B(5) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´              ³"
      B(6) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
      B(7) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´     By     ô"
      B(8) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ ChandraMDE ³³"
      B(9) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´ Thin Basic ô"
      B(10) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÔÍÍÍÍÍÍÍÍÍÍÍ;³"
      B(11)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´              ³"
      B(12)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
      B(13)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´   STATUS   ô"
      B(14)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÆÍÍÍÍÍÍÍÍÍÍÍ͵³"
      B(15)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´³ Mines (  ) ³³"
      B(16)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ Found (  ) ³³"
      B(17)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´³ Left  (  ) ³³"
      B(18)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ Skor(    ) ³³"
      B(19)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÅÄÄÄÄÄÄÄÄÄÄÄÄÅ´"
      B(20)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ ÛÛÛÛÛÛÛÛÛÛ ³³"
      B(21)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ³"
      B(22)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³  MY WEBSITE  ³"
      B(23)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´   /telinks   ³"
      B(24)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³  @wordPress  ³"
      B(25)= "ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
                        
      Cls()                  
      hbuffer = Console_CreateScreenBuffer
      Console_SetActiveScreenBuffer(hbuffer)
      Console_SetTitle("THINSWEEPER - Chandra MDE, http://teknikelektrolinks.com")
      Console_HideCursor
    
      For i=1 To 25
        Console_PrintAt_Buffer(B(i), 1, i, 8, hbuffer)
      Next                                             
    
      Console_PrintAt_Buffer("THINSWEEPER", 68, 3, 14, hbuffer)
      Console_PrintAt_Buffer("By", 72, 7, 14, hbuffer)
      Console_PrintAt_Buffer("ChandraMDE", 68, 8, 12, hbuffer)
      Console_PrintAt_Buffer("Thin Basic", 68, 9, 15, hbuffer)
      Console_PrintAt_Buffer("STATUS", 70, 13, 14, hbuffer)
      Console_PrintAt_Buffer("Mines (  )", 68, 15, 12, hbuffer)
      Console_PrintAt_Buffer("Found (  )", 68, 16, 10, hbuffer)
      Console_PrintAt_Buffer("Left  (  )", 68, 17, 11, hbuffer)
      Console_PrintAt_Buffer("Skor(    )", 68, 18, 13, hbuffer)
      Console_PrintAt_Buffer("MY WEBSITE", 68, 22, 14, hbuffer)
      Console_PrintAt_Buffer(" /telinks ", 68, 23, 10, hbuffer)
      Console_PrintAt_Buffer("@wordpress", 68, 24, 11, hbuffer)
    End Sub
        
    '***********************
    '  Cell Initialization
    '***********************
    Sub InitCell()
      Local nb, xp, xm, yp, ym As Byte
    		For x = 1 To 16
    			For y = 1 To 12
    				Cell(x, y) = 0
    				CellStatus(x, y) = 0
    			Next
    		Next
    		           
    		Randomize Timer
    		Mines = Rnd(5, 45)
    		
    		For i = 1 To Mines
    			x = Rnd(1, 16)
    			y = Rnd(1, 12)
    			Cell(x, y) = -1
    		Next 
    		
    		Score = 0
    		Found = 0
    		MinesLeft = Mines
    		
    		For x = 1 To 16
    			For y = 1 To 12
    				If Cell(x, y) = -1 Then Next
    				 
    				nb = 0
    				xp = x + 1
    				xm = x - 1
    				yp = y + 1
    				ym = y - 1
    				
    				If xp<=16 Then
    					If Cell(xp, y) = -1 Then Incr nb
    				End If 
    				
    				If xm>=1 Then
    					If Cell(xm, y) = -1 Then Incr nb
    				End If
    				
    				If yp<=12 Then
    					If Cell(x, yp) = -1 Then Incr nb
    				End If
    				
    				If ym>=1 Then
    					If Cell(x, ym) = -1 Then Incr nb
    				End If
    				
    				If (xp<=16) And (yp<=12) Then
    					If Cell(xp, yp) = -1 Then Incr nb
    				End If
    				
    				If (xp<=16) And (ym>=1) Then
    					If Cell(xp, ym) = -1 Then Incr nb
    				End If
    				
    				If (xm>=1) And (yp<=12) Then
    					If Cell(xm, yp) = -1 Then Incr nb
    				End If
    				
    				If (xm>=1) And (ym>=1) Then
    					If Cell(xm, ym) = -1 Then Incr nb
    				End If
    				
    				Cell(x, y) = nb	
    			Next 
    		Next 
    End Sub 
                                                     
    '************************
    '  Printing Game Status
    '************************
    Sub PrintStatus()
    	Console_PrintAt_Buffer(Format$ (Mines, "00"), 75, 15, 15, hbuffer)
    	Console_PrintAt_Buffer(Format$ (Found, "00"), 75, 16, 15, hbuffer)
    	Console_PrintAt_Buffer(Format$ (MinesLeft, "00"), 75, 17, 15, hbuffer)
    	Console_PrintAt_Buffer(Format$ (Score, "0000"), 73, 18, 15, hbuffer)
    End Sub 
    
    '*********************************
    '  Print Cell (Revealed)
    '*********************************
    Sub PrintCell()
    		For x = 1 To 16
    			For y = 1 To 12
    				Select Case Cell(x, y)
    					Case -1 'bomb
    						Console_PrintAt_Buffer(Chr$(1), 3+(x-1)*4, 2+2*(y-1), 12, hbuffer)
    					Case 0 'space
    						Console_PrintAt_Buffer(Chr$(249), 3+(x-1)*4, 2+2*(y-1), 7, hbuffer)
    					Case Else 
    						Console_PrintAt_Buffer(Format$(Cell(x, y), "0"), 3+(x-1)*4, 2+2*(y-1), 8+Cell(x, y), hbuffer)
    				End Select 
    			Next
    		Next 
    End Sub
                        
    '***************************
    '  Print Cell (Unrevealed)
    '***************************
    Sub PrintClosedCell()
    		For x = 1 To 16
    			For y = 1 To 12
    				Console_PrintAt_Buffer(Chr$(254), 3+(x-1)*4, 2+2*(y-1), 4, hbuffer)
    			Next
    		Next 
    End Sub 
                        
    '--------------------------------- Let's Go!
    'Display ThinSweeper Cells 5 times                    
    Dim count As Integer
    InitBoard()
    For count=1 To 5
      InitCell()
      PrintStatus()                        
      PrintCell() 
      Console_WaitKey(2)
    Next
    PrintClosedCell()
    Console_WaitKey()
    '------------------ End of Program
    
    Some screenshots:
    thinsweeper1.jpg
    thinsweeper2.jpg
    thinsweeper_closed.jpg

  10. #10
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,527
    Rep Power
    170
    I can confirm it crashes after a few keyboard-pushes whithout any Error-Message.

    I did a few changes to eliminate it - the reason was "If Cell(X,Y) = -1 Then Next"- Line 94
    'Program thinsweeper
    Uses "console"
       
    Dim i, j, x, y As Long
    Dim hbuffer As Long
    Dim Cell(17, 13) As Long
    Dim CellStatus(17, 13) As Long
    Dim Mines As Long
    Dim Score As Long
    Dim Found As Long
    Dim MinesLeft As Long
     
    Sub InitBoard()
      Local B(25) As String
      B(1) = "ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
      B(2) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
      B(3) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´ THINSWEEPERô"
      B(4) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÔÍÍÍÍÍÍÍÍÍÍÍ;³"
      B(5) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´              ³"
      B(6) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
      B(7) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´     By     ô"
      B(8) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ ChandraMDE ³³"
      B(9) = "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´ Thin Basic ô"
      B(10) = "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÔÍÍÍÍÍÍÍÍÍÍÍ;³"
      B(11)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´              ³"
      B(12)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÕÍÍÍÍÍÍÍÍÍÍÍ͸³"
      B(13)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅ´   STATUS   ô"
      B(14)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³ÆÍÍÍÍÍÍÍÍÍÍÍ͵³"
      B(15)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´³ Mines (  ) ³³"
      B(16)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ Found (  ) ³³"
      B(17)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´³ Left  (  ) ³³"
      B(18)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ Skor(    ) ³³"
      B(19)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÅÄÄÄÄÄÄÄÄÄÄÄÄÅ´"
      B(20)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³³ ÛÛÛÛÛÛÛÛÛÛ ³³"
      B(21)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ³"
      B(22)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³  MY WEBSITE  ³"
      B(23)= "ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´   /telinks   ³"
      B(24)= "³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³   ³  @wordPress  ³"
      B(25)= "ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
                         
      Cls()                 
      hbuffer = Console_CreateScreenBuffer
      Console_SetActiveScreenBuffer(hbuffer)
      Console_SetTitle("THINSWEEPER - Chandra MDE, http://teknikelektrolinks.com")
      Console_HideCursor
     
      For i=1 To 25
        PrintAt_Buffer(B(i), 1, i, 8, hbuffer)
      Next                                            
     
      PrintAt_Buffer("THINSWEEPER", 68, 3, 14, hbuffer)
      PrintAt_Buffer("By", 72, 7, 14, hbuffer)
      PrintAt_Buffer("ChandraMDE", 68, 8, 12, hbuffer)
      PrintAt_Buffer("Thin Basic", 68, 9, 15, hbuffer)
      PrintAt_Buffer("STATUS", 70, 13, 14, hbuffer)
      PrintAt_Buffer("Mines (  )", 68, 15, 12, hbuffer)
      PrintAt_Buffer("Found (  )", 68, 16, 10, hbuffer)
      PrintAt_Buffer("Left  (  )", 68, 17, 11, hbuffer)
      PrintAt_Buffer("Skor(    )", 68, 18, 13, hbuffer)
      PrintAt_Buffer("MY WEBSITE", 68, 22, 14, hbuffer)
      PrintAt_Buffer(" /telinks ", 68, 23, 10, hbuffer)
      PrintAt_Buffer("@wordpress", 68, 24, 11, hbuffer)
    End Sub
         
    '***********************
    '  Cell Initialization
    '***********************
    Sub InitCell()
      Local nb, xp, xm, yp, ym As Byte
        For x = 1 To 16
          For y = 1 To 12
            Cell(x, y) = 0
            CellStatus(x, y) = 0
          Next
        Next
                    
        Randomize Timer
        Mines = Rnd(5, 45)
         
        For i = 1 To Mines
          x = Rnd(1, 16)
          y = Rnd(1, 12)
          Cell(x, y) = -1
        Next
         
        Score = 0
        Found = 0
        MinesLeft = Mines
         
        For x = 1 To 16
          For y = 1 To 12
            If Cell(x, y) = -1 Then 
              ' do nothing
            Else  
              nb = 0
              xp = x + 1
              xm = x - 1
              yp = y + 1
              ym = y - 1
             
              If xp<=16 Then
                If Cell(xp, y) = -1 Then Incr nb
              End If
             
              If xm>=1 Then
                If Cell(xm, y) = -1 Then Incr nb
              End If
             
              If yp<=12 Then
                If Cell(x, yp) = -1 Then Incr nb
              End If
             
              If ym>=1 Then
                If Cell(x, ym) = -1 Then Incr nb
              End If
             
              If (xp<=16) And (yp<=12) Then
                If Cell(xp, yp) = -1 Then Incr nb
              End If
             
              If (xp<=16) And (ym>=1) Then
                If Cell(xp, ym) = -1 Then Incr nb
              End If
             
              If (xm>=1) And (yp<=12) Then
                If Cell(xm, yp) = -1 Then Incr nb
              End If
             
              If (xm>=1) And (ym>=1) Then
                If Cell(xm, ym) = -1 Then Incr nb
              End If
             
              Cell(x, y) = nb
            EndIf
          Next
        Next
    End Sub
                                                      
    '************************
    '  Printing Game Status
    '************************
    Sub PrintStatus()
      PrintAt_Buffer(Format$ (Mines, "00"), 75, 15, 15, hbuffer)
      PrintAt_Buffer(Format$ (Found, "00"), 75, 16, 15, hbuffer)
      PrintAt_Buffer(Format$ (MinesLeft, "00"), 75, 17, 15, hbuffer)
      PrintAt_Buffer(Format$ (Score, "0000"), 73, 18, 15, hbuffer)
    End Sub
     
    '*********************************
    '  Print Cell (Revealed)
    '*********************************
    Sub PrintCell()
        For x = 1 To 16
          For y = 1 To 12
            Select Case Cell(x, y)
              Case -1 'bomb
                PrintAt_Buffer(Chr$(1), 3+(x-1)*4, 2+2*(y-1), 12, hbuffer)
              Case 0 'space
                PrintAt_Buffer(Chr$(249), 3+(x-1)*4, 2+2*(y-1), 7, hbuffer)
              Case Else
                PrintAt_Buffer(Format$(Cell(x, y), "0"), 3+(x-1)*4, 2+2*(y-1), 8+Cell(x, y), hbuffer)
            End Select
          Next
        Next
    End Sub
                         
    '***************************
    '  Print Cell (Unrevealed)
    '***************************
    Sub PrintClosedCell()
        For x = 1 To 16
          For y = 1 To 12
            PrintAt_Buffer(Chr$(254), 3+(x-1)*4, 2+2*(y-1), 4, hbuffer)
          Next
        Next
    End Sub
                         
    '--------------------------------- Let's Go!
    'Display ThinSweeper Cells 5 times                   
    Local count As Long
    InitBoard()
    For count=1 To 5
      InitCell()
      PrintStatus()                       
      PrintCell()
      WaitKey(2)
    Next
    PrintClosedCell()
    WaitKey
    '------------------ End of Program
    
    Edit: Suggest: Eliminate stuff as ...= -1 and replace this number by some Const as

    %Bomb = -1
    so your code becomes clearly readable
    Last edited by ReneMiner; 04-05-2013 at 09:37.
    I think there are missing some Forum-sections as beta-testing and support

Page 1 of 2 12 LastLast

Similar Threads

  1. Game: UFO on the run
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 19
    Last Post: 27-10-2008, 21:59
  2. Game: Game modes
    By Michael Hartlef in forum CM contest 2009
    Replies: 16
    Last Post: 05-10-2008, 04:58
  3. Fun game
    By Michael Clease in forum Gaming
    Replies: 4
    Last Post: 02-06-2008, 07:21
  4. A little but very serious game in 96k
    By ErosOlmi in forum Gaming
    Replies: 3
    Last Post: 12-05-2007, 20:24

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •