Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:16c174ded933, committed 2016-05-05
- Comitter:
- el14ja
- Date:
- Thu May 05 09:40:31 2016 +0000
- Parent:
- 4:e4952be370d3
- Commit message:
- Submitting
Changed in this revision
Tetris.cpp | Show annotated file Show diff for this revision Revisions of this file |
Tetris.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r e4952be370d3 -r 16c174ded933 Tetris.cpp --- a/Tetris.cpp Tue Apr 12 12:48:14 2016 +0000 +++ b/Tetris.cpp Thu May 05 09:40:31 2016 +0000 @@ -1,4 +1,4 @@ -/** My Tetris class +/** @file Tetris.cpp @@ -10,15 +10,15 @@ N5110 screen (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); int tetrominoe[7][4] = {{0x00F0,0x4444,0x0F00,0x2222},{0x0071,0x0226,0x0470,0x0322},{0x0074,0x0622,0x0170,0x0223},{0x0033,0x0033,0x0033,0x0033},{0x0072,0x0262,0x0270,0x0232},{0x0036,0x0462,0x0360,0x0231},{0x0063,0x0264,0x0630,0x0132}}; - -Tetris::Tetris(){ - + +Tetris::Tetris() +{ } void Tetris::gameSetup() { - //drawRect(int x0,int y0,int width,int height,int fill) + //prints the starting game info on the screen screen.printString("Level:",0,0); screen.printString("Score:",0,2); screen.printString("0",0,1); @@ -54,48 +54,44 @@ clearGamePixel(-6+i,12+j); } } - piecePlace(-6,12,tetrominoe[next][0]) ; + piecePlace(-6,12,tetrominoe[next][0]); //places the next piece in the next piece position } -void Tetris::gamePixel(int x, int y)//*** +void Tetris::gamePixel(int x, int y) { - - screen.drawRect(42+(3*x),2+(3*y),2,2,1); + screen.drawRect(42+(3*x),2+(3*y),2,2,1); //draws a 3x3 square on the screen relative to the game area screen.refresh(); } - -void Tetris::clearGamePixel(int x, int y){ + +void Tetris::clearGamePixel(int x, int y) +{ for(int i =0; i<3; i++) { for(int j =0; j<3; j++) { - screen.clearPixel(42+(x*3)+i,2+(3*y)+j); - + screen.clearPixel(42+(x*3)+i,2+(3*y)+j); //clears a 3x3 sqaure relative to the game area } } screen.refresh(); - } - -void Tetris::clearGame(){ +} + +void Tetris::clearGame() +{ for(int i = 0; i<30; i++) { - for(int j = 0; j<45; j++) { - screen.clearPixel(42+i,2+j); } } screen.refresh(); - } - +} + void Tetris::piecePlace(int x,int y,int shape) { - - - int count = 0; + int count = 0; //converts the hex value into seperate bits for(int i = 0; i<4; i++) { for(int j = 0; j<4; j++) { - int bit = shape & (1<<count); + int bit = shape & (1<<count); - if (bit) { + if (bit) { //prints each 1 bit gamePixel(j+x,i+y); } count++; @@ -105,17 +101,16 @@ void Tetris::pieceClear(int x,int y,int shape) { - int count = 0; + int count = 0; //converts the hex value into seperate bits for(int i = 0; i<4; i++) { for(int j = 0; j<4; j++) { int bit = shape & (1<<count); if (bit) { - clearGamePixel(j+x,i+y); + clearGamePixel(j+x,i+y); //clears each bit } count++; } } -} - +} \ No newline at end of file
diff -r e4952be370d3 -r 16c174ded933 Tetris.h --- a/Tetris.h Tue Apr 12 12:48:14 2016 +0000 +++ b/Tetris.h Thu May 05 09:40:31 2016 +0000 @@ -1,13 +1,7 @@ -/*Tetris - -Library which contains the functions for the game tetris to run on a Nokia N5110 screen +/** +@file Tetris.h -V 1.0 - initial release - -Joseph Allison March 2016 - -#ifndef TMP102_H -#define TMP102_H +@brief V 1.0 - initial release */ @@ -17,17 +11,26 @@ #include "mbed.h" #include "N5110.h" +/** +@brief Library created to interact with the game area for Tertis on a N5110 screen -class Tetris -{ +@brief Version - 1.0 + +@author Joseph Allison +@date April 2016 +*/ + + +class Tetris{ public: + /**Create Tetris instance + */ Tetris(); - - - /** - Creates the game area boarder and writes the Level, score and next text + + /** Game Setup + @brief Creates the game area boarder and writes the Level, score and next text */ void gameSetup();