MODULE OxoExt; (* Description: Het spel "OXO" Author: Joris Van Regemortel Date Created: 26/01/2004 lang : Oberon 2.0 *) IMPORT OutExt, In; TYPE Speler = RECORD name : ARRAY 20 OF CHAR; score : INTEGER; END; Bord = ARRAY 4, 4 OF CHAR; SpelerPointer = POINTER TO SpelerArr; SpelerArr = ARRAY OF Speler; VAR speelbord : Bord; beurt : INTEGER; aantal : INTEGER; totaalscore : INTEGER; speler : SpelerPointer; PROCEDURE Init*; (* Description: Maakt een leeg speelbord en het scorepaneel aan. Parameters: - Returntype: - Algorithm: - *) VAR x,y, i: INTEGER; BEGIN OutExt.Open; OutExt.Clear; In.Open; In.Int(aantal); NEW(speler, aantal); DEC(aantal); FOR i:=0 TO aantal DO In.String(speler[i].name); speler[i].score := 0; END; beurt := 0; FOR x := 0 TO 3 DO FOR y:= 3 TO 0 BY -1 DO speelbord[x,y] := "."; END; END; Teken; END Init; PROCEDURE Teken*; (* Description: Tekent het huidige speelbord en scorepaneel. Parameters: - Returntype: - Algorithm: - *) VAR x, y,i : INTEGER; BEGIN OutExt.Clear; FOR y := 3 TO 0 BY -1 DO OutExt.Int(y, 0); OutExt.String("| "); FOR x:= 0 TO 3 BY 1 DO OutExt.Char(speelbord[x,y]); OutExt.String(" "); END; OutExt.Ln; END; OutExt.String(" - - - -"); OutExt.Ln; OutExt.String(" 0 1 2 3"); OutExt.Ln; OutExt.Ln; OutExt.String("---------------------------"); OutExt.Ln; FOR i:=0 TO aantal DO OutExt.String(speler[i].name); OutExt.String(" : "); OutExt.Int(speler[i].score, 0); OutExt.Ln; END; OutExt.String("Totaal"); OutExt.String(" = "); OutExt.Int(totaalscore ,0 ); OutExt.Ln; OutExt.String("Speler aan de beurt: "); OutExt.String(speler[beurt].name); OutExt.Ln; OutExt.String("---------------------------"); OutExt.Ln; OutExt.Ln; END Teken; PROCEDURE Beurt*; (* Description: De coordinerende procedure voor de beurten. Parameters: - Returntype: - Algorithm: - *) VAR coord1, coord2, temp : INTEGER; teken : CHAR; BEGIN In.Open; In.Char(teken); In.Int(coord1); In.Int(coord2); IF coord1 > 3 THEN Teken; OutExt.String("Coordinaat is te groot, probeer opnieuw"); ELSIF coord2 > 3 THEN Teken; OutExt.String("Coordinaat is te groot, probeer opnieuw"); ELSE temp := totaalscore; totaalscore := 0; IF speelbord[coord1, coord2] = "." THEN speelbord[coord1, coord2] := teken; HorizontCheck; VerticCheck; DiagoRightCheck; DiagoLeftCheck; Scoreberekening(temp); Teken; ELSE Teken; OutExt.String("hier staat reeds een coordinaat, probeer opnieuw"); END; END; END Beurt; PROCEDURE Scoreberekening(temp: INTEGER); (* Description: Berekent de scores per speler, en de totaalscore. Parameters: temp (totaalscore van vorige beurt). Returntype: - Algorithm: - *) BEGIN speler[beurt].score := speler[beurt].score + totaalscore - temp; IF (totaalscore - temp)=0 THEN IF beurt = aantal THEN beurt := 0; ELSE INC(beurt); END; ELSE beurt := 0; END; END Scoreberekening; PROCEDURE HorizontCheck; (* Description: Kijkt of er horizontaal OXOs zijn.. Parameters: - Returntype: - Algorithm: - *) VAR x,y : INTEGER; BEGIN FOR y := 0 TO 3 DO FOR x := 0 TO 1 DO IF speelbord[x,y] = "o" THEN IF speelbord[x+1,y] = "x" THEN IF speelbord[x+2,y] = "o" THEN INC(totaalscore); END; END; END; END; END; END HorizontCheck; PROCEDURE VerticCheck; (* Description: Kijkt of er verticaal OXOs zijn. Parameters: - Returntype: - Algorithm: - *) VAR x,y : INTEGER; BEGIN FOR y := 0 TO 1 DO FOR x := 0 TO 3 DO IF speelbord[x,y] = "o" THEN IF speelbord[x,y+1] = "x" THEN IF speelbord[x,y+2] = "o" THEN INC(totaalscore); END; END; END; END; END; END VerticCheck; PROCEDURE DiagoRightCheck; (* Description: Kijkt of er diagonaal in recht oplopende richting OXOs zijn.. Parameters: - Returntype: - Algorithm: - *) VAR x,y : INTEGER; BEGIN FOR y := 0 TO 1 DO FOR x := 0 TO 1 DO IF speelbord[x,y] = "o" THEN IF speelbord[x+1,y+1] = "x" THEN IF speelbord[x+2,y+2] = "o" THEN INC(totaalscore); END; END; END; END; END; END DiagoRightCheck; PROCEDURE DiagoLeftCheck; (* Description: Kijkt of er diagonaal in links oplopende richting OXOs zijn. Parameters: - Returntype: - Algorithm: - *) VAR x,y : INTEGER; BEGIN FOR y := 2 TO 3 DO FOR x := 0 TO 1 DO IF speelbord[x,y] = "o" THEN IF speelbord[x+1,y-1] = "x" THEN IF speelbord[x+2,y-2] = "o" THEN INC(totaalscore); END; END; END; END; END; END DiagoLeftCheck; BEGIN END OxoExt.