20X2 Games with a 20x4 LCD and Keyboard: 21

Jamster

Senior Member
Well this is one of the easiest games to play, requiring only a voice. So here is a version on the PICAXE.As always there are instructions in the program and all Comments are welcome.
__________________________________________
Code:
[SIZE=2][SIZE=2][SIZE=2];*************************************
;*                    21             *
;*************************************
;*      The easiest game ever?       *
;*************************************[/SIZE]
[SIZE=2];21 is very much like Blackjack (which I will make at some 
;point), each player takes it in turns to add 1, 2 or 3 to
;the a number starting at 0; the person that says 21 is the
;lo(o)ser
;
;To play you need a 20x4 serial LCD connected to pin B.6 of a
;PICAXE 20X2 (To simulate goto Options>>Simulation>>Simulate 
;Serial LCD with 'serout' commands on output: and change the 
;pin name to B.6) and a keyboard or Numpad connected to C.1 and 
;C.2.
;
#picaxe 20X2
;
;Use the number keys to enter the amount you wish to add or
;to make a menu selection. Enter confirms.
;
;You may have as many players as you like but 255 players 
;does make for a boring game for at least 234 of them...
;[/SIZE]
[SIZE=2];
;************************************
;*REVISIONS:                        *
;*~~~~~~~~~~                        *
;*#Created: 3.8.11                  *
;*#Completed: 10.8.11               *
;*                                  *
;************************************[/SIZE]
[SIZE=2]SYMBOL thenumber=b0
SYMBOL players=b1
SYMBOL looper=b2
SYMBOL PICAXEon=b3
SYMBOL char=b4
SYMBOL temp1=b5
SYMBOL target=b6
SYMBOL curplayer=b7
SYMBOL lgtemp=w4
SYMBOL temp2=b10
SYMBOL true=1
SYMBOL false=0
SYMBOL round=b11
target=21
curplayer=0[/SIZE]
[SIZE=2]
init: 'Get amount of players
 '~~~~~~~~~~~~~~~~~~~~~
 serout B.6,N2400,(254,128)
 serout B.6,N2400,("How many players?")
 do 
  kbin char
  if char<>$5A then
   read char,char
   players=players*10
   players=players+char
   serout B.6,N2400,(254,192)
   serout B.6,N2400,(#players)
  endif
 loop until char=$5A
 
 'Should the computer play?
 '~~~~~~~~~~~~~~~~~~~~~~~~~
 serout B.6,N2400,(254,128)
 serout B.6,N2400,("Should PICAXE play?")
 serout B.6,N2400,(254,192)
 serout B.6,N2400,("1) Yes")
 serout B.6,N2400,(254,148)
 serout B.6,N2400,("2) No")
 kbin char
 if char=$16 then
  PICAXEon=true
 else
  PICAXEon=false
 endif
 
 'Setup gameboard
 '~~~~~~~~~~~~~~~
 serout B.6,N2400,(254,1)
 serout B.6,N2400,(254,149)
 serout B.6,N2400,("X")
 serout B.6,N2400,(254,139)
 temp2=curplayer+1
 serout B.6,N2400,("Player:",#temp2)
 
 'Play!
 '#####
 
main: curplayer=curplayer+1
 if curplayer>players and PICAXEon=true then
  'Computer
  '~~~~~~~~
  random lgtemp
  temp1=lgtemp/21845
 else
  'Human
  '~~~~~
  kbin temp1
  select temp1
  case $16
   temp1=1
  case $1E
   temp1=2
  case $26
   temp1=3
  else
   goto main
  endselect
  sertxd ("h: ",#temp1)
 endif
 if curplayer>players then
  curplayer=0
 endif
 'Display
 '~~~~~~~
 serout B.6,N2400,(254,146)
 temp2=curplayer+1
 serout B.6,N2400,(#temp2)
 serout B.6,N2400,(254,128)
 temp2=thenumber+temp1
 for looper=1 to temp2
  if looper=11 then 
   serout B.6,N2400,(254,192)
  endif
  if looper=21 then
   serout B.6,N2400,(254,148)
  endif
  serout B.6,N2400,("#")
 next
 thenumber=thenumber+temp1
 
 'Result Check
 '~~~~~~~~~~~~
 if thenumber>=target then
   goto lose
   goto loose
 endif
 
 wait 1
 goto main
 
 
 'Lo(o)se Routine
 '~~~~~~~~~~~
loose:
lose: serout B.6,N2400,(254,1)
 serout B.6,N2400,(254,195)
 serout B.6,N2400,("You are out!!!")
 wait 3
 dec players
 serout B.6,N2400,(254,1)
 serout B.6,N2400,(254,195)
 serout B.6,N2400,("Round: ",#round)
 wait 1
 serout B.6,N2400,(254,212)
 serout B.6,N2400,("Players: ",#players)
 wait 3
 inc round
 goto main
 
'Chart to understand keys
'~~~~~~~~~~~~~~~~~~~~~~~~
EEPROM $45,(0,9)
EEPROM $16,(1)
EEPROM $1E,(2)
EEPROM $25,(4,3)
EEPROM $2E,(5)
EEPROM $36,(6)
EEPROM $3D,(7,8)[/SIZE]
[/SIZE][/SIZE]
 
Top