Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Kod][Pytanie] Mój pierwszy program


Rekomendowane odpowiedzi

Opublikowano

Gra Los
4 losowe cyfry
Chwilowo 49 możliwości na wygraną i właśnie co do tego mam pytanie.
Jak mógłbym zoptymalizować kod na wygraną ?


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet( "{PAUSE}", "Exit1")
$win = False
$st = True
$1=0
$2=0
$3=0
$4=0
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Los", 175, 169, 192, 124)
$B1 = GUICtrlCreateLabel($1, 35, 25, 25, 25)
$B2 = GUICtrlCreateLabel($2, 70, 25, 25, 25)
$B3 = GUICtrlCreateLabel($3, 105, 25, 25, 25)
$B4 = GUICtrlCreateLabel($4, 140, 25, 25, 25)
$B8 = GUICtrlCreateButton("Start", 35, 72, 105, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $B8
			Start2()

	EndSwitch
WEnd

Func Start()
lose()
     $1 = Random(1, 9, 1)
	 $2 = Random(1, 9, 1)
	 $3 = Random(1, 9, 1)
	 $4 = Random(1, 9, 1)

	GUICtrlSetData($b1, $1)
	GUICtrlSetData($b2, $2)
	GUICtrlSetData($b3, $3)
	GUICtrlSetData($b4, $4)





If $1=1 And $2=1 And $3=1 And $4=1 Then
		$win = true
		EndIf
If $1=2 And $2=2 And $3=2 And $4=2 Then
		$win = true
	EndIf
If $1=3 And $2=3 And $3=3 And $4=3 Then
		$win = true
		EndIf
If $1=4 And $2=4 And $3=4 And $4=4 Then
		$win = true
	EndIf
If $1=5 And $2=5 And $3=5 And $4=5 Then
		$win = true
	EndIf
If $1=6 And $2=6 And $3=6 And $4=6 Then
		$win = true
	EndIf
If $1=7 And $2=7 And $3=7 And $4=7 Then
		$win = true
	EndIf
If $1=8 And $2=8 And $3=8 And $4=8 Then
		$win = true
		EndIf
If $1=9 And $2=9 And $3=9 And $4=9 Then
		$win = true
	EndIf
	If $1=1 And $2=2 And $3=2 And $4=1 Then
		$win = true
	EndIf
	If $1=1 And $2=4 And $3=4 And $4=1 Then
		$win = true
	EndIf
	If $1=1 And $2=6 And $3=6 And $4=1 Then
		$win = true
	EndIf
	If $1=1 And $2=8 And $3=8 And $4=1 Then
		$win = true
	EndIf
	If $1=3 And $2=2 And $3=2 And $4=3 Then
		$win = true
	EndIf
	If $1=3 And $2=4 And $3=4 And $4=3 Then
		$win = true
	EndIf
	If $1=3 And $2=6 And $3=6 And $4=3 Then
		$win = true
	EndIf
	If $1=3 And $2=8 And $3=8 And $4=3 Then
		$win = true
	EndIf
	If $1=5 And $2=2 And $3=2 And $4=5 Then
		$win = true
	EndIf
	If $1=5 And $2=4 And $3=4 And $4=5 Then
		$win = true
	EndIf
	If $1=5 And $2=6 And $3=6 And $4=5 Then
		$win = true
	EndIf
	If $1=5 And $2=8 And $3=8 And $4=5 Then
		$win = true
	EndIf
	If $1=9 And $2=2 And $3=2 And $4=9 Then
		$win = true
	EndIf
	If $1=9 And $2=4 And $3=4 And $4=9 Then
		$win = true
	EndIf
	If $1=9 And $2=6 And $3=6 And $4=9 Then
		$win = true
	EndIf
	If $1=9 And $2=8 And $3=8 And $4=9 Then
		$win = true
	EndIf
	If $1=7 And $2=2 And $3=2 And $4=7 Then
		$win = true
	EndIf
	If $1=7 And $2=4 And $3=4 And $4=7 Then
		$win = true
	EndIf
	If $1=7 And $2=6 And $3=6 And $4=7 Then
		$win = true
	EndIf
	If $1=7 And $2=8 And $3=8 And $4=7 Then
		$win = true
	EndIf
	If $1=2 And $2=1 And $3=1 And $4=2 Then
		$win = true
	EndIf
	If $1=2 And $2=3 And $3=3 And $4=2 Then
		$win = true
	EndIf
	If $1=2 And $2=5 And $3=5 And $4=2 Then
		$win = true
	EndIf
	If $1=2 And $2=7 And $3=7 And $4=2 Then
		$win = true
	EndIf
	If $1=2 And $2=9 And $3=9 And $4=2 Then
		$win = true
	EndIf
	If $1=4 And $2=1 And $3=1 And $4=4 Then
		$win = true
	EndIf
	If $1=4 And $2=3 And $3=3 And $4=4 Then
		$win = true
	EndIf
	If $1=4 And $2=5 And $3=5 And $4=4 Then
		$win = true
	EndIf
	If $1=4 And $2=7 And $3=7 And $4=4 Then
		$win = true
	EndIf
	If $1=4 And $2=9 And $3=9 And $4=4 Then
		$win = true
	Endif
	If $1=6 And $2=1 And $3=1 And $4=6 Then
		$win = true
	EndIf
	If $1=6 And $2=3 And $3=3 And $4=6 Then
		$win = true
	EndIf
	If $1=6 And $2=5 And $3=5 And $4=6 Then
		$win = true
	EndIf
	If $1=6 And $2=7 And $3=7 And $4=6 Then
		$win = true
	EndIf
	If $1=6 And $2=9 And $3=9 And $4=6 Then
		$win = true
	EndIf
	If $1=8 And $2=1 And $3=1 And $4=8 Then
		$win = true
	EndIf
	If $1=8 And $2=3 And $3=3 And $4=8 Then
		$win = true
	EndIf
	If $1=8 And $2=5 And $3=5 And $4=8 Then
		$win = true
	EndIf
	If $1=8 And $2=7 And $3=7 And $4=8 Then
		$win = true
	EndIf
	If $1=8 And $2=9 And $3=9 And $4=8 Then
		$win = true
	EndIf


If $win = true then
	 GUICtrlSetData($B8,"Winner!")
	 MsgBox(0, "", "Winner!")
Sleep( 3000 )
EndIf
sleep ( 1500)

$1=0
$2=0
$3=0
$4=0
    GUICtrlSetData($b1, $1)
	GUICtrlSetData($b2, $2)
	GUICtrlSetData($b3, $3)
	GUICtrlSetData($b4, $4)
	GUICtrlSetData($B8,"Start")
	$st = True
	$win = False
 EndFunc

 Func start2()
	  If GUICtrlRead($B8) = "Start" And $st = true Then
		  $st = False
	   GUICtrlSetData($B8,"Wait..")
Start()
Else
	EndIf
EndFunc
Func lose()
	For $z= 1 to 6

		GUICtrlSetData($B1, $z)
		GUICtrlSetData($B2, $z+1)
		GUICtrlSetData($B3, $z+4)
		GUICtrlSetData($B4, $z+3)
		sleep(200)
         Next

For $z= 6 to 1 step - 2

		GUICtrlSetData($B1, $z)
		GUICtrlSetData($B2, $z+1)
		GUICtrlSetData($B3, $z+4)
		GUICtrlSetData($B4, $z+3)
		sleep(200)
	Next
	EndFunc

Func Exit1()
	Exit
EndFunc

 

 

 

 


 


 

v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v
 

Opublikowano

Oook :)
A co myślisz o tym ? Jako że to mój 2 program ?:D
A i co do tego pytanie:)
Jak mógłbym slidera zrobić priorytetową częścią programu ?
żeby od razu po odpaleniu dało się ruszać scrolem od myszy?:D

 

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <sound.au3>
#include <SliderConstants.au3>
#include <File.au3>

