Der Nachfolger des WDR-Computerclub mit Wolfgang Back und Wolfgang Rudolph - ...und immer ein Bit übrigbehalten!


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 C-Control Memory Spiel Kategorie: C-Control I V1.1 (von Ralf Rosche - 19.10.2021 12:44)
Ralf Rosche nutzt:  CC1-Unit V1.1, CC1-M-Unit V1.1, CC1-Station V1.1, C-Control 2
Hallo,
ich hatte etwas Zeit und wollte mal was zur Entspannung programmieren.
Aufgabe war, reines CCBASIC zu verwenden und keine komfortableren Compiler / Interpreter.

Obwohl ich inzwischen auf OCBasic umgestiegen bin, wollte ich alles in der Grundaustattung für die C-Control I mit Applicationboard, der Matrixtastatur und dem Standard Display bauen.
Das war mit 24 UserBytes gar nicht so einfach.

Die LCD Routinen stammen aus dem Buch MSR von Burkhard Kainka.

Das Spiel ist ähnlich des klasssischen Memory Spiels. Es gilt 7 Buchstabenpaare in den beiden LCD Zeilen zu finden. Die Paare sind auf die beiden Zeilen verteilt, was das Spiel etwas einfacher macht.

Nach dem Start kann man den Schwierigkeitsgrad wählen 4=leicht 6=schwer, schwer heisst die Buchsteben werden doppelt so schnell auf- und wieder zugedeckt.

Nach dem Start sieht mal 2 Zeilen mit insgesamt 14 '#' Zeichen. Die werden nun kurz auf- und dann wieder abgedeckt.  

Mit den Tasten 4 und 6 navigiert man zu den Zeichen und mit 5 wird eins aufgedeckt.
Hat man ein Paar aufgedeckt bleiben sie offen und es geht weiter.

Man hat 5 Punkte zum Start, macht man alles richtig kann man 12 erreichen, ansonsten ist es schnell vorbei.






Hier der Code:
'**************************************
'
' C-Control/BASIC        PAYATTN.BAS
'
' - Spiel wie Memory, 7 Buchstabenpaare in 2 Reihen
' - Anlehung an PAYYATN aus der Standardsammlung des HP-75 von 1983
' - für 2x16 Zeichen Display und Applictionboard & Tastatur
' - 2 Spielstufen
' - Taste 4 Bewegung nach links
' - Taste 6 Bewegung nach rechts
' - Taste 5 verdecktes Feld aufdecken, weiter neues Spiel etc
' - Startsielstand 5, Ende bei 0 oder allen aufgedeckten Zahlenpaaren, max 12
'
'**************************************

' --- Definitionen --------------------
define lcd_port byteport[2]
define lcd_rs port[14]
define lcd_rw port[13]
define lcd_e port[15]
define Tastatur ad[8]
define lcd_buf byte
define lcd_param byte
define i byte
define k byte
define l byte
define lcd_pos  byte
define char_counter byte
define score byte
define zeichen1 byte
define position1 byte
define zeichen2 byte
define position2 byte
define zeichen3 byte
define position3 byte
define zeichen4 byte
define position4 byte
define zeichen5 byte
define position5 byte
define zeichen6 byte
define position6 byte
define zeichen7 byte
define position7 byte
define e byte
define success_counter byte


gosub LCD_INIT
' Spielstart
' Leicht schwer ausgeben
lcd_param = 1
gosub LCD_GOTOLINE
lcd_pos = &H80
gosub LCD_WRITECMD
lcd_param = &H2A
gosub LCD_WRITECHAR
lcd_param = &H2A
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H53
gosub LCD_WRITECHAR
lcd_param = &H70
gosub LCD_WRITECHAR
lcd_param = &H69
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H6C
gosub LCD_WRITECHAR
lcd_param = &H73
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H61
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H2A
gosub LCD_WRITECHAR
lcd_param = &H2A
gosub LCD_WRITECHAR
lcd_param = 2
gosub LCD_GOTOLINE
lcd_pos = &HC0
lcd_param = &H4C
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H69
gosub LCD_WRITECHAR
lcd_param = &H63
gosub LCD_WRITECHAR
lcd_param = &H68
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H73
gosub LCD_WRITECHAR
lcd_param = &H63
gosub LCD_WRITECHAR
lcd_param = &H68
gosub LCD_WRITECHAR
lcd_param = &H77
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H3F
gosub LCD_WRITECHAR
hour=50

