This page contains my library of MATLAB m-files for a simple game and everything else that I make just for fun. All of these m-files are free and you may use or modify them as you like.Â To download the m-files, simply click the link on each m-file name and a pop-up window will appear, allowing you to download the m-files from my dropboxÂ (or right-click on the link and choose ‘save target as’). Enjoy…

**Turn-Based Board Game M-Files**

TicTacToe.m – a simple game of Tic-Tac-Toe (or noughts and crosses) with MATLAB GUI.

TicTacToeLite.m – a lite version ofÂ TicTacToe.m (does not require MATLAB Image Processing Toolbox).

TicTacToeReloaded.m – another version of TicTacToe.m.

Othello.m – a game of Othello with MATLAB GUI.

SudokuSolver.m – solves an incomplete 9×9 Sudoku board or generates a random 9×9 Sudoku board.

Sudoku.m – a game of Sudoku with MATLAB GUI and its solver (requires SudokuSolver.m).

Congklak.mÂ – a traditional Indonesian board game with MATLAB GUI.

Congklak_custom.mÂ –Â a traditional Indonesian board game with MATLAB GUI (with customizable number of houses and number of beans).

CongklakReloaded.mÂ – another version ofÂ Congklak_custom.mÂ which incorporates doubleplay for first turn.

Minesweeper.mÂ – a game of minesweeper with MATLAB GUI.

***

**Arcade Game M-Files**

Pong.m – a game of classic Atari’s PongÂ with MATLAB GUI.

Snake.m – a game of classic snake with MATLAB GUI.

Tetris.m – a game of classic Tetris and its two alternate modes in one MATLAB GUI.

DoodleJump.m – a simplified version of DoodleJump game with MATLAB GUI.

Bull_n_Cow.mÂ – a number guessing game,Â Bull and Cows, with MATLAB GUI.

VirusShooter.m – a webcam-based shooting game with MATLAB GUI (requires image processing toolbox).

***

**Not-A-Game-But-Still-Fun-Or-Unique M-File**

LineScreenSaver.m – an animation of Windows XP’s line screen saver.

Balls.m – a class library for 2-D elastic collision simulation (includes example script).

Those m-files that I listed aboveÂ might be fun, but it is also not perfect. If you have any comments, critics, and suggestion for my m-files, please feel free to message me at zerocross_raptor@yahoo.com or leave a comment.

### Like this:

Like Loading...

Awesome thnxxxxxxxxxxxxxxxxxxxxxxxxxxxx

whenever i run any m.file, it give me an error “unexpected matlab operator”

Its giving error at line 191 and column 35.

Which m-file that gives you the error and what are the error message?

please install matlab

Try to keep the name saved as it is. Don’t call it something random else the function will not work

All of yours m.files gives error that “Unexpected matlab operator”. Thanks for replying

It would be helpful for me to trace the error if you could give me the complete error message printed by MATLAB for each m-files. Also, Which MATLAB version you are currently using?

it displays this error, whenever i run any mfile.

“” ??? Error: File: VirusShooter.m Line: 191 Column: 35 Unexpected MATLAB operator. “”

i’m using matlab 7.8.0 (32bit)

thanks ðŸ™‚

Only the last link works, when i press on the others ones they dont download, its just opens a new page with codes, such as :

function TicTacToe %————————————————————————– %TicTacToe %Version 1.01 %Created by Stepen %Created 5 February 2011 %Last modified 24 October 2011 %————————————————————————– %TicTacToe starts GUI game of a simple tic-tac-toe. %————————————————————————–

Dear Bilal…

I used dropbox for my file sharing and it seems that dropbox automatically opens any links to text-based files using your browser. The last code works because it is in zip files instead of m-files (Thus, dropbox prompt you to save it instead of opening the file directly in your browser). To download the code, just copy the text into your Matlab file editor and save it, or you can right click the link and choose ‘save link as’, it should work…

Regards,

Stepen

Ok thanks it worked, btw im taking a computer methods class, and we are asked to make a simple game using matlab, can you help me with that? i saw all ur games but there so long and and are somehow advanced.

Yes, all quite long because it involves interactive GUI. Do you have any game in mind that you want to make? If not, I suggest you make tic-tac-toe for two player and without using any GUI, that would make the code a lot simpler. Also, try seraching in MATLAB File Exchange, it has a lot of simple game that maybe you can learn from.

I think im gonna make a ”guessing random number game”, but first i have to send a 1-2 page with the objective of the game, its only a draft though so no problem, the draft is for the teacher to see if the game were making is too simple, she dosent want it to be waay to simple because its worth 40% of the grade, this is what i got, so what do you think? see the file below, and thanks alot for the reply,

this is what the program should contain:

A 1-2 page document outlining • Game Objective • How to Play (1 or 2 player, brief overview of rules of game) • Program Objectives • How the program will work • How the computer and players will interact

This is a first draft to be submitted for my approval at any time before the due date. I will review your document and identify whether the program will be difficult enough to warrant full points or less. If your document is reviewed and it is determined that your final program would not be difficult enough to warrant full points, you may continue with the program with a reduction in mark, or resubmit the document with more challenging Program Objectives or a completely new game. Approximately 20 separate and moderately difficult Program Objectives will be worth full points (20/20) The Game Rules will be the rubric for program marking as the more of your original rules and objectives you satisfy, the more marks you will receive. There are to be no duplicate games between students. Program approval will be given on a first come-first serve basis. The faster you submit your Game Rules document, the more likely you will be to have the project of your choice.

