Пример #1
0
func Play(pp []Piece, ctxt draw.Context) {
	display = ctxt
	screen = ctxt.Screen()
	screenr = draw.Rect(0, 0, screen.Width(), screen.Height())
	pieces = pp
	N = len(pieces[0].d)
	initPieces()
	rand.Seed(int32(time.Nanoseconds() % (1e9 - 1)))
	whitemask = draw.White.SetAlpha(0x7F)
	tsleep = 50
	timerc = time.Tick(int64(tsleep/2) * 1e6)
	suspc = make(chan bool)
	mousec = make(chan draw.Mouse)
	resizec = ctxt.ResizeChan()
	kbdc = make(chan int)
	go quitter(ctxt.QuitChan())
	go suspproc()
	points = 0
	redraw(false)
	play()
}
Пример #2
0
func app(inContext draw.Context)
{
    vl_screen := inContext.Screen();

    screenr := draw.Rect(0, 0, vl_screen.Width(), vl_screen.Height());
    draw.Draw(vl_screen, screenr, draw.White, nil, draw.ZP);

    squareSize := 30;

    var cell *SMazeCell = new(SMazeCell);
    cell.draw(inContext, squareSize);

    inContext.FlushImage();

    fmt.Printf("Press the any key to exit.\n");
    for
    {
        select
        {
            case r := <- inContext.KeyboardChan():
                switch r
                {
                    case 'q', 'Q', 0x04, 0x7F, 32 :
                        fmt.Printf("Exiting because of keyboard event %d\n", r);
                        os.Exit(0);
                    default :
                        fmt.Printf("Exiting because of keyboard event %d\n", r);
                }
            case <- inContext.MouseChan():
                // No-op.
            case <- inContext.ResizeChan():
                // No-op.
            case <- inContext.QuitChan():
                fmt.Printf("Exiting because of QuitChan\n");
                return;
        }
    }
}