#spielpower
pause 5
if abs(Tastatur-46)<3 then goto lowpower
if abs(Tastatur-214)<3 then goto highpower
goto spielpower

#highpower
hour=hour-40
#lowpower
gosub LCD_CLS
' Achtung!!
' Drücke Taste ausgeben
i=0
lcd_param = 1
gosub LCD_GOTOLINE
lcd_pos = &H80
gosub LCD_WRITECMD
lcd_param = &H41
gosub LCD_WRITECHAR
lcd_param = &H63
gosub LCD_WRITECHAR
lcd_param = &H68
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H75
gosub LCD_WRITECHAR
lcd_param = &H6E
gosub LCD_WRITECHAR
lcd_param = &H67
gosub LCD_WRITECHAR
lcd_param = &H21
gosub LCD_WRITECHAR
lcd_param = &H21
gosub LCD_WRITECHAR
lcd_param = 2
gosub LCD_GOTOLINE
lcd_pos = &HC0
lcd_param = &H54
gosub LCD_WRITECHAR
lcd_param = &H61
gosub LCD_WRITECHAR
lcd_param = &H73
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H64
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &HF5
gosub LCD_WRITECHAR
lcd_param = &H63
gosub LCD_WRITECHAR
lcd_param = &H6B
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H6E
gosub LCD_WRITECHAR

#taste
pause 5
i=i+1 ' Zähler der für randomize beim Init genutzt wird
if abs(Tastatur-46)<3 then goto start_zufall
if abs(Tastatur-132)<3 then goto start_zufall
if abs(Tastatur-214)<3 then goto start_zufall
goto taste

#start_zufall
randomize i

#start
gosub LCD_CLS
score=5
success_counter=0
l=0
position1=-1
position2=-1
position3=-1
position4=-1
position5=-1
position6=-1
position7=-1
zeichen1= -1
zeichen2= -1
zeichen3= -1
zeichen4= -1
zeichen5= -1
zeichen6= -1
zeichen7= -1

for i = 0 to 6
#random_zeichen
e = ((RAND SHR 1)+16384)/1261  ' zahl zwischen 0 und 25
gosub test_zeichen
if e = 255 Then goto random_zeichen  ' Buchstabe schon vorhanden
gosub store_zeichen
if i=6 then goto  letze_positionen  ' letzte Position nicht per rand ermitteln, das dauert zu lange

#random_position
e = ((RAND SHR 1)+16384)/4682 ' zahl zwischen 0 und 6
gosub test_position
if e = 255 Then goto random_position ' Position schon vorhanden
gosub store_position
goto letzte_position

#letze_positionen
l=0

#next_position
e=l
gosub test_position
l=l+1
if e = 255 Then goto next_position
gosub store_position

#letzte_position
next
gosub Ausgabe
l = 0 'aktuelle Position
k=255

#Loop
pause 5
if abs(Tastatur-46)<3 then gosub move_left
if abs(Tastatur-132)<3 then goto show_zeichen
if abs(Tastatur-214)<3 then gosub move_right
goto Loop

#move_left
gosub remove_brackets
if l=0 then l=13  else l=l-1
gosub add_brackets
return

#show_zeichen
if  k=l then goto loop ' gleiches zeichen nicht noch einmal aufdecken
if l>6 then i=l-7 else i=l
if l>6 then gosub get_position_zeichen else  gosub get_zeichen   'zeichen ist in e
if e=255 then goto loop  ' zeichen ist schon aufgedeckt
BEEP 3000,1,1
if l>6 then lcd_param = 2 else lcd_param = 1
gosub LCD_GOTOLINE
if l>6 then lcd_pos = &HC0 else lcd_pos = &H80
lcd_param = lcd_pos + 1 + i * 2
gosub LCD_WRITECMD
looktab zeichen,e,lcd_param
gosub LCD_WRITECHAR
char_counter = char_counter +1
if char_counter = 2 then goto test_char
k=l 'erstes Zeichen position speichern
goto Loop