See attached powerpoint for an example of Game Rules.

thanks!

I can’t see the attached file… Could you maybe just email it to my mail: zerocross_raptor@yahoo.com? I think it would be better…

just wondering, what is the strategy or algorithm(without gui, just if you want to display everything in command window) you used for the othello game(e.g.. set global variables,set board….)

What do you mean by algorithm? Is it the computer algorithm (how to responds to player’s move) or how to create the game but without using GUI?

i want to design a game in matlab…but all yours codes gives error when i was using matlab version 7.5….please give a correct codes to design a tetris game….its very urgent…please requesting

Hi Shaveta,

It is probably a compatibility error… For example, older version of matlab does not support the use of tilde operator for callback’s input argument. However, I cant know the problem for sure unless you give me the error message that Matlab generates.

Thanx for the reply. Kindly let me know which version are you working on?

Matlab R2011b or 7.13.

thanx…these codes are working ðŸ™‚

hi…

kindly send me the link from where i can download the matlab latest version software easily in less time or send me the software setup on my mail id as zip file….if its possible

n also please give me a guidance how to make a game in matlab.. i want to done my project in matlab game

hiâ€¦

kindly send me the link from where i can download the matlab latest version software easily in less time or send me the software setup on my mail id as zip fileâ€¦.if its possible

Errr, no I can’t…

Like I said, if you send me the error message, I might be able to fix the code for you so that it will run on your version of MATLAB.

its ok

i work on matlab 7.5.0/R2007b…whenever i run your tetris codes…error must be occur… this error is given:-

(??? Error: File: Tetris.m Line: 403 Column: 26

Unexpected MATLAB operator)

thnx if u run this program on version 7.5.0

where line 403 is :-

function keypressfcn(~,event)

why unexpected matlab operator error is shown

It is actually pretty simple to fix… All you need is to replace the tilde sign with src. So, you should change (~,event) in line 403 and 437 with (src, event). You should also do the same with (~,~) in line 463, 472, 481, 786, 797, and maybe in other line into (src,event).

Hope this helps…

after replace the ~ operator with src…its also gives an error

??? Error: File: Tetris1.m Line: 463 Column: 5

The variable src was mentioned more than once as an input.

line no.463 is:-

function movegamespeedsliderfcn(src,src)

Sorry, my last comment was a bit confusing… For (~,~), you should change it into (src,event). Basically, wince these functions are callback function, by default it must has two input argument, which is src and event. Since my callback function didnot use any of these input argument, I still have to pass something to the function. In version 2011b, they introduced ~ (tilde sign) that you can use to replace unused input argument or output argument. That’s why you will receive error in previous Matlab because this operator is not supported.

did u run this progrm on matlab R2007b??

if not then please run these codes on matlab 2007b…..bcoz i work on this version…and show me the accurate codes for this version

please reply as soon as possible

I can’t run it on R2007 because I don’t have one… If you are still having error with my solution, let me know the error message, maybe I can help solve it… Or maybe you can google it too if my response is too slow….

if we add background music during played game then what can i do?

can u please tell me what is the function of ”~” operator

Hey, on the tictactoelite game is there anyway to replace the concept of the x and o with an image from google? Instead of marking the squares with xs and os I think it would be awesome to use some comic or funny image to play the game. Could you show me how to input that code?

Hey, for the tictactoelite game, I was wondering if it would be possible to manipulate the x and o concept into using images from google to fill in the squares. Could you show me how to fix the code to allow it to do that?

Sure… In uicontrol properties, there is ‘CData’ properties. You can modify this property to make your GUI shows an image…

Try checking out this link: http://www.mathworks.com/matlabcentral/newsreader/view_thread/158739

When i try to start snake in matlab R2007b i get the error:

??? Error using ==> figure

Invalid figure property: ‘WindowKeyPressFcn’.

Error in ==> Snake at 51

mainwindow=figure(‘Name’,’Snake’,…

And the (src,event) does not seem to work for me. I do get an error message:

Input argument ‘src’ appears never to be used.

Input argument ‘event’ appears never to be used.

can anyone tell how to collide two balls in an m file and change their sizes as they collide?

this is really interesting … (i commented two days ago but it is erased know (with no reason ;;) )

i want to change program of tetris like , when my score over a specific points, then blocks are chaged like ã„· ã… etc. to make a game more difficult .

i tried but , i think it is impossible for me ;; ã… ,.ã… can you do it ? ? ?

Hello, JH Lee…

Your comment didnt get erased, I just haven’t read and approve them. My bad :D… Actually, if you download the source code, you can see the cell variable called shapemodifier_x and shapemodifier_y. This variable defines the library of block shape to be used. You can simply add new element to these cells to add new shape. However, note that some code may be adjusted here and there to accomodate the change in the cell size (Not exactly remember if I hardcoded the cell size into the code or not). Hope this helps.

Stepen

i just played colormatched game but , down button (s) don’t work . when i push that button, it just change its color array. what is wrong…??ã… ,.ã…œ