Bejeweled like : Zahlen im Array tauschen
Übersicht

The ForswornBetreff: Bejeweled like : Zahlen im Array tauschen |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Jo... aktuell bin ich an nem Bejeweled Remake.
Problem: Stein auswählen und mit anderem tauschen map(MouseX()/50, MouseY()/50) bekomm ich hin... aber mir fehlt der komplette Ansatz zum tauschen Wie kann ich den aktuellen Stein in eine Auswahl speichern und einen zweiten Stein dazu?? Ich hab den kompletten Hänger. Wenn mir jetzt jemand mit nem Code kommt, dann bitte mit Erklärung, weil ich will das ja auch kapieren^^ Es hab schon so einen ähnlichen Thread, aber dort wurde das Problem nicht angesprochen, deswegen dieser hier. Zur Erläuterung: Ich habe ein 10*10 Feld, indem es Zahlen von 0-9 gibt. Wobei 0 eben nichts ist. ![]() MFG |
||
![]() |
D2006Administrator |
![]() Antworten mit Zitat ![]() |
---|---|---|
Boar, das ist aber absolutes Basic!
Code: [AUSKLAPPEN] Local a%, b%, temp%
a = 5 b = 10 ;Variablenwerte tauschen temp = a a = b b = temp ; nun ist a = 10 und b = 5 |
||
Intel Core i5 2500 | 16 GB DDR3 RAM dualchannel | ATI Radeon HD6870 (1024 MB RAM) | Windows 7 Home Premium
Intel Core 2 Duo 2.4 GHz | 2 GB DDR3 RAM dualchannel | Nvidia GeForce 9400M (256 MB shared RAM) | Mac OS X Snow Leopard Intel Pentium Dual-Core 2.4 GHz | 3 GB DDR2 RAM dualchannel | ATI Radeon HD3850 (1024 MB RAM) | Windows 7 Home Premium Chaos Interactive :: GoBang :: BB-Poker :: ChaosBreaker :: Hexagon :: ChaosRacer 2 |
The Forsworn |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Code: [AUSKLAPPEN] Function Swap()
Local a%, b%, temp% If MouseHit (1) Then map(MouseX()/50,MouseY()/50) = a EndIf If MouseHit(1) Then map(MouseX()/50,MouseY()/50) = b EndIf temp=a a=b b=temp End Function Soweit war ich ja auch schon... Aber er soll das ja bei der gleichen Taste machen, aber nicht beim gleichen Feld! Mit diesem Code wird der Stein nur überschrieben und die Steine rutschen nach: Code: [AUSKLAPPEN] Function fallen()
For x = 3 To 12 For y = 3 To 12 If map(x, y) <> 0 And map(x,y +1) = 0 Then map(x,y + 1) = map(x, y) map(x,y) = 0 EndIf Next Next |
||
BB-Fan |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
types in einem array, da kannst du dann temporär die feldinformationen speichern. | ||
The Forsworn |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Erklär mir das doch mal genauer und gib mir nen Demo-Code oder ne Anleitung... thx! ;O | ||
BB-Fan |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
feld(x,y)\information
ein 10x10 feld mit feld(x,y) dimensionieren, und mittels type kann man dann eben in jedem feld verschiedene informationen speichern. kannst aber auch ein dreidimensionales array nehmen, wobei die 3. dimension die verschiedenen informationsslots markiert. also feld(x, y, i) feld(x, y, farbe) feld(x, y, positionX) feld(x, y, positionY) x, y sind die jeweiligen feldpositionen wie auf einem schachbrett. |
||
The Forsworn |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Code: [AUSKLAPPEN] Graphics 800, 800, 0, 2
SetBuffer BackBuffer() frametimer = CreateTimer (30) ClsColor 0, 0, 255 SeedRnd MilliSecs() ;DATEN______ Global diamond1 = LoadImage ("Grafik/diamond1.bmp") MaskImage diamond1, 255,0,255 Global diamond2 = LoadImage ("Grafik/diamond2.bmp") MaskImage diamond2, 255,0,255 Global diamond3 = LoadImage ("Grafik/diamond3.bmp") MaskImage diamond3, 255,0,255 Global diamond4 = LoadImage ("Grafik/diamond4.bmp") MaskImage diamond4, 255,0,255 Global diamond5 = LoadImage ("Grafik/diamond5.bmp") MaskImage diamond5, 255,0,255 Global diamond6 = LoadImage ("Grafik/diamond6.bmp") MaskImage diamond6, 255,0,255 Global diamond7 = LoadImage ("Grafik/diamond7.bmp") MaskImage diamond7, 255,0,255 Global diamond8 = LoadImage ("Grafik/diamond8.bmp") MaskImage diamond8, 255,0,255 Global bonbon = LoadImage ("Grafik/sonderbonbon.bmp") MaskImage bonbon, 255,0,255 Global maus = LoadImage ("Grafik/maus.bmp") MaskImage maus , 255,0,255 ;______________________________ Global a = 7 Global i = 2 Global bg = LoadImage ("Grafik/hintergrund1.jpg") ;_______________________ bg = LoadImage ("Grafik/hintergrund"+Rand(1,i)+".jpg") Dim map (10,10) Type ball Field farbe Field pos_x Field pos_y End Type For x = 0 To 10 For y = 0 To 10 map(x,y) = ball Next Next ;Schleife Repeat Cls WaitTimer (frametimer) BG() Aufbau() maus() Flip Until KeyHit (1) End ;Functions!!! Function BG() DrawBlock bg, 0,0 End Function Function Aufbau() End Function Function maus() HidePointer DrawImage maus ,MouseX()-9,MouseY()-8 End Function Vom Aufbau her okay? Blick da irgendwie voll nicht durch... -.- Was soll ich denn eigtl. machen? Was bringen mir die Types? Wie soll ich das alles realisieren??? Code: [AUSKLAPPEN] Function Aufbau()
For y=0 To 9 For x=0 To 9 If (map(x,y))\farbe = 1 Then DrawImage bonbon , x*50, y*50 EndIf If (map(x,y))\farbe = 2 Then DrawImage diamond1 , x*50, y*50 EndIf If (map(x,y))\farbe = 3 Then DrawImage diamond2 , x*50, y*50 EndIf If (map(x,y))\farbe = 4 Then DrawImage diamond3 , x*50, y*50 EndIf If (map(x,y))\farbe = 5 Then DrawImage diamond4 , x*50, y*50 EndIf If (map(x,y))\farbe = 6 Then DrawImage diamond5 ,x*50, y*50 EndIf If (map(x,y))\farbe = 7 Then DrawImage diamond6 , x*50, y*50 EndIf If (map(x,y))\farbe = 8 Then DrawImage diamond7 , x*50, y*50 EndIf If (map(x,y))\farbe = 9 Then DrawImage diamond8 , x*50, y*50 EndIf Next Next Wie sprech ich die Types nun an? Edit: Wenn jetzt nicht einer kommt und mir sagt, dass das ganz normal mit nem 2d Array nicht möglich ist, oder ich mit Types einen Riesenvorteil habe, mach ich das wie gehabt mit einem gewöhnlichen Array! Viel übersichtlicher, einfacher und schneller... imo Dann hab ich aber wieder das alte Problem... =/ Ich hab ein Array und will nun die Position zweier Werte tauschen!!! Kann mir da denn niemand helfen?? _________________________________________________ Code: [AUSKLAPPEN] Graphics 800, 800, 0, 2
SetBuffer BackBuffer() frametimer = CreateTimer (30) ClsColor 0, 0, 255 SeedRnd MilliSecs() ;DATEN______ Global diamond1 = LoadImage ("Grafik/diamond1.bmp") MaskImage diamond1, 255,0,255 Global diamond2 = LoadImage ("Grafik/diamond2.bmp") MaskImage diamond2, 255,0,255 Global diamond3 = LoadImage ("Grafik/diamond3.bmp") MaskImage diamond3, 255,0,255 Global diamond4 = LoadImage ("Grafik/diamond4.bmp") MaskImage diamond4, 255,0,255 Global diamond5 = LoadImage ("Grafik/diamond5.bmp") MaskImage diamond5, 255,0,255 Global diamond6 = LoadImage ("Grafik/diamond6.bmp") MaskImage diamond6, 255,0,255 Global diamond7 = LoadImage ("Grafik/diamond7.bmp") MaskImage diamond7, 255,0,255 Global diamond8 = LoadImage ("Grafik/diamond8.bmp") MaskImage diamond8, 255,0,255 Global bonbon = LoadImage ("Grafik/sonderbonbon.bmp") MaskImage bonbon, 255,0,255 Global maus = LoadImage ("Grafik/maus.bmp") MaskImage maus , 255,0,255 ;______________________________ Global a = 6 Global i = 2 Global bg = LoadImage ("Grafik/hintergrund1.jpg") ;_______________________ ;Zufall______________________________ Dim map(20,20) Local temp% Local tempString$ .start For x = 3 To 12 For y = 3 To 12 map(x,y) = Rand(1, 201) Select map(x,y) Case 1 map(x,y) = 1 Case 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 map(x,y) = 2 Case 27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51 map(x,y) = 3 Case 52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76 map(x,y) = 4 Case 77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101 If a >= 5 Then map(x,y) = 5 Else map(x,y) = Rand(2,a) EndIf Case 102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126 If a >= 6 Then map(x,y) = 6 Else map(x,y) = Rand(2,a) EndIf Case 127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151 If a >= 7 Then map(x,y) = 7 Else map(x,y) = Rand(2,a) EndIf Case 152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176 If a >= 8 Then map(x,y) = 8 Else map(x,y) = Rand(2,a) EndIf Case 177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201 If a >= 9 Then map(x,y) = 9 Else map(x,y) = Rand(2,a) EndIf End Select tempString$=String(map(x,y),1)+String(map(x,y-1),1)+String(map(x,y-2),1) Select tempString$ Case "111","222","333","444","555","666","777","888" Goto start End Select tempString$=String(map(x,y),1)+String(map(x-1,y),1)+String(map(x-2,y),1) Select tempString$ Case "111","222","333","444","555","666","777","888" Goto start End Select Next Next ;____________________________________________ ;;;;;FIXXXXXXXXXXXXXXXX For x= 0 To 19 For y = 0 To 19 If map(x,y) = 0 Then map(x,y) = 678 EndIf Next Next ;;;;;;;;;;;;;;;;;;;;;;;;;;;; bg = LoadImage ("Grafik/hintergrund"+Rand(1,i)+".jpg") ;Schleife Repeat Cls WaitTimer (frametimer) BG() Aufbau() maus() Swap() fallen() neue() Flip Until KeyHit (1) End ;Functions!!! Function BG() DrawBlock bg, 0,0 End Function Function Aufbau() For y=3 To 12 For x=3 To 12 If (map(x,y))= 1 Then DrawImage bonbon ,x*50,y*50 EndIf If (map(x,y))= 2 Then DrawImage diamond1 , x*50, y*50 EndIf If (map(x,y))= 3 Then DrawImage diamond2 , x*50, y*50 EndIf If (map(x,y))= 4 Then DrawImage diamond3, x*50, y*50 EndIf If (map(x,y))= 5 Then DrawImage diamond4 , x*50, y*50 EndIf If (map(x,y))= 6 Then DrawImage diamond5 ,x*50, y*50 EndIf If (map(x,y))= 7 Then DrawImage diamond6 , x*50, y*50 EndIf If (map(x,y))= 8 Then DrawImage diamond7 , x*50, y*50 EndIf If (map(x,y))= 9 Then DrawImage diamond8 , x*50, y*50 EndIf Next Next End Function Function maus() HidePointer DrawImage maus ,MouseX()-9,MouseY()-8 End Function Function Swap() End Function Function fallen() For x = 3 To 12 For y = 3 To 12 If map(x, y) <> 0 And map(x,y +1) = 0 Then map(x,y + 1) = map(x, y) map(x,y) = 0 EndIf Next Next End Function Function neue() For x= 3 To 12 For y = 3 To 12 If map(x,y) = 0 And map(x,y-1) =678 Then map(x,y) = Rand(1,a) EndIf Next Next End Function Bitte hilft mir jemand das für Types zurecht zu machen und erklärt dabei, oder lößt mein Problem mit dem tauschen.... aber bitte macht irgendjemand irgendwas... =( |
||
BB-Fan |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
schau dir mal den anderen bejeweled thread an, dort wirds mit einem 3dimensionalen array gemacht.
und statt der dritten dimension hab ich eher einen type genommen, dort kann man eben auch temporäre feldwerte speichern und sieht gleich was es ist. beide wege gehen, nur mit 2d wirds schwieriger, weil das feld dann aus einem eindimensionalen array bestehen müsste, ist ein wenig kompliziert/umständlich/unnötig. |
||
The Forsworn |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Ich werd das die nächsten Tage nochmal versuchen.
Jetzt gerade hab ich genug von dem Dreck... xD In dem andern Thread (deiner^^) wurde die dritte Ebene aber nur für die Animation benutzt. ![]() Wie hast du es denn nun gelöst? |
||
The Forsworn |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
------ | ||
.erazer |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
hat jemand eine lösung dazu, gerade was die steinfallanimation betrifft? | ||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group