#hide_zeichen
' zeile 1
if l>6 then i=l-7 else i=l
if l>6 then lcd_param = 2 else lcd_param = 1
gosub LCD_GOTOLINE
if l>6 then lcd_pos = &HC0 else lcd_pos = &H80
lcd_param = lcd_pos + 1 + i * 2
gosub LCD_WRITECMD
lcd_param = &H23
gosub LCD_WRITECHAR
' zeile 2
if k>6 then i=k-7 else i=k
if k>6 then lcd_param = 2 else lcd_param = 1
gosub LCD_GOTOLINE
if k>6 then lcd_pos = &HC0 else lcd_pos = &H80
lcd_param = lcd_pos + 1 + i * 2
gosub LCD_WRITECMD
lcd_param = &H23
gosub LCD_WRITECHAR
return

#move_right
gosub remove_brackets
if l=13 then l=0 else l=l+1
gosub add_brackets
return

#remove_brackets
if l>6 then lcd_param = 2 else lcd_param = 1
gosub LCD_GOTOLINE
if l>6 then lcd_pos = &HC0 else  lcd_pos = &H80
if l>6 then i= l-7 else i=l
lcd_param = lcd_pos + i * 2
gosub LCD_WRITECMD
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = lcd_pos + 2 + i*2
gosub LCD_WRITECMD
lcd_param = &H20
gosub LCD_WRITECHAR
return

#add_brackets
if l>6 then lcd_param = 2 else lcd_param = 1
gosub LCD_GOTOLINE
if l>6 then lcd_pos = &HC0 else lcd_pos = &H80
if l>6 then i= l-7 else i=l
lcd_param = lcd_pos + i * 2
gosub LCD_WRITECMD
lcd_param = &H5B
gosub LCD_WRITECHAR
lcd_param = lcd_pos + 2 + i*2
gosub LCD_WRITECMD
lcd_param = &H5D
gosub LCD_WRITECHAR
return

#test_char
if k>6 then i=k-7 else i=k
if k>6 then gosub get_position_zeichen else gosub get_zeichen
lcd_buf = e
if l>6 then i=l-7 else i=l
if l>6 then gosub get_position_zeichen else gosub get_zeichen
if lcd_buf=e then goto sucess else goto fault

#sucess
BEEP 3000,1,1
BEEP 2000,1,1
BEEP 1000,1,1
score = score +1
char_counter = 0
' l und k als gezeigt markieren für show_zeichen
if k> 6 then i=k-7
if k>6 then  gosub get_position_zeichen  else e=k
i=e
e=255
gosub store_zeichen
k=255
success_counter = success_counter+1 ' anzahl aufgedeckter Zahelnpaare
if success_counter  < 7 then goto Loop ' noch nicht alles aufgedeckt, weitermachen
' alles wurde aufgedeckt, gewonnen Meldung zeigen
BEEP 3000,5,1
BEEP 2000,5,1
BEEP 1000,5,1
gosub LCD_CLS
lcd_param = 1
gosub LCD_GOTOLINE
lcd_pos = &H80
gosub LCD_WRITECMD
lcd_param = &H47
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H77
gosub LCD_WRITECHAR
lcd_param = &H6F
gosub LCD_WRITECHAR
lcd_param = &H6E
gosub LCD_WRITECHAR
lcd_param = &H6E
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H6E
gosub LCD_WRITECHAR
lcd_param = &H21
gosub LCD_WRITECHAR
lcd_param = &H21
gosub LCD_WRITECHAR
lcd_param = 2
gosub LCD_GOTOLINE
lcd_pos = &HC0
gosub LCD_WRITECMD
lcd_param = &H53
gosub LCD_WRITECHAR
lcd_param = &H63
gosub LCD_WRITECHAR
lcd_param = &H6F
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H3A
gosub LCD_WRITECHAR
if score <10 then goto score_9
lcd_param = &H30 + score / 10
gosub LCD_WRITECHAR
score = score mod 10