Global $Sound, $Sound1, $File1
Global $s2, $s, $s3, $B, $h
$volume=True
$plynie=True
$s4=-1
$Random = True
$Rep=True
HotKeySet("{ESC}", "wyjscie")



#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Amfiproject", 390, 350, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 40, 22, 310, 70)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("...", 20, 22, 20, 20)
$Button2 = GUICtrlCreateButton("Play", 40, 100, 145, 97, $BS_ICON)
$Button4= GUICtrlCreateButton("Pause", 205, 100, 145, 97)
;$Button3= GUICtrlCreateButton("Pause", 205, 300, 145, 97)
;$Button5= GUICtrlCreateButton("UnPause", 40, 300, 145, 97)
$Button6= GUICtrlCreateButton(">>>>", 205, 200, 145, 97)
$Button7= GUICtrlCreateButton("<<<<", 40, 200, 145, 97)
$Slider1 = GUICtrlCreateSlider(40, 50, 280, 25)
$Label2 = GUICtrlCreateLabel("100%", 320, 51, 30, 25)
$Radio1 = GUICtrlCreateRadio("Random", 215, 315, 70, 17)
$Radio2 = GUICtrlCreateRadio("Repeats", 130, 315, 70, 17)
$Radio3 = GUICtrlCreateRadio("Normal", 50, 315, 70, 17)
GUICtrlSetState($radio3, $GUI_CHECKED)
;$Labe2 = GUICtrlCreateLabel("0:00", 300, 5,50,15)
;$Labe3 = GUICtrlCreateLabel("0:00",  40, 5,50,15)
;$List1 = GUICtrlCreateEdit("", 40, 300, 300, 200)
GUICtrlSetData($Slider1, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;-----------------------------------------------------------------------------@

$Folder = FileSelectFolder("Wybierz folder.", "", 2)
$szukaj = FileFindFirstFile($Folder & "\*.mp3")
$FileList = _FileListToArray($Folder,"*.mp3")
$s2 = $FileList[0]
$s=0





      While 1
         $file = FileFindNextFile($szukaj)
         If @error then ExitLoop

            GUICtrlSetData($Combo1, $file)
		WEnd
		$FileList = _FileListToArray($Folder,"*.mp3")
$s2 = $FileList[0]


FileClose($szukaj)
;------------------------------------------------------------------------------@

While 1

$nMsg = GUIGetMsg()
 $stats = _SoundStatus($Sound1)
If $volume = True then
$B = GUICtrlRead($Slider1)
SoundSetWaveVolume($
GUICtrlSetData($Label2, $B &"%")
sleep (10)
EndIf
if $plynie = True And $stats = "stopped" And $Random = True And $Rep = True Then
next1()
	EndIf
if $plynie = True And $stats = "stopped" And $Random = False And $Rep = True Then
$s = Random(1,$s2)
 next1()
EndIf
if $plynie = True And $stats = "stopped" And $Random = True And $Rep = False Then
Play()
EndIf


	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			wyjscie()

		case $Button1
			Find()
		case $Combo1
			play()
			$plynie = True
		case $Button2
			Playstop()
		Case $Radio1
			$Random=False
            $Rep=True
	    Case $Radio2
	       $Rep = False
		   $Random=True
	   Case $radio3
		   $Rep = True
		   $Random=True

		Case $Slider1
			$B = GUICtrlRead($Slider1)
SoundSetWaveVolume($
GUICtrlSetData($Label2, $B &"%")
		Case $Button4
			StartPause()
		Case $Button6
		   next1()
		   $plynie = True
	   case $Button7
		   Back()
		   $plynie = True

	EndSwitch

	WEnd
Func PLAY12()
	GUICtrlSetData($Combo1, $Filelist[$s])
	play()
	endfunc
func random1()

endfunc
func play()
	_SoundStop($Sound1)
	$Sound = GUICtrlRead($Combo1)
			$Sound1 = $Folder & "\" & $Sound
			_SoundPlay($Sound1,0)
		EndFunc
func next1()
if $s<$s2 And $Random = True And $Rep = True then
			GUICtrlSetData($Combo1, $Filelist[$s])
			play()
			$s+=1

	If $s=$s2 then
	$s=0
	EndIf
EndIf
if $Random = False And $Rep = True then
	$s = Random(1,$s2)
	GUICtrlSetData($Combo1, $Filelist[$s])
	play()
	EndIf
EndFunc

func Back()
	if $Random = False And $Rep = True then
	$s = Random(1,$s2)
	GUICtrlSetData($Combo1, $Filelist[$s])
	play()
	EndIf
if $s>0 And $Random = True And $Rep = True then
	$s-=1
			GUICtrlSetData($Combo1, $FileList[$s])
			play()
If $s=$s2 And $Random = True And $Rep = True then
	$s=2
EndIf
if $s =0 And $Random = True And $Rep = True then
	$s = $s2
	GUICtrlSetData($Combo1, $FileList[$s])
			play()
		EndIf

EndIf
		EndFunc
func Find()
GUICtrlSetData($Combo1, $s3)
	$Folder = FileSelectFolder("Wybierz folder.", "", 2)
$szukaj = FileFindFirstFile($Folder & "\*.mp3")

      While 1
         $file = FileFindNextFile($szukaj)
         If @error then ExitLoop

            GUICtrlSetData($Combo1, $file)
		WEnd
		$FileList = _FileListToArray($Folder,"*.mp3")
$s2 = $FileList[0]
FileClose($szukaj)
	EndFunc
Func wyjscie()
	Exit
EndFunc
Func StartPause()
	$hams=GUICtrlRead($Button4)
if $hams = "Pause" then
	GUICtrlSetData($Button4, "Continue...")
	Pause()
	EndIf
	If $hams = "Continue..." Then
	GUICtrlSetData($Button4, "Pause")
	resume()

	EndIf


EndFunc
func resume()
	_SoundResume($Sound1)

	endfunc
Func Pause()
	_SoundPause($Sound1)
EndFunc
Func Playstop()

		$hams2=GUICtrlRead($Button2)
if $hams2 = "Play" then
	GUICtrlSetData($Button2, "Stop")
	$plynie = True
	PLAY12()

	EndIf
	If $hams2 = "Stop" Then
	GUICtrlSetData($Button2, "Play")
	_SoundStop($Sound1)
	$plynie = False

	EndIf

	endfunc

v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v
 

Opublikowano

nie wrzucam całego, tylko kawałek kodu który powinieneś zamienić

      While 1
         $file = FileFindNextFile($szukaj)
         If @error then ExitLoop
GUICtrlSetData($Combo1, $file)
        WEnd

FileClose($szukaj)
guictrlsetstate($Slider1,$GUI_FOCUS)
;------------------------------------------------------------------------------@
 
Opublikowano

Ten trochę zmieniłem od wczoraj :D
Tak że daje nową wersje w temacie dotyczącą tego:)

v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v
 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...