Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
let's say i'm trying to make a game of snake on excel
i know the basic baiscs...like how to make the snake "move" but the the main problem is to keep the snake moving until i tell it to chang direction. so...is there anyway to keep a macro running on and on until i give i another command? i'm quite sure i've seen snake being done in excel somewhere before... any suggestions accepted : -- Message posted from http://www.ExcelForum.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't think this is possible.
-- Vasant "jest " wrote in message ... let's say i'm trying to make a game of snake on excel i know the basic baiscs...like how to make the snake "move" but then the main problem is to keep the snake moving until i tell it to change direction. so...is there anyway to keep a macro running on and on until i give it another command? i'm quite sure i've seen snake being done in excel somewhere before... any suggestions accepted :) --- Message posted from http://www.ExcelForum.com/ |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
just a thought: - use the OnKey event to check the arrow keys -- Regards Frank Kabel Frankfurt, Germany let's say i'm trying to make a game of snake on excel i know the basic baiscs...like how to make the snake "move" but then the main problem is to keep the snake moving until i tell it to change direction. so...is there anyway to keep a macro running on and on until i give it another command? i'm quite sure i've seen snake being done in excel somewhere before... any suggestions accepted :) --- Message posted from http://www.ExcelForum.com/ |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
thx for posting back
i know about the onkey method and how to make the snake 'move' (usin the arrow keys if i want to), but is it possible to make the snake kee moving until i make it change direction -- Message posted from http://www.ExcelForum.com |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
not tested, just to give you some ideas: - Define some global variables for storing the current position and direction - Use the OnTime procedure to move the snake every x econds (check the global variables for direction / position) - Use the OnKey method to change the global direction variables Saying this you may have a look at the following code: - uses the sheet 'Snake_Test' - moves the selection within the range A1:J10 - uses the arrow keys for changing the direction You may adapt this as you like. copy the code in a module of your workbook Option Explicit Dim Nexttime Dim PosX As Integer Dim PosY As Integer Dim direction As Byte Dim start As Boolean Sub Snake() Dim wks As Worksheet Set wks = ActiveWorkbook.Worksheets("Snake_test") Nexttime = Now + TimeValue("00:00:01") If Not start Then PosX = Int(9 * Rnd + 2) PosY = Int(9 * Rnd + 2) direction = Int(4 * Rnd + 1) start = True wks.Cells(PosY, PosX).Select Application.OnKey "{UP}", "move_up" Application.OnKey "{DOWN}", "move_down" Application.OnKey "{LEFT}", "move_left" Application.OnKey "{RIGHT}", "move_right" Application.OnTime Nexttime, "Snake" Else Select Case direction Case 1 PosX = PosX + 1 Case 2 PosX = PosX - 1 Case 3 PosY = PosY + 1 Case 4 PosY = PosY - 1 End Select If PosY < 1 Or PosY 10 Or PosX < 1 Or PosX 10 Then MsgBox "Game over" start = False Application.OnKey "{UP}" Application.OnKey "{DOWN}" Application.OnKey "{LEFT}" Application.OnKey "{RIGHT}" Else wks.Cells(PosY, PosX).Select Application.OnTime Nexttime, "Snake" End If End If End Sub Sub move_left() direction = 2 End Sub Sub move_right() direction = 1 End Sub Sub move_up() direction = 4 End Sub Sub move_down() direction = 3 End Sub -- Regards Frank Kabel Frankfurt, Germany thx for posting back i know about the onkey method and how to make the snake 'move' (using the arrow keys if i want to), but is it possible to make the snake keep moving until i make it change direction? --- Message posted from http://www.ExcelForum.com/ |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
wow thank you so much
that has really helped, i thought something like this would b impossible, so thank you once again :) oh and one more thing.. is it possible to make the snake move faste (for example, moves every half a second)? i cannot seem to do tha using the OnTime procedure.. -- Message posted from http://www.ExcelForum.com |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
AFAIK 1 second is the minimum for OnTime -- Regards Frank Kabel Frankfurt, Germany wow thank you so much that has really helped, i thought something like this would be impossible, so thank you once again :) oh and one more thing.. is it possible to make the snake move faster (for example, moves every half a second)? i cannot seem to do that using the OnTime procedure.. --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|