#score_9
lcd_param = &H30 + score
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H53
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H61
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H74
gosub LCD_WRITECHAR
lcd_param = &H3F
gosub LCD_WRITECHAR

#warte
pause 5
if abs(Tastatur-132)<3 then goto start
goto warte

#fault
BEEP 3000,1,1
BEEP 3000,1,1
score = score -1
char_counter = 0
gosub hide_zeichen
k=255
if score >0 then goto Loop  ' noch nicht verloren
' verloren, punktesatnd ist 0
' Display Leider verloren
BEEP 3000,10,1
BEEP 3000,10,1
gosub LCD_CLS
lcd_param = 1
gosub LCD_GOTOLINE
lcd_pos = &H80
gosub LCD_WRITECMD
lcd_param = &H4C
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H69
gosub LCD_WRITECHAR
lcd_param = &H64
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H76
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H6C
gosub LCD_WRITECHAR
lcd_param = &H6F
gosub LCD_WRITECHAR
lcd_param = &H72
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H6E
gosub LCD_WRITECHAR
lcd_param = &H21
gosub LCD_WRITECHAR
' neues Spiel?
lcd_param = 2
gosub LCD_GOTOLINE
lcd_pos = &HC0
gosub LCD_WRITECMD
lcd_param = &H4E
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H75
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H73
gosub LCD_WRITECHAR
lcd_param = &H20
gosub LCD_WRITECHAR
lcd_param = &H53
gosub LCD_WRITECHAR
lcd_param = &H70
gosub LCD_WRITECHAR
lcd_param = &H69
gosub LCD_WRITECHAR
lcd_param = &H65
gosub LCD_WRITECHAR
lcd_param = &H6C
gosub LCD_WRITECHAR
lcd_param = &H3F
gosub LCD_WRITECHAR
goto warte

#Ausgabe
for k = 1 to 2
 lcd_param = k
 gosub LCD_GOTOLINE
 for i = 0 to 6
  lcd_param = &H20
  gosub LCD_WRITECHAR
  lcd_param = &H23
  gosub LCD_WRITECHAR
 next
next
pause hour
lcd_pos = &H80
for k = 1 to 2
 lcd_param = k
 gosub LCD_GOTOLINE
 for i = 0 to 6
  BEEP 160,1,1
  lcd_param = lcd_pos + i * 2
  gosub LCD_WRITECMD
  lcd_param = &H5B
  gosub LCD_WRITECHAR
  lcd_param = lcd_pos + 2 +i*2
  gosub LCD_WRITECMD
  lcd_param = &H5D
  gosub LCD_WRITECHAR
  lcd_param = lcd_pos + 1+ i * 2
  gosub LCD_WRITECMD
  if k=2 then goto zeile2
  gosub get_zeichen
  looktab zeichen,e,lcd_param
  gosub LCD_WRITECHAR
  goto  letztes_zeichen
#zeile2
  gosub get_position_zeichen
  looktab zeichen,e,lcd_param
  gosub LCD_WRITECHAR
#letztes_zeichen
  BEEP 80,1,1
  pause hour
  lcd_param = lcd_pos + 1+ i * 2
  gosub LCD_WRITECMD
  lcd_param = &H23
  gosub LCD_WRITECHAR
  if i = 6 THEN goto ende
  lcd_param = lcd_pos + i * 2
  gosub LCD_WRITECMD
  lcd_param = &H20
  gosub LCD_WRITECHAR
#ende
  lcd_param = lcd_pos + i * 2
  gosub LCD_WRITECMD
  lcd_param = &H20
  gosub LCD_WRITECHAR
  lcd_param = lcd_pos + 2 +i*2
  gosub LCD_WRITECMD
  lcd_param = &H20
  gosub LCD_WRITECHAR
 next
  lcd_pos = &HC0
