- Автор темы
- Добавить закладку
- #21
Нет ребяты, я с вас офигеваю. Асмер кульный язык, тока сложный, а байсик лёгкий, но медленный! Вот авторы пурика и смутили гибрид басика и асма. Но, как это было сказанно выше, это дело вкуса.
на асме гуевый smtp-сендер в архиве - 2 кило
на Visual Basic 8 гуевый smtp-сендер в архиве - 4 кило.
;Структура клетки --------------------------------------------------
Structure cell
Objects.l
Was.l
Definition.l
Target.l
Way.l
EndStructure
; Константы ---------------------------------------------------------
#MapX.l = 20 ;Ширина карты 20 а задаем 21 так как с нуля считаем
#MapY.l = 20 ;Высота карты 20
#Empty.l = 48 ;Пустая клетка символ '0'
#Man.l = 49 ;тот кто ищет символ '1'
#Target.l = 50 ;Цель '2'
#Block.l = 51 ;Блок через который нельзя пройти
#East.l =1 ;Восток
#West.l =2 ;Запад
#North.l =3 ;Север
#South.l =4 ;Юг
#SouthWest.l = 5 ;Юга-Запад
#SouthEast.l = 6 ;Юга-Восток
#NorthWest.l = 7 ;Северо-Запад
#NorthEast.l = 8 ;Северо-Восток
#True.l = 1
#False.l = 0
; Переменные ------------------------------------------------------------
; Опишем тип long, 4 байта под каждую переменную
DefType.l FIND, UnitX, UnitY, TargetI, TargetJ, i, j
MapXMapY.l = #MapX*#MapY
; Созададим 2x мерную матрицу, каждый елемент который имеет структуру cell
Dim MATRIX.cell(#MapX+1,#MapY+1)
;Обнулим массив
For j=1 To #MapY
For i=1 To #MapX
MATRIX(i,j)\Objects = 0
MATRIX(i,j)\Was = 0
MATRIX(i,j)\Definition = 0
MATRIX(i,j)\Target = 0
MATRIX(i,j)\Way = 0
next i
next j
; Считываем данные с файла ------------------------------------------------
If ReadFile(0, "MYMAP.MAP")
For j=1 To #MapY
For i=1 To #MapX
MATRIX(i,j)\Objects = ReadByte()
If MATRIX(i,j)\Objects = #Man
UnitX = i
UnitY = j
MATRIX(i,j)\Was = #True
EndIf
if MATRIX(i,j)\Objects = #Target
MATRIX(i,j)\Target = #True
EndIf
Next i
Next j
CloseFile(0)
Else
PrintN("Error: Can't read the file 'MYMAP.MAP'")
EndIf
;/Считали данные с файла-------------------------------------------------------------------------
; Ищем путь ------------------------------------------------------
For i = 1 To #MapX
For j = 1 To #MapY
MATRIX(i,j)\Way = #False ;Обнуляем флаг дороги
Next j
Next i
; --------Основной цыкл
Num.l = 0
Finded.l = #False
Repeat
Num = Num+1
For j=1 To #MapY
For i=1 To #MapX
if MATRIX(i,j)\Was = #True
; --------------
if (MATRIX(i-1,j-1)\Was = #False) AND (MATRIX(i-1,j-1)\Objects = #Empty)
MATRIX(i-1,j-1)\Was = #True
MATRIX(i-1,j-1)\Definition = #SouthEast
EndIf
; --------------
; --------------
if (MATRIX(i,j-1)\Was = #False) AND (MATRIX(i,j-1)\Objects = #Empty)
MATRIX(i,j-1)\Was = #True
MATRIX(i,j-1)\Definition = #South
EndIf
; --------------
; --------------
if (MATRIX(i+1,j-1)\Was = #False) AND (MATRIX(i+1,j-1)\Objects = #Empty)
MATRIX(i+1,j-1)\Was = #True
MATRIX(i+1,j-1)\Definition = #SouthWest
EndIf
; --------------
; --------------
if (MATRIX(i-1,j)\Was = #False) AND (MATRIX(i-1,j)\Objects = #Empty)
MATRIX(i-1,j)\Was = #True
MATRIX(i-1,j)\Definition = #East
EndIf
; --------------
; --------------
if (MATRIX(i+1,j)\Was = #False) AND (MATRIX(i+1,j)\Objects = #Empty)
MATRIX(i+1,j)\Was = #True
MATRIX(i+1,j)\Definition = #West
EndIf
; --------------
; --------------
if (MATRIX(i-1,j+1)\Was = #False) AND (MATRIX(i-1,j+1)\Objects = #Empty)
MATRIX(i-1,j+1)\Was = #True
MATRIX(i-1,j+1)\Definition = #NorthEast
EndIf
; --------------
; --------------
if (MATRIX(i,j+1)\Was = #False) AND (MATRIX(i,j+1)\Objects = #Empty)
MATRIX(i,j+1)\Was = #True
MATRIX(i,j+1)\Definition = #North
EndIf
; --------------
; --------------
if (MATRIX(i+1,j+1)\Was = #False) AND (MATRIX(i+1,j+1)\Objects = #Empty)
MATRIX(i+1,j+1)\Was = #True
MATRIX(i+1,j+1)\Definition = #NorthWest
EndIf
; --------------
; TARGET FINDER
if (MATRIX(i-1,j-1)\Target = #True) Or (MATRIX(i,j-1)\Target = #True) Or (MATRIX(i+1,j-1)\Target = #True) Or (MATRIX(i-1,j)\Target = #True) Or (MATRIX(i+1,j)\Target = #True) Or (MATRIX(i-1,j+1)\Target = #True) Or (MATRIX(i,j+1)\Target = #True) Or (MATRIX(i+1,j+1)\Target = #True)
Finded = #True
TargetI = i
TargetJ = j
Endif
; ----------------
EndIf
Next i
Next J
if Finded = #True
i = TargetI
j = TargetJ
Repeat
MATRIX(i,j)\Way = #True
; -------------
if MATRIX(i,j)\Definition = #SouthEast
i = i + 1
j = j + 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #SouthWest
i = i - 1
j = j + 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #NorthEast
i = i + 1
j = j - 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #NorthWest
i = i - 1
j = j - 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #North
j = j - 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #South
j = j + 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #East
i = i + 1
MATRIX(i,j)\Way = #True
endif
; -------------
; -------------
if MATRIX(i,j)\Definition = #West
i = i - 1
MATRIX(i,j)\Way = #True
endif
; -------------
Until (i = UnitX) And (j = UnitY)
EndIf
Until (Num > MapXMapY) Or (Finded = #True)
; /Окончили поиск пути -------------------------------------------
If OpenConsole()
ClearConsole() ;Очистка окна консоли
For j=1 to #MapY
For i=1 to #MapX
If MATRIX(i,j)\way=#True
ConsoleColor(15, 0)
else
ConsoleColor(8, 0)
endif
View.l = MATRIX(i,j)\Objects
if View = #Empty
Print("0")
endif
if View = #Man
ConsoleColor(4, 0)
Print("1")
endif
if View = #Target
ConsoleColor(4, 0)
Print("2")
endif
if View = #Block
ConsoleColor(2, 0)
Print("3")
endif
Print(" ")
Next i
PrintN("") ;Перевод на новую строку
Next j
ConsoleColor(3, 0)
if Finded = #True
PrintN("OK, The PATH to the Target is found")
else
PrintN("Ooops, NO PATH is found")
endif
;для отладки
; Print(Str(MATRIX(13,2)\Objects)) ;51=33h='3'
;48=30h='0'
; Print(" Way: ")
; Print(Str(MATRIX(13,2)\Way))
CloseConsole()
EndIf
;
; ------------------------------------------------------------
;
; PureBasic - CD-Audio example file
;
; (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;
; 28/04/2001
; First version. A full CD-Audio player with unlimited CDDrive support
; coded in less than half an hour :-)
;
NbCDDrives = InitCDAudio()
If NbCDDrives = 0
MessageRequester("Error", "No CD Audio drives found...", 0)
End
EndIf
Global Null$
Procedure.s GetHourFormat(LengthInSeconds)
Minutes = LengthInSeconds/60
Seconds = LengthInSeconds-Minutes*60
If Seconds < 10 : Null$ = "0" : Else : Null$ = "" : EndIf
ProcedureReturn Str(Minutes)+":"+Null$+Str(Seconds)
EndProcedure
; Initialize constants for easier code reading
;
#GADGET_Play = 0
#GADGET_Stop = 1
#GADGET_Eject = 2
#GADGET_Close = 3
#GADGET_Select = 4
#GADGET_Status = 5
#GADGET_Time = 6
#GADGET_CDAudioDrive = 7
#GADGET_SelectDrive = 8
If OpenWindow(0, 100, 200, 265, 125, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "PureBasic - CDAudio Example")
If CreateGadgetList(WindowID())
ButtonGadget (#GADGET_Play , 10, 10, 60 , 24, "Play")
ButtonGadget (#GADGET_Stop , 70, 10, 60 , 24, "Stop")
ButtonGadget (#GADGET_Eject , 130, 10, 60 , 24, "Eject")
ButtonGadget (#GADGET_Close , 190, 10, 60 , 24, "Close")
ComboBoxGadget(#GADGET_Select , 10, 43, 240, 400)
TextGadget (#GADGET_Status , 10, 70, 180, 16, "Status: stopped")
TextGadget (#GADGET_Time , 200, 70, 240, 16, "")
TextGadget (#GADGET_CDAudioDrive, 10, 94, 140, 24, "Select the CD-Audio drive :")
ComboBoxGadget(#GADGET_SelectDrive , 150, 90, 40, 200)
For k=1 To NbCDDrives
UseCDAudio(k-1)
AddGadgetItem(#GADGET_SelectDrive, -1, Left(CDAudioName(),2))
Next
SetGadgetState(#GADGET_SelectDrive, 0)
UseCDAudio(0)
If NbCDDrives = 1
DisableGadget(#GADGET_SelectDrive, 1)
EndIf
EndIf
Gosub RefreshCD
Repeat
Repeat
EventID = WindowEvent() ; This time we use the WindowEvent(), non-blocking command to allow time refreshing
If EventID = #PB_Event_Gadget
Select EventGadgetID()
Case #GADGET_Play
CurrentTrack = GetGadgetState(4)+1
PlayCDAudio(CurrentTrack, CurrentTrack)
Case #GADGET_Stop
StopCDAudio()
Case #GADGET_Eject
EjectCDAudio(1)
Case #GADGET_Close
EjectCDAudio(0)
Case #GADGET_SelectDrive
UseCDAudio(GetGadgetState(#GADGET_SelectDrive))
Gosub RefreshCD
EndSelect
Else
If EventID = #PB_Event_CloseWindow : Quit = 1 : EndIf
EndIf
Until EventID = 0
Delay(20); Wait 20 ms, which is a long period for the processor, to don't steal the whole CPU power
; for our little application :)
CurrentTrack = CDAudioStatus()
If CurrentTrack > 0
SetGadgetText(#GADGET_Status, "Playing Track "+Str(CurrentTrack)+" (Length: "+GetHourFormat(CDAudioTrackLength(CurrentTrack))+")")
SetGadgetText(#GADGET_Time, "Time: "+GetHourFormat(CDAudioTrackSeconds()))
DisableGadget(#GADGET_Play, 1)
DisableGadget(#GADGET_Stop, 0)
DisableGadget(#GADGET_Select, 0)
Else
SetGadgetText(#GADGET_Status, "Status: Stopped")
SetGadgetText(#GADGET_Time, "")
DisableGadget(#GADGET_Play, 0)
DisableGadget(#GADGET_Stop, 1)
If CurrentTrack = -1; CD Drive not ready
DisableGadget(#GADGET_Select, 1)
Else
DisableGadget(#GADGET_Select, 0)
EndIf
EndIf
Until Quit = 1
EndIf
For k=0 To NbCDDrives-1 ; Stop all the CD drives, if some are playing together
UseCDAudio(k)
StopCDAudio()
Next
End
;-----------------------------------------------------------------
; SubRoutines
;
RefreshCD:
ClearGadgetItemList(#GADGET_Select)
NbAudioTracks = CDAudioTracks()
For k=1 To NbAudioTracks
AddGadgetItem(#GADGET_Select, -1, "Track "+Str(k))
Next
SetGadgetState(#GADGET_Select, 0)
Return
;
; ------------------------------------------------------------
;
; PureBasic - Terrain
;
; (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;
#CameraSpeed = 5
IncludeFile "Screen3DRequester.pb"
DefType.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
Add3DArchive("Data\" , #PB_3DArchive_FileSystem)
Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
AmbientColor(RGB(255,255,255))
CreateMaterial (0, LoadTexture(0, "Terrain_Texture.jpg"))
AddMaterialLayer(0, LoadTexture(1, "Terrain_Detail.jpg"), 1)
CreateTerrain("Terrain.png", MaterialID(0), 4, 0.6, 4, 4)
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 128, 25, 128)
SkyDome("Clouds.jpg",10)
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
EndIf
Height.f = TerrainHeight(CameraX(0), CameraZ(0))
RotateCamera(0, MouseX, MouseY, RollZ)
MoveCamera (0, KeyX, -CameraY(0)+Height+8, KeyY)
RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Почему все бэйсик к каллу приписывают???
хм... ты нагло гонишь!!! от пары кило занимает.На VB такой екзешник занимает не менее 1 Мб