schule:perlenspiel
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
schule:perlenspiel [2013-10-28 16:46] – +video marco.bakera | schule:perlenspiel [2019-12-22 14:12] (aktuell) – link akt. marco.bakera | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====== Das Perlenspiel-Framework ====== | ====== Das Perlenspiel-Framework ====== | ||
+ | Mit Hilfe des [[https:// | ||
- | Mit Hilfe des [[http://perlenspiel.org/|Perlenspiel-Frameworks]] lassen sich einfach Spiele | + | Die c't stellt in Heft 23/2013 in dem Artikel |
+ | [[http://www.heise.de/ | ||
+ | - Ihr Einstieg | ||
- | < | + | Ich habe bisher folgende Spiele damit programmiert. |
- | <iframe width=" | + | |
- | </ | + | |
- | ==== Quelltext ==== | + | * [[Vier Gewinnt Perlenspiel]] |
+ | * [[Farbwechsel Perlenspiel]] | ||
- | <file javascript game.js> | ||
- | "use strict" | ||
- | |||
- | var aktuellerSpieler; | ||
- | var spielBeendet; | ||
- | |||
- | // All of the functions below MUST exist, or the engine will complain! | ||
- | |||
- | // PS.init( system, options ) | ||
- | // Initializes the game | ||
- | // This function should normally begin with a call to PS.gridSize( x, y ) | ||
- | // where x and y are the desired initial dimensions of the grid | ||
- | // [system] = an object containing engine and platform information; | ||
- | // [options] = an object with optional parameters; see documentation for details | ||
- | PS.init = function( system, options ) | ||
- | { | ||
- | "use strict"; | ||
- | |||
- | PS.gridSize( 7, 6 ); | ||
- | |||
- | PS.statusText(" | ||
- | aktuellerSpieler = 1; | ||
- | spielBeendet = false; | ||
- | }; | ||
- | |||
- | function spielerWechseln() | ||
- | { | ||
- | if(spielBeendet) | ||
- | { | ||
- | return; | ||
- | } | ||
- | | ||
- | if(aktuellerSpieler == 1) | ||
- | { | ||
- | aktuellerSpieler = 2; | ||
- | } | ||
- | else | ||
- | { | ||
- | aktuellerSpieler = 1; | ||
- | } | ||
- | PS.statusText(" | ||
- | } | ||
- | |||
- | // PS.touch ( x, y, data, options ) | ||
- | // Called when the mouse button is clicked on a bead, or when a bead is touched | ||
- | // It doesn' | ||
- | // [x] = zero-based x-position of the bead on the grid | ||
- | // [y] = zero-based y-position of the bead on the grid | ||
- | // [data] = the data value associated with this bead, 0 if none has been set | ||
- | // [options] = an object with optional parameters; see documentation for details | ||
- | PS.touch = function( x, y, data, options ) | ||
- | { | ||
- | "use strict"; | ||
- | |||
- | if(spielBeendet) | ||
- | { | ||
- | PS.audioPlay(" | ||
- | return; | ||
- | } | ||
- | | ||
- | PS.audioPlay( " | ||
- | var erfolg = einwerfen(x); | ||
- | if(!erfolg) | ||
- | { | ||
- | PS.audioPlay(" | ||
- | return; | ||
- | } | ||
- | | ||
- | gewinnPruefen(); | ||
- | spielerWechseln(); | ||
- | }; | ||
- | |||
- | function einwerfen(spalte) | ||
- | { | ||
- | for(var y=5; y>=0; y--) | ||
- | { | ||
- | if(feldFrei(spalte, | ||
- | { | ||
- | PS.color(spalte, | ||
- | return true; | ||
- | } | ||
- | } | ||
- | return false; | ||
- | } | ||
- | |||
- | function feldFrei(x, y) | ||
- | { | ||
- | return PS.color(x, | ||
- | } | ||
- | |||
- | function aktuelleFarbe() | ||
- | { | ||
- | if(aktuellerSpieler == 1) | ||
- | { | ||
- | return PS.COLOR_RED; | ||
- | } | ||
- | else | ||
- | { | ||
- | return PS.COLOR_YELLOW; | ||
- | } | ||
- | } | ||
- | |||
- | function gewinnPruefenAlleRichtungen() | ||
- | { | ||
- | for(var x=0; x<=6; x++) | ||
- | { | ||
- | for(var y=0; y<=5; y++) | ||
- | { | ||
- | var vierGefunden = suche4InAlleRichtungen(x, | ||
- | if( vierGefunden) | ||
- | { | ||
- | return true; | ||
- | } | ||
- | } | ||
- | } | ||
- | return false; | ||
- | } | ||
- | |||
- | function suche4InAlleRichtungen(x, | ||
- | { | ||
- | var waagerechtRechts = 0; // - | ||
- | var senkrechtUnten = 0; // | | ||
- | var diagonalAufwaerts = 0; // / | ||
- | var diagonalAbwaerts = 0; // \ | ||
- | |||
- | for(var i=0; i<=3; i++) | ||
- | { | ||
- | if(eigenerStein(x + i, y)) | ||
- | { | ||
- | waagerechtRechts++; | ||
- | } | ||
- | if(eigenerStein(x, | ||
- | { | ||
- | senkrechtUnten++; | ||
- | } | ||
- | if(eigenerStein(x + i, y - i)) | ||
- | { | ||
- | diagonalAufwaerts++; | ||
- | } | ||
- | if(eigenerStein(x + i, y + i)) | ||
- | { | ||
- | diagonalAbwaerts++; | ||
- | } | ||
- | } | ||
- | |||
- | if(waagerechtRechts == 4 || senkrechtUnten == 4 || | ||
- | diagonalAufwaerts == 4 || diagonalAbwaerts == 4) | ||
- | { | ||
- | return true; | ||
- | } | ||
- | else | ||
- | { | ||
- | return false; | ||
- | } | ||
- | } | ||
- | |||
- | function eigenerStein(x, | ||
- | { | ||
- | if(x >= 0 && x <= 6 && y >= 0 && y <= 5) | ||
- | { | ||
- | return PS.color(x, y) == aktuelleFarbe(); | ||
- | } | ||
- | else | ||
- | { | ||
- | return false; | ||
- | } | ||
- | } | ||
- | |||
- | function gewinnPruefen() | ||
- | { | ||
- | if( gewinnPruefenAlleRichtungen() ) | ||
- | { | ||
- | gewinnMelden(); | ||
- | spielBeendet = true; | ||
- | } | ||
- | |||
- | if(brettVoll()) | ||
- | { | ||
- | PS.statusText(" | ||
- | PS.audioPlay(" | ||
- | spielBeendet = true; | ||
- | } | ||
- | } | ||
- | |||
- | function brettVoll() | ||
- | { | ||
- | var freiePlaetze = 0; | ||
- | for(var x=0; x<=6; x++) | ||
- | { | ||
- | for(var y=0; y<=5; y++) | ||
- | { | ||
- | if( feldFrei(x, | ||
- | { | ||
- | freiePlaetze++; | ||
- | } | ||
- | } | ||
- | } | ||
- | return freiePlaetze == 0; | ||
- | } | ||
- | |||
- | function gewinnMelden() | ||
- | { | ||
- | PS.audioPlay(" | ||
- | PS.statusText(" | ||
- | } | ||
- | |||
- | // Called when the mouse button is released over a bead, or when a touch is lifted off a bead | ||
- | // It doesn' | ||
- | PS.release = function( x, y, data, options ) { | ||
- | }; | ||
- | |||
- | // Called when the mouse/touch enters a bead | ||
- | // It doesn' | ||
- | PS.enter = function( x, y, data, options ) { | ||
- | }; | ||
- | |||
- | // Called when the mouse cursor/ | ||
- | // It doesn' | ||
- | PS.exit = function( x, y, data, options ) { | ||
- | }; | ||
- | |||
- | // Called when the mouse cursor/ | ||
- | // It doesn' | ||
- | PS.exitGrid = function( options ) { | ||
- | }; | ||
- | |||
- | // Called when a key on the keyboard is pressed | ||
- | // It doesn' | ||
- | PS.keyDown = function( key, shift, ctrl, options ) { | ||
- | }; | ||
- | |||
- | // Called when a key on the keyboard is released | ||
- | // It doesn' | ||
- | PS.keyUp = function( key, shift, ctrl, options ) { | ||
- | }; | ||
- | |||
- | // Called when an input device event (other than mouse/ | ||
- | // It doesn' | ||
- | PS.input = function( sensors, options ) { | ||
- | }; | ||
- | |||
- | </ |
schule/perlenspiel.1382975171.txt.gz · Zuletzt geändert: 2017-04-19 08:39 (Externe Bearbeitung)