next
' Anfang, Curser Spalte 0 Zeile 1
lcd_param = 1
gosub LCD_GOTOLINE
lcd_param = &H80
gosub LCD_WRITECMD
lcd_param = &H5B
gosub LCD_WRITECHAR
lcd_param = &H80 + 2
gosub LCD_WRITECMD
lcd_param = &H5D
gosub LCD_WRITECHAR
return

#test_zeichen
if zeichen1 = e then e=255
if zeichen2 = e then e=255
if zeichen3 = e then e=255
if zeichen4 = e then e=255
if zeichen5 = e then e=255
if zeichen6 = e then e=255
if zeichen7 = e then e=255
return

#test_position
if position1 = e then e=255
if position2 = e then e=255
if position3 = e then e=255
if position4 = e then e=255
if position5 = e then e=255
if position6 = e then e=255
if position7 = e then e=255
return

#store_zeichen
if i = 0 then zeichen1 = e
if i = 1 then zeichen2 = e
if i = 2 then zeichen3 = e
if i = 3 then zeichen4 = e
if i = 4 then zeichen5 = e
if i = 5 then zeichen6 = e
if i = 6 then zeichen7 = e
return

#store_position
if i = 0 then position1 = e
if i = 1 then position2 = e
if i = 2 then position3 = e
if i = 3 then position4 = e
if i = 4 then position5 = e
if i = 5 then position6 = e
if i = 6 then position7 = e
return

#get_zeichen
if i=0 then e=zeichen1
if i=1  then e=zeichen2
if i=2  then e=zeichen3
if i=3  then e=zeichen4
if i=4  then e=zeichen5
if i=5  then e=zeichen6
if i=6  then e=zeichen7
return

#get_position
if i=0 then e=position1
if i=1  then e=position2
if i=2  then e=position3
if i=3  then e=position4
if i=4  then e=position5
if i=5  then e=position6
if i=6  then e=position7
return

#get_position_zeichen
if position1=i then e=zeichen1
if position2=i then e=zeichen2
if position3=i then e=zeichen3
if position4=i then e=zeichen4
if position5=i then e=zeichen5
if position6=i then e=zeichen6
if position7=i then e=zeichen7
return

'*** LCD_Interface ***
#LCD_INIT
' alle ports 0
lcd_port = OFF
' 8-Bit-Modus aktivieren
lcd_param=&H38 : gosub LCD_WRITECMD
' mit 8-Bit-Command in 4-Bit-Modus umschalten
lcd_port=&B00000010
tog lcd_e
tog lcd_e
' ab jetzt 4-Bit-Modus
lcd_param = &H28 : gosub LCD_WRITECMD
lcd_param = &H0C : gosub LCD_WRITECMD
' Display loeschen
#LCD_CLS
lcd_param = &H02 : gosub LCD_WRITECMD
lcd_param = &H01 : gosub LCD_WRITECMD
return
' Zeilenwechsel
#LCD_GOTOLINE
if lcd_param = 1 then lcd_param = &H80
if lcd_param = 2 then lcd_param = &HC0
goto LCD_WRITECMD
' LCD-Kommando
#LCD_WRITECMD
lcd_buf = OFF
goto LCD_WRITE
' Zeichenausgabe
#LCD_WRITECHAR
lcd_buf = &B00100000
' Kommando oder Zeichen an Display senden
#LCD_WRITE
' Hi-Nibble
lcd_port = lcd_buf or (lcd_param shr 4)
tog lcd_e
tog lcd_e
' Lo-Nibble
lcd_port = lcd_buf or (lcd_param and &H0F)
tog lcd_e
tog lcd_e
return

table zeichen ' zeichen tabelle Codierung für Hitachi HD44780
      &H41 &H42 &H43 &H44 &H45 &H46 &H47 &H48 &H49 &H4A &H4B &H4C &H4D &H4E &H4F &H50 &H51 &H52 &H53 &H54 &H55 &H56 &H57 &H58 &H59 &H5A
tabend

 Antwort schreiben

Bisherige Antworten: