Main Menu

The Game of MEMORY

Started by geecee, April 13, 2009, 01:21:42 AM

Previous topic - Next topic

geecee

Hi there!

In this game of MEMORY there are 12 different categories to choose from, ARMY · BUTTERFLIES · DISCO · DOGS · FACES · GARDEN · KIDS · MISCELLANEOUS · NATIONAL COSTUMES · SHIELDS · SPORTS ANIMATION · TEENS

In each category there are 25 cards, each having a matching card as its pair.

To start play, all the cards are placed face down in the play area.  In each turn, the player chooses a card and it is turned over, then chooses a second card and it is turned over.

If the cards match, they are removed from the play area.  If the cards do not match, they are returned to their respective face-down positions.

For each match made, you are awarded a score and, when all matches have been made, you win.

You are also playing against the clock.

The category selection can be automatically random or manual.

The original code was written by Kevin Picone using PB V1.64j at

http://www.underwaredesign.com/forums/index.php?topic=3002.0

and has been adapted for PB V1.63v and is used here with permission.

I have posted the code here but it and necessary media are included in the attached .zip file.

PlayBASIC Code: [Select]
remstart
****************************************************************************

The Game of MEMORY (Also known as The Game of Pairs)

Original Code by Kevin Picone
Built Using PlayBasic V1.64j

Adapted for this game by geecee with permission
Built Using PlayBasic V1.63v

****************************************************************************

About:
======

This example is a version of the classic memory game, where you have to
flip cards to find the matching pairs. Each time a pair is located
you're awarded a score. When all pairs are matched you win.

Pretty simple game mechanic, but it can be a pretty enjoyable little
game.

Have Fun!

Controls:
========

Mouse = Select a card
ESC = EXIT

****************************************************************************
remend


rem ========================================================================
rem Initialize program
rem ========================================================================

rem Set the max frames per second this program should execute at
SetFps 61.7

rem Tell PB to include the input support library
#include "Input"

rem Load fonts used in game
StatusFont =loadnewfont("arial bold",24,0)
Arial40=loadnewfont("arial bold",40,0)

rem Card width/height and number of unique cards in pack
CardWidth=71
CardHeight=96
NumberOfCardsInDeck=25

rem Declare array/s
Dim CardIMages(1)
Dim cardimage(336)
Dim message$(30)


rem Pre-load media
global cardimage=loadnewimage("Cardback.bmp")

for lp=1 to 28
CardIMage(lp) = LoadNewImage("A"+Str$(lp)+".Bmp")
CardIMage(28+lp) = LoadNewImage("B"+Str$(lp)+".Bmp")
CardIMage(56+lp) = LoadNewImage("DI"+Str$(lp)+".Bmp")
CardIMage(84+lp) = LoadNewImage("D"+Str$(lp)+".Bmp")
CardIMage(112+lp) = LoadNewImage("F"+Str$(lp)+".Bmp")
CardIMage(140+lp) = LoadNewImage("G"+Str$(lp)+".Bmp")
CardIMage(168+lp) = LoadNewImage("K"+Str$(lp)+".Bmp")
CardIMage(196+lp) = LoadNewImage("M"+Str$(lp)+".Bmp")
CardIMage(224+lp) = LoadNewImage("N"+Str$(lp)+".Bmp")
CardIMage(252+lp) = LoadNewImage("S"+Str$(lp)+".Bmp")
CardIMage(280+lp) = LoadNewImage("SP"+Str$(lp)+".Bmp")
CardIMage(308+lp) = LoadNewImage("T"+Str$(lp)+".Bmp")
next

rem Make variables visible from not only within the main programme,
rem but from within functions/sub's also.
global category
global category$
global choice

rem Go to introduction subroutine
gosub intro

rem ========================================================================
rem Declare CARD STATE constants.
rem ========================================================================

rem These constants are used for the various 'states' each card can be in.
rem They exist to make the code more readible

Constant CardState_NotMatched=1
Constant CardState_Selected=2
Constant CardState_Matched=3

rem ========================================================================
rem Declare Type to represent CARDS within the game
rem ========================================================================
Type tCard

rem State of this card. Not matched/ Selected / or matched
State

rem The value (index) of card within pack
CardValue

rem Screen position of this card
Xpos
Ypos

rem Time until a selected card changes STATES
ChangeStateTime

rem The new state this card will change to after selection.
NewState

EndType

rem ========================================================================
rem Programs MAIN LOOP
rem ========================================================================

rem repeat / Until loop
repeat

rem Jump to Play a game
Gosub PLay_Game

rem Display the game complete page once the game sub routine has returned
Gosub Game_Complete

rem Check if the player wants to play again ?
SetFont Arial40
FadeAngle#=0

repeat
Cls 0
KeyPressed$=UPPER$(inkey$())
Xpos= GetScreenWidth()/2
Ypos= GetScreenHeight()*0.40
Ink rgbfade(rgb(255,255,255),50+sinRadius(FadeAngle#,25))
CenterText Xpos,Ypos,"Play Again (Y/N)?"
FadeAngle#=wrapangle(FadeAngle#,1)
Sync
until KeyPressed$="N" or KeyPressed$="Y"

rem Repeat this loop until the players chooses the N (NO) option.
Login required to view complete source code


:)
Enjoy
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

micky4fun

Hi geecee

Nice game , well put together , even if a tad hard to complete

mick :)

geecee

Thanks for your reply micky4fun.

However, I cannot claim all credit for the "putting together" ...... The original code was by Kevin and I adapted it to suit.

:)
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

geecee

#3
Hi there!

If you want to add an extra touch try this.

Find this part of the code ...... Do a search for winner.

 Xpos=GetScreenWidth()/2
 Ypos=GetScreenHeight()*0.30
 Message$="Winner !"
 CenterText Xpos,Ypos,Message$
 ypos=ypos+GettextHeight(Message$)*2


Rem or delete

CenterText Xpos,Ypos,Message$

add this

rem Go to subroutine for flashing text
gosub flashtext


between

Message$="Winner !"

and

ypos=ypos+GettextHeight(Message$)*2

then add this subroutine at the end of the code

PlayBASIC Code: [Select]
rem ========================================================================   
rem Flash text SubRoutine
rem ========================================================================
flashtext:
repeat

` Increment flashes counter
inc flashes

` Draw box to hide previous text at location
boxc 2,180,798,220,1,rgb(0,0,0)

` Flash the text on and off every 1/10 of a second.
if textTime <= timer()
textToggle = Not textToggle
textTime = timer()+100
endif
if textToggle <> 0
CenterText Xpos,Ypos,message$
endif

` Display the Screen
sync

` End loop
until flashes=80

CenterText Xpos,Ypos,message$
return



:)
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

Big C.

hmmm... its easier to update the first post with original sourcecode   :P

geecee

Quotehmmm... its easier to update the first post with original sourcecode

Point taken Big C.

The post has been updated and now also includes a routine for manual selection of the categories.

:)
geecee

LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

geecee

Hi there!

The attachment is a screenshot from The Game of Memory ...... Due to the limitations on attachments, I couldn't attach to the original post.

:)
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)