Matlab - GUI

 
Vista:

GUI

Publicado por nataly (13 intervenciones) el 27/04/2013 23:51:05
hola debo hacer un juego que se llama picas y fijas en gui el juego consiste en un numero de cuatro cifras que da el programa pero no se ve , ya que el usuario debe adivinarlo ... las fijas son la cifras que estan exactamente en la misma posicion es decir si el programa da 2564 y el usuario pone 8562 el 5 y el 6 son 2 fijas .. y el 2 seria una pica ya que esta pero no esta en la misma posicion .. ya tengo lo mas complicado pero me falta definir las picas y las fijas en 2 funciones ....
gracias
esto es lo que tengo


function varargout = ejemplo1(varargin)
% EJEMPLO1 MATLAB code for ejemplo1.fig
% EJEMPLO1, by itself, creates a new EJEMPLO1 or raises the existing
% singleton*.
%
% H = EJEMPLO1 returns the handle to a new EJEMPLO1 or the handle to
% the existing singleton*.
%
% EJEMPLO1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EJEMPLO1.M with the given input arguments.
%
% EJEMPLO1('Property','Value',...) creates a new EJEMPLO1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ejemplo1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ejemplo1_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 ejemplo1

% Last Modified by GUIDE v2.5 25-Apr-2013 14:00:53

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ejemplo1_OpeningFcn, ...
'gui_OutputFcn', @ejemplo1_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 ejemplo1 is made visible.
function ejemplo1_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 ejemplo1 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);
global arr;
arr = unicos(4, 0, 9);
% UIWAIT makes ejemplo1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ejemplo1_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 bpf1.
function bpf1_Callback(hObject, eventdata, handles)
% hObject handle to bpf1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


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


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


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


function fuenteTamano_Callback(hObject, eventdata, handles)
% hObject handle to fuenteTamano (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
size = str2num(get(handles.fuenteTamano, 'String'));
set(handles.bpf1, 'FontSize', size);
set(handles.bpf2, 'FontSize', size);
set(handles.bpf3, 'FontSize', size);
set(handles.bpf4, 'FontSize', size);
% Hints: get(hObject,'String') returns contents of fuenteTamano as text
% str2double(get(hObject,'String')) returns contents of fuenteTamano as a double


% --- Executes during object creation, after setting all properties.
function fuenteTamano_CreateFcn(hObject, eventdata, handles)
% hObject handle to fuenteTamano (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


% --- Executes on button press in bjuego.
function bjuego_Callback(hObject, eventdata, handles)
% hObject handle to bjuego (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global arr;
usuario = get(handles.usuario, 'String');
if numel(usuario)<4
msgbox('Ingresar un valor de 4 digitos');
return;
end
if usuario==arr
msgbox('Acertado!');
return;
end
%set(handles.bpf1, 'String', arr(1));
%set(handles.bpf2, 'String', arr(2));
%set(handles.bpf3, 'String', arr(3));
%set(handles.bpf4, 'String', arr(4));



% --- Genera un vector de n enteros unicos (sin repetir) comprendidos
% --- entre v1 y v2
function a = unicos(n, v1, v2)
a = [];
for i=1:n
while 1
x = num2str(randi(v2-v1+1, 1)+v1-1);
if ~contiene(a, x);
a = [a x];
break;
end
end
end


% --- Determina si el vector a contiene o no al elemento x
function e = contiene(a, x)
e = 0;
for i=1:numel(a)
if a(i)==x;
e = 1;
break;
end
end


% --- Executes on button press in verNumeros.
function verNumeros_Callback(hObject, eventdata, handles)
% hObject handle to verNumeros (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
activo = get(handles.verNumeros, 'Value');
if activo
activo = 'on';
else
activo = 'off';
end
set(handles.bpf1, 'Visible', activo);
set(handles.bpf2, 'Visible', activo);
set(handles.bpf3, 'Visible', activo);
set(handles.bpf4, 'Visible', activo);
% Hint: get(hObject,'Value') returns toggle state of verNumeros


% --- Executes on key press with focus on verNumeros and none of its controls.
function verNumeros_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to verNumeros (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)



function usuario_Callback(hObject, eventdata, handles)
% hObject handle to usuario (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 usuario as text
% str2double(get(hObject,'String')) returns contents of usuario as a double


% --- Executes during object creation, after setting all properties.
function usuario_CreateFcn(hObject, eventdata, handles)
% hObject handle to usuario (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 w = fijas ....??
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Dave
Val: 497
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

GUI

Publicado por Dave (1094 intervenciones) el 30/04/2013 06:40:02
Hola Nataly;

En el siguiente link http://mygnet.net/codigos/c/juegos/picas_y_fijas.83, podrás encontrar el código fuente en C++ del juego que estas desarrollando, podrías tomarlo como referencia para implementarlo en Matlab.

Espero que sea de alguna ayuda, aprovecho en comentarte sobre mis servicios de programación en Matlab http://fismatlab.blogspot.com/

Saludos
Dave Correa
[email protected]
Servicios de Programación Matlab
http://fismatlab.blogspot.com/
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar