Code covered by the BSD License  

Highlights from
Magic!!!. Guesses the number in your mind!!

image thumbnail
from Magic!!!. Guesses the number in your mind!! by Vihang Patil
This game will guess the number in your mind. Its Magic!!

magic_number(varargin)
function varargout = magic_number(varargin)
% MAGIC_NUMBER M-file for magic_number.fig
%      MAGIC_NUMBER, by itself, creates a new MAGIC_NUMBER or raises the existing
%      singleton*.
%
%      H = MAGIC_NUMBER returns the handle to a new MAGIC_NUMBER or the handle to
%      the existing singleton*.
%
%      MAGIC_NUMBER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAGIC_NUMBER.M with the given input arguments.
%
%      MAGIC_NUMBER('Property','Value',...) creates a new MAGIC_NUMBER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before magic_number_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to magic_number_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
%
% Edit the above text to modify the response to help magic_number
%
% Last Modified by GUIDE v2.5 16-Oct-2006 17:15:27
%
% Begin initialization code - DO NOT EDIT
%
% Vihang Patil, Oct 2006
% Copyright 2006-2007 Vihang Patil
% Email: vihang_patil@yahoo.com
% Acknowlwdgement: Han Qun Email: junziyang@126.com for Splash.m



gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @magic_number_OpeningFcn, ...
                   'gui_OutputFcn',  @magic_number_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before magic_number is made visible.
function magic_number_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to magic_number (see VARARGIN)

splash('mindreader.jpg');%%Splash Window

axes(handles.axes1);
gifplayer;

n = 75; %this four lines of code, generates 21 unique random numbers
f = ceil(n.*rand(100,1));
[a b] = unique(f);
c = b(1:21);

for i = 1 : 21
    str = ['text' num2str(i)];
    set(handles.(str),'String',c(i));
end
handles.count = 1; %intial count
set(handles.your_magic_number,'Enable','Off');


   
% Choose default command line output for magic_number
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes magic_number wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = magic_number_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in column1.
function column1_Callback(hObject, eventdata, handles)
% hObject    handle to column1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

str2 = 1:3:19;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c1(i) = str2double(get(handles.(str),'String'));
end

str2 = 2:3:20;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c2(i) = str2double(get(handles.(str),'String'));
end

str2 = 3:3:21;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c3(i) = str2double(get(handles.(str),'String'));
end


handles.number = [handles.c2 handles.c1 handles.c3];
for i = 1 : 21
    str = ['text' num2str(i)];
    set(handles.(str),'String',handles.number(i));
end

set(handles.tiptool,'String','Select the column in which your number is currently');
handles.count = handles.count + 1;

if handles.count == 4
   set(handles.column1,'Enable','off');
   set(handles.column2,'Enable','off');
   set(handles.column3,'Enable','off');
   set(handles.tiptool,'String','Look Straight into the Crystal Ball,make a Wish and Press the Magic Button to reveal your Number');
   set(handles.your_magic_number,'Enable','On');
end

guidata(hObject, handles);


% --- Executes on button press in column2.
function column2_Callback(hObject, eventdata, handles)
% hObject    handle to column2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


str2 = 1:3:19;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c1(i) = str2double(get(handles.(str),'String'));
end

str2 = 2:3:20;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c2(i) = str2double(get(handles.(str),'String'));
end

str2 = 3:3:21;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c3(i) = str2double(get(handles.(str),'String'));
end

handles.number =  [handles.c1 handles.c2 handles.c3];
for i = 1 : 21
    str = ['text' num2str(i)];
    set(handles.(str),'String',handles.number(i));
end
set(handles.tiptool,'String','Select the column in which your number is currently');
handles.count = handles.count + 1;

if handles.count == 4
   set(handles.column1,'Enable','off');
   set(handles.column2,'Enable','off');
   set(handles.column3,'Enable','off');
   set(handles.tiptool,'String','Look Straight into the Crystal Ball,make a Wish and Press the Magic Button to reveal your Number');
   set(handles.your_magic_number,'Enable','On');
end

guidata(hObject, handles);

% --- Executes on button press in column3.
function column3_Callback(hObject, eventdata, handles)
% hObject    handle to column3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


str2 = 1:3:19;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c1(i) = str2double(get(handles.(str),'String'));
end

str2 = 2:3:20;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c2(i) = str2double(get(handles.(str),'String'));
end

str2 = 3:3:21;
for i = 1 : 7
    str = ['text' num2str(str2(i))];
    handles.c3(i) = str2double(get(handles.(str),'String'));
end

handles.number =  [handles.c1 handles.c3 handles.c2];
for i = 1 : 21
    str = ['text' num2str(i)];
    set(handles.(str),'String',handles.number(i));
end
set(handles.tiptool,'String','Select the column in which your number is currently');
handles.count = handles.count + 1;

if handles.count == 4
   set(handles.column1,'Enable','off');
   set(handles.column2,'Enable','off');
   set(handles.column3,'Enable','off');
   set(handles.tiptool,'String','Look Straight into the Crystal Ball,make a Wish and Press the Magic Button to reveal your Number');
   set(handles.your_magic_number,'Enable','On');
end

guidata(hObject, handles);




% --- Executes on button press in your_magic_number.
function your_magic_number_Callback(hObject, eventdata, handles)
% hObject    handle to your_magic_number (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

your_number = handles.number(11);
set(handles.magic_text,'String',num2str(your_number));
set(handles.tiptool,'String','Play Once again or Exit through File Menu');


function magic_text_Callback(hObject, eventdata, handles)
% hObject    handle to magic_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of magic_text as text
%        str2double(get(hObject,'String')) returns contents of magic_text as a double


% --- Executes during object creation, after setting all properties.
function magic_text_CreateFcn(hObject, eventdata, handles)
% hObject    handle to magic_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject    handle to file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function new_game_Callback(hObject, eventdata, handles)
% hObject    handle to new_game (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.tiptool,'String','Think of any one number from any of the 3 Columns, and select that column ,after 3 guesses, the computer will tell you the number in your mind!!');
set(handles.your_magic_number,'Enable','Off');
set(handles.column1,'Enable','on');
set(handles.column2,'Enable','on');
set(handles.column3,'Enable','on');

n = 75;
f = ceil(n.*rand(100,1));
[a b] = unique(f);
c = b(1:21);

for i = 1 : 21
    str = ['text' num2str(i)];
    set(handles.(str),'String',c(i));
end

handles.count = 1;
set(handles.magic_text,'String',[]);
guidata(hObject, handles);

% --------------------------------------------------------------------
function exit_Callback(hObject, eventdata, handles)
% hObject    handle to exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles=guihandles; 
d=timerfind;stop(d);delete(d);

closereq;



% --------------------------------------------------------------------
function show_splash_Callback(hObject, eventdata, handles)
% hObject    handle to show_splash (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
splash('mindreader.jpg');%%Splash Window



% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
handles=guihandles; 
d=timerfind;stop(d);delete(d);

delete(hObject);


Contact us at files@mathworks.com