10 octubre 2006

Correcciones y pantalla modificada

Bueno aqui un breve cambio en la pantalla de sumatic y por lo que veo yo creo que habra mas cambios, estoy encontrando problemas en el arrastre, pero bueno aqui dejo parte del codigo y la nueva pantalla de sumatic.




Codigo


// ------------------------------------------ //
// Proyecto: Juego de sumas
// Desarrollador: gsur
// Licencia: GPL
// Blog: http:gsur.blogspot.com
// Email: rafamp78(dot)gmail.com
// ------------------------------------------
// mcs -pkg:gtk-sharp-2.0 -pkg:glade-sharp-2.0 -resource:vsumatic.glade Sumatic-0.1.cs
// mono Sumatic-0.1.exe



using System;
using Gtk;
using Gdk;
using GtkSharp;
using Glade;
class Sumatic
{
[Glade.Widget] Gtk.Window window;
[Glade.Widget] Gtk.HBox boxBotones;
[Glade.Widget] Gtk.Table tabla;
[Glade.Widget] Gtk.Button btNuevo;
[Glade.Widget] Gtk.Button btN1;
[Glade.Widget] Gtk.Button btN2;
[Glade.Widget] Gtk.Button btN3;
[Glade.Widget] Gtk.Button btN4;
[Glade.Widget] Gtk.Button btN5;
[Glade.Widget] Gtk.Button btN6;
[Glade.Widget] Gtk.Button btN7;
[Glade.Widget] Gtk.Button btN8;
[Glade.Widget] Gtk.Button btN9;
[Glade.Widget] Gtk.Button btN10;
[Glade.Widget] Gtk.Label lblN1;
[Glade.Widget] Gtk.Label lblN2;
[Glade.Widget] Gtk.Label lblN3;
[Glade.Widget] Gtk.Label lblN4;
[Glade.Widget] Gtk.Label lblN5;
[Glade.Widget] Gtk.Label lblN6;
[Glade.Widget] Gtk.Label lblN7;
[Glade.Widget] Gtk.Label lblN8;
[Glade.Widget] Gtk.Label lblN9;
[Glade.Widget] Gtk.Label lblN10;
int Nfila1, Nfila2, Nresultado;
static void Main()
{
Application.Init();
new Sumatic();
Application.Run();
}
public Sumatic()
{
Glade.XML gxml = new Glade.XML("vsumatic.glade", "window", null);
gxml.Autoconnect(this);
window.ShowAll();
btNuevo.Clicked += Nuevo_Juego;
TargetEntry [] te = new TargetEntry [] { new TargetEntry ("STRING", 0, 1), };
foreach(Gtk.Widget b in boxBotones)
{
Gtk.Drag.SourceSet (b, Gdk.ModifierType.Button1Mask, te, Gdk.DragAction.Copy);
b.DragDataGet += OnBtNDragGet;
}
foreach(Gtk.Widget lbl in tabla)
{
Gtk.Drag.DestSet (lbl, DestDefaults.All, te, DragAction.Copy);
lbl.DragDataReceived += OnlblNDropDragDataRecieved;
}
iniciar();
}
public void on_window_delete_event(object obj, DeleteEventArgs args)
{
Application.Quit();
}
public void on_btsalir_clicked(object obj, EventArgs args)
{
Application.Quit();
}
private void Nuevo_Juego(object obj, EventArgs args)
{
Random r = new Random();
Nfila1 = r.Next(100,999);
Nfila2 = r.Next(100,999);
Nresultado = Nfila1 + Nfila2;
string numeros = Nresultado.ToString();
if(numeros.Length < 4)
numeros += "?";
numeros += Nfila1.ToString() + Nfila2.ToString();
int i=0;
foreach(Gtk.Button b in boxBotones)
{
b.Label = numeros[i].ToString();
i+=1;
}
}
private void OnBtNDragGet(object o, DragDataGetArgs args)
{
Gtk.Button boton = (Gtk.Button) o;
Atom [] targets = args.Context.Targets;
args.SelectionData.Set(targets [0], 8, System.Text.Encoding.UTF8.GetBytes(boton.Label));
}
private void OnlblNDropDragDataRecieved(object o, DragDataReceivedArgs args)
{
Gtk.Widget source = Gtk.Drag.GetSourceWidget(args.Context);
Gtk.Button boton = (Gtk.Button) source;
Gtk.Label Contenedor = (Gtk.Label) o;
string strB = boton.Data["disponible"].ToString();
string strL = Contenedor.Data["vacio"].ToString();
if((strB.Equals("si") == true) && (strL.Equals("si") == true))
{
string data = System.Text.Encoding.UTF8.GetString ( args.SelectionData.Data );
Contenedor.Markup = "< background="\" foreground="\" size="\"> " + data + " < / span >";
boton.Data["disponible"] = "no";
Contenedor.Data["vacio"]="no";
boton.Label = "-";
//boton.Hide();
}
}
private void iniciar()
{
foreach(Gtk.Widget b in boxBotones)
{
b.Data["disponible"] = "si";
}
foreach(Gtk.Widget lbl in tabla)
{
lbl.Data["vacio"] = "si";
}
}
}


Pantalla

Ya solo falta la parte logica del juego, claro que si alguien quisiera aportar alguna mejora con gusto sera recibida, pero ahora hasta aqui dejo esto, ya es tarde y quiero ver mi programa en la tele.

No hay comentarios.: