2013年3月5日火曜日

爆弾探しゲーム

いわゆる「マインスイーパー」です。
bomb11.aiffも入れる必要があります。
/*****************************************************************
// 爆弾捜しゲーム
//    アイディアは違うけど、プログラムは
//    Copyright (C) 1993,2012 by AIG-SOFT
//        うわぁ、約20年ぶりに移植したのか!
/*****************************************************************
/* 定数 じゃなくて 変数

font("IPAGothic")
int fzenhan
int WX=64
int WY=width(WX,,fzenhan)
int xw=1:/* 全角1文字の桁数
if fzenhan then xw=2

/*****************************************************************

int MX =(WX/2)-2    :/* マップ最大横幅(-2は枠用)
int MY =19          :/* マップ最大縦幅
int MXX=5           :/* マップ最小横幅
int MYY=4           :/* マップ最小縦幅

int BOMB='*'        :/* 爆弾コード
int ERR=9           :/* 判定間違い
int BMBIT=bit(7)    :/* 爆弾在るはずビット
int CHBIT=bit(6)    :/* わかんないビット
int OPBIT=(BMBIT or CHBIT)    :/* オープン状態を示すビット
int NOPBIT=(not OPBIT)        :/* キャラクターのみを取り出すビット

/* 画面表示ホーム座標
int SX=2    :/* sx>=2 & sx+(MX+1)*2<画面x幅
int SY=4    :/* sy>=4 & sy+MY+1    <画面y幅

int ESC=&h1B
int CR =&h0d

/*****************************************************************
/* グローバル変数

dim char map( (64/2),19)    :/* (MX,MY)だけど変数だから使えない 現在マップ
dim char map0((64/2),19)    :/* (MX,MY) 表示用仮想画面

dim int    touchNo(10)      :// タッチエリア番号
int touchCnt    :// タッチエリア数

int wx,wy       :/* マップ幅
int seed,bomb   :/* 全爆弾数,爆弾ありそう数
int all         :/* 開けるべき全ますの数
int ts,dt       :/* 開始時間、経過時間

/*****************************************************************

int ret
int minbomb,maxbomb
/* フィールド幅、爆弾個数設定
str widthStr,heightStr,bombStr,defaultStr,messageStr
if isLocalizeJapan() then {
    widthStr ="横幅"
    heightStr="縦幅"
    minbomb=MXX*MYY/8 :/* 最小1/8
    maxbomb=wx*wy/2     :/* 最大1/2
    bombStr="爆弾数"
    defaultStr="標準"
    messageStr="メッセージ"
} else {
    widthStr ="width "
    heightStr="height"
    minbomb=MXX*MYY/8 :/* 最小1/8
    maxbomb=wx*wy/2     :/* 最大1/2
    bombStr="bombs"
    defaultStr="default"
    messageStr="message"
}
    print widthStr ;"(";MXX;"~";MX;")";
    dim str menues(3)={"10","20","30"}
    menues(3)=defaultStr
    wx=selectMenu(widthStr,menues):// selectMenu()の最終項目は特別
    if wx=3 then wx=2
    wx=(wx+1)*10
    print wx
//    input wx
    print heightStr;"(";MYY;"~";MY;")";
    menues={"5","10","15","19"}
    repeat
        wy=selectMenu2(heightStr,menues)
    until wy<>-1
    wy=5*(wy+1)
    print wy
//    input wy
    
    if wx<MXX then wx=MXX
    if wx>MX  then wx=MX
    if wy<MYY then wy=MYY
    if wy>MY  then wy=MY
    minbomb=MXX*MYY/8 :/* 最小1/8
    maxbomb=wx*wy/2     :/* 最大1/2
    print bombStr;"(";minbomb;"~";maxbomb")";
    menues={"50","100","150","200"}
    seed=selectMenuWithMessage(bombStr,messageStr,menues)
    seed=50*(seed+1)
    print seed
//    input seed
    if seed<minbomb then seed=minbomb
    if seed>maxbomb then seed=maxbomb

int sno=a_setPlayData("bomb11.aiff")
a_play(sno)

/* メインルーチン
repeat
    /* 乱数初期化
    srand2()
    
    /* 爆弾配置
    all=BombSeed(seed)
    bomb=0
    BombCount()
    dt=0:/* 経過時間
    
    /* 初期画面表示
    InitScreen()

    /* キー操作
    ret=CursorMove()
    
    /* 終わり判定
    if ret=-2 then break:/* 強制終了
    switch ret
        case -1:/* やり直し
            MapPrintAll(YES):/* 全表示
            break
        case 0: /* Game clear
            GameClear()
            break
        case 1: /* Game over
            MapPrintAll(YES):/* 全表示
            GameOver()
            break
    endswitch

    /* 再開処理
    locate(20,2)
    if isLocalizeJapan() then {
        print "《もう一度しますか?》";
        setFunctionKey(0,"はい"  ,CR)
        setFunctionKey(1,"いいえ",ESC)
    } else {
        print "<< Try Again ? >>";
        setFunctionKey(0,"YES",CR)
        setFunctionKey(1,"NO" ,ESC)
    }
    displayFunctionKey(YES,0,1)
    repeat
        ret=inkey()
    until ret<>0
    displayFunctionKey(NO,0,1)
    // タッチエリアの解除
    // 一旦解除してから再設定しないと重なり続ける
    resetTouchArea()
until (ret=ESC)
a_end(sno):// 音声バッファー解放
if isLocalizeJapan() then {
    print "終了"
} else {
    print "end"
}
end

/*****************************************************************
/* 関数群
/*****************************************************************

func int CursorMove()
/* カーソル移動&操作
int x,y,c
int t
    /* 初期座標
    /* 爆弾が無い座標に置く
    for x=0 to wx-1
        for y=0 to wy-1
            if ((map(x,y) and NOPBIT)<>BOMB) then goto "CM1"
        next
    next
label "CM1"
    ts=time():/* 開始時間
    while YES
        /* カーソル位置を反転表示
        c=map(x,y)
        tatrb(ATRB_REVERSE)
        locate2(x,y)
        print printChr$(c);
        tatrb(ATRB_NORMAL)
        
        // キー入力待ちしながら時計を回す
//        int cnt=0
        while (not kbhit())
            /* キー入力の無い間
            t=time()
            if t-ts>dt then { :/* 秒が変った
                dt=dt+1
                PrintTime(dt)
//                beep2(0)
//                print "cnt=";cnt
            }
//            inc(cnt)
        endwhile
        
        /* カーソル位置を普通表示
        locate2(x,y)
        print printChr$(c);
        //
        // キー操作判定
        c=inkey()
        beep2(0)    :// click sound
        switch c
            case &h1b: /* やり直し
                return(-1)
            
            /* カーソルは画面端でロールする
            case '2': /* ↓
                if y<wy-1 then y=y+1 else y=0
                break
            case '4': /* ←
                if x>0 then x=x-1 else x=wx-1
                break
            case '6': /* →
                if x<wx-1 then x=x+1 else x=0
                break
            case '8': /* ↑
                if y>0 then y=y-1 else y=wy-1
                break
            
            case '5': /* Check
                CheckMapPoint(x,y)
                MapPrint()
                /* チェックでは全開きにはならない
                break
            
            case ' ': /* Open
                if OpenMapPoint(x,y) then return(YES):/* game over
                /* 表示
                if MapPrint() then return(NO)
                break
        endswitch
    endwhile
    return (YES)
endfunc

/*****************************************************************

func int MapPrint()
/* マップを表示する&仮想画面変更
/* リターン値:0=まだ全ては開いていない , 1=全部開いた
int x,y,c
int all0=0
    for y=0 to wy-1
        for x=0 to wx-1
            c=map(x,y)
            if map0(x,y)<>c then {
                /* 画面に変更がある
                locate2(x,y)
                print printChr$(c)
                map0(x,y)=c:/* 仮想画面も変更
            }
            /* 開いているポイントを数える
            if ((c and OPBIT)=OPBIT) then all0=all0+1
        next
    next
    return(all0=all)
endfunc

/*****************************************************************

func MapPrintAll(mode;int)
/* マップ全表示
/* mode : 0=そのままで , 1=すべて開いて(間違い判定付き)
int x,y,c
str ls
    for y=0 to wy-1
        ls=""
        for x=0 to wx-1
            c=map(x,y)
            if mode then {
                if (c and OPBIT)=BMBIT then {
                    /* 爆弾ありとしているが・・
                    /* そこに爆弾がなければ間違い
                    if (c and NOPBIT)<>BOMB then c=ERR
                }
                c=(c or OPBIT):/* 開く
            }
            ls=ls+printChr$(c)
        next
        locate2(0,y)
        print ls
    next
    // color(7)
endfunc

/*****************************************************************

func str printChr$(c;int)
/* キャラクター表示
/* c : bit6,7 = 開き済み(11)/チェックマーク(10)/爆弾マーク(01)/閉じている(00)
/*     bit0-5 = マップ状態 &h00~&h3f
str cs
    int cc=(c and OPBIT)
    if cc=0 then {
        /* 閉じている
        return ("□")
    }
    if cc=CHBIT then {
        /* CHBIT チェックマーキング中
        return ("?")
    }
    if cc=BMBIT then {
        /* 爆弾ありマーキング中
        return ("☆")
    }
    if cc=OPBIT then {
        /* 開いている
        switch (c and NOPBIT)
            case  0:cs= "・":break
            case  1:cs= "1":break
            case  2:cs= "2":break
            case  3:cs= "3":break
            case  4:cs= "4":break
            case  5:cs= "5":break
            case  6:cs= "6":break
            case  7:cs= "7":break
            case  8:cs= "8":break
            case  9:/* 間違い
                cs= "×"
                break
            case '*':/* 爆弾
                cs= "★"
                break
        endswitch
    }
    return (cs)
endfunc

/*****************************************************************

func locate2(x;int,y;int)
    locate(SX+(x)*xw,SY+y)    :/* *xw for 全角文字
endfunc

/*****************************************************************

func WakuPrint(yoko;str,tate;str,kado;str,fall;int)
/* マップ枠表示
int i
    /* 横線
    str yokos=""
    for i=0 to wx-1:yokos=yokos+yoko:next
    locate2(0,-1):print yokos
    locate2(0,wy):print yokos

    /* 縦線
    if fall then {
        // 内側も消す=速い
        str tates=tate+space$(wx*xw)+tate
        for i=0 to wy-1
            locate2(-1,i):print tates;
        next
    } else {
        // 枠だけ=遅い
        for i=0 to wy-1
            locate2(-1,i):print tate;
            locate2(wx,i):print tate;
        next
    }
    
    /* 角
    locate2(-1,-1):print kado;
    locate2(-1,wy):print kado;
    locate2(wx,-1):print kado;
    locate2(wx,wy):print kado;
endfunc

/*****************************************************************

func InitScreen()
/* 初期画面表示
    cls()
    WakuPrint("-","|","+",YES)
    MapPrintAll(NO)
    locate(5,0)
    if isLocalizeJapan() then {
        print using "マップ幅:##×##  爆弾数:###/###  時間:#####";wx,wy,bomb,seed,dt
            /*         0         1           2         3          4    
            /*        +0123456789012345678901234567890123456789012    
            /*        +locate
    } else {
        print using "map size:##×##  bombs :###/###  time:#####";wx,wy,bomb,seed,dt
    }
    str open$,exit$
    if isLocalizeJapan() then {
        open$="開く"
        exit$="中断"
    } else {
        open$="open"
        exit$="exit"
    }
    int x=WX/2-18
    int y=SY+wy+2
                    //     012345678901234567890123456789
    locate(x,y+0):print "      ┏━┓"
    locate(x,y+1):print "      ┃↑┃"
    locate(x,y+2):print "      ┗━┛"
    locate(x,y+3):print "┏━┓┏━┓┏━┓    ┏━━┓"
    locate(x,y+4):print "┃←┃┃?┃┃→┃    ┃";open$;"┃"
    locate(x,y+5):print "┗━┛┗━┛┗━┛    ┗━━┛"
    locate(x,y+6):print "      ┏━┓"
    locate(x,y+7):print "      ┃↓┃"
    locate(x,y+8):print "      ┗━┛"
    
    int i=0
    touchNo(inc(i))=setTouchAreaWithText(x+ 6,y  ,xw*3,3,'8',YES,125,0,5,100)
    touchNo(inc(i))=setTouchAreaWithText(x+ 6,y+6,xw*3,3,'2',YES,125,0,5,100)
    touchNo(inc(i))=setTouchAreaWithText(x   ,y+3,xw*3,3,'4',YES,125,0,5,100)
    touchNo(inc(i))=setTouchAreaWithText(x+12,y+3,xw*3,3,'6',YES,125,0,5,100)
    //
    touchNo(inc(i))=setTouchAreaWithText(x+ 6,y+3,xw*3,3,'5',YES,150,50, 5,120):/* check
    touchNo(inc(i))=setTouchAreaWithText(x+22,y+3,xw*4,3,' ',YES,150, 5 ,5,120):/* open
    touchCnt=i
    //
    setFunctionKey(0,exit$,ESC)
    displayFunctionKey(YES,0,0)
endfunc

func resetTouchArea()
// タッチエリアの解除
int i
    for i=0 to touchCnt
        removeTouchArea(touchNo(i))
    next
    touchCnt=0
endfunc

/*****************************************************************

func PrintBombCount()
/* 残り爆弾数表示
    locate(5+26,0)
    print using "###";bomb
endfunc

/*****************************************************************

func PrintTime(dt;int)
/* 経過時間表示
    locate(5+42,0)
    print using "#####";dt
endfunc

/*****************************************************************

func GameClear()
/* ゲームクリア時画面表示
    /* 枠の模様を代える
    beep()
    WakuPrint("◇","◇","◇",NO)
    beep()
    locate(6,1)
    if isLocalizeJapan() then {
        print "§§ おめでとう! あなたは総ての爆弾を捜し当てました §§";
    } else {
        print "<< Congratulations! You've turned up the bomb of all >>";
    }
endfunc

/*****************************************************************

func GameOver()
/* ゲームオーバー時画面表示
    /* 枠の模様を代える
    a_play(sno)
    WakuPrint("☆","☆","☆",NO)
    a_play(sno)
    locate(10,1)
    if isLocalizeJapan() then {
        print "@@ あなたは爆弾にぶち当たってしまいました @@";
    } else {
        print "@@ You've hit a bomb @@";
    }
endfunc

/*****************************************************************

func CheckMapPoint(x;int,y;int)
/* マップ上のポイントをチェックする
int c
    c=map(x,y)
    c=(c and OPBIT)
    if c=OPBIT then {
        /* すでに開いている
        /* 開いている所を調べることは不用
        beep()
        return()
    }
    if c=0 then {
        /* 閉じている -> 爆弾ありそう
        map(x,y)=(BMBIT or map(x,y))
        bomb=bomb+1
        PrintBombCount()
        return()
    }
    if c=BMBIT then {
        /* 爆弾ありそう -> チェックしてね
        map(x,y)=(c and NOPBIT)or CHBIT
        return()
    }
    if c=CHBIT then {
        /* チェックしてね -> 閉じる
        map(x,y)=(NOPBIT and map(x,y))
        bomb=bomb-1
        PrintBombCount()
    }
endfunc

/*****************************************************************

func int OpenMapPoint(x;int,y;int)
/* マップ上のポイントを開く
int c
    c=map(x,y)
    if ((c and OPBIT)=OPBIT) then {
        /* すでに開いている
        /* 開いているところを再度開くことは不用
        beep()
        return(NO):/* 警告以外は何もしない
    }
    if ((c and NOPBIT)=BOMB) then {
        /* 爆弾を開けてしまった
        a_play(sno)
        return(YES):/* game over
    }
    /* そこはまだ開いていない所なので開ける
    if (c=0) then {
        /* 周りに爆弾がない所ならペイント型で開く
        PaintMap(x,y)
    } else {
        /* 周りに1つでも爆弾がある時は1ポイントだけ開ける
        map(x,y)=(OPBIT or map(x,y)):/* 開けた印
    }
    return(NO)
endfunc

/*****************************************************************

func PaintMap(x;int,y;int)
/* マップの(x,y)から0の点を開く
/* 基本的にはペイントと同じルーチンになるが、境界まで開くのが違う
int c,xs,xe
    if map(x,y)<>0 then {
        /* 最初の点が0でなければ終わり
        return()
    }
    /* 0 <- x : 左サーチ
    xe=x+1 :/* 右へ捜し始めるポイント
    while x>=0
        c=map(x,y)
        if ((c and OPBIT)=0) then {
            map(x,y)=(OPBIT or map(x,y))
        }
        if (c<>0) then break:/* 境界
        /* 境界も開かれる
        //    境界は爆弾ではない。/ border is not bomb
        //    なぜなら爆弾の周りには1~8が必ずあるから。
        x=x-1:/* 左へ
    endwhile
    if x<0 then xs=0 else xs=x
    /* xs=線分左端(境界も含む)

    /* x -> wx-1 : 右サーチ
    while xe<=wx-1
        c=map(xe,y)
        if (c and OPBIT)=0 then map(xe,y)=(OPBIT or map(xe,y))
        if c<>0 then break:/* 境界
        xe=xe+1 :/* 右へ
    endwhile
    if xe=wx then xe=xe-1
    /* xe=線分右端(境界を含む)
    if y>0    then PaintMapSub(xs,xe,y-1):/* 上チェック
    if y<wy-1 then PaintMapSub(xs,xe,y+1):/* 下チェック
endfunc

/*****************************************************************

func PaintMapSub(xs;int,xe;int,yy;int)
/* PaintMap()サブルーチン:上下チェック用
int x,c
    for x=xs to xe
        c=map(x,yy)
        if c=0 then {
            PaintMap(x,yy)
        } else {
            if (c and OPBIT)=0 then map(x,yy)=(OPBIT or map(x,yy)):/* 境界も開く
        }
    next
endfunc

/*****************************************************************

func int BombSeed(seeds;int)
/* マップ内に爆弾をまく
/* seeds : 爆弾個数 < wx*wyにすること
/* 乱数の初期化は外部で行なうこと
int x,y
int all
    /* マップクリア
    for y=0 to wy-1
        for x=0 to wx-1
            map(x,y)=0
        next
    next
    
    /* 要開き数:爆弾以外すべて
    all=wx*wy-seeds
    
    /* 爆弾配置
    while seeds>0
        x=rand2(wx)
        y=rand2(wy)
        if map(x,y)=0 then {
            /* 爆弾を置く
             map(x,y)=BOMB:/* マップ
            map0(x,y)=BOMB:/* 仮想画面
            seeds=seeds-1 :/* 残りを1つ減らす
        }:/* そこにすでに爆弾がある時は別の場所を探す
    endwhile
    
    return(all)
endfunc

/*****************************************************************

func BombCount()
/* マップ内の爆弾状況を書き込む
/* 各ポイント毎の周りの爆弾の数をあらかじめ書き込む
int x,y,xx,yy,xs,ys,xe,ye,c
    for y=0 to wy-1
        ys=y-1:if ys<0    then ys=0
        ye=y+1:if ye>wy-1 then ye=wy-1
        for x=0 to wx-1
            if map(x,y)=BOMB then continue:/* 爆弾の所はスキップ
            xs=x-1:if xs<0    then xs=0
            xe=x+1:if xe>wx-1 then xe=wx-1
            /* 周りをカウント
            c=0
            for yy=ys to ye
                for xx=xs to xe
                    if map(xx,yy)=BOMB then c=c+1
                next
            next
            /* c=0~8
             map(x,y)=c:/* マップ
            map0(x,y)=c:/* 仮想画面
        next
    next
endfunc

/*****************************************************************
/* 汎用関数
/*****************************************************************

func srand2()
/* rand()乱数を初期化する
int tm=time()
    tm=tm and &h0fff
    tm=tm * 16
    srand(tm)
endfunc

func rand2(seed;int)
    return (rand() mod seed):/* 0~seed-1の乱数を発生
endfunc

/*****************************************************************
音声ファイル入り圧縮ファイル: XBbs.zip

2013年3月4日月曜日

SHIFT-JIS文字ほぼ全一覧表示(SHIFT-JIS版)

X68000がサポートしていたSHIFT-JIS文字ほぼ全てを一覧表示します。
こちらは内部処理が全てSHIFT-JISですが、正常に動きます。
強制SHIFT-JISモードをオンに設定して実行してください。
// SHIFT-JIS版(強制SJISモード)
/* SHIFT-JIS 全文字コード表示プログラム 
// テキスト画面がスクロールできないのでページ切り替え
    font("Migu 1M")
    int fzenhan:// YES=
    width(64,,fzenhan)
    print "fzenhan=";fzenhan
    cls()
    
    if isLocalizeJapan() then {
        setFunctionKey(0,"次へ",&h0d)
        setFunctionKey(1,"中断",&h1b)
        print "半角文字"
    } else {
        setFunctionKey(0,"Next",&h0d)
        setFunctionKey(1,"Break",&h1b)
        print "Half-Width Character"
    }
    print_code0(fzenhan)
    //
    displayFunctionKey(YES,0,1)
    //
    while YES
        if print_code(&h8100,&h9fff) then break
        if print_code(&he000,&hefff) then break
        print_head()
        break
    endwhile
    //
    // ファンクションキー表示は個数を変えても自動的に前の表示は消えないので、ユーザーが消す必要がある(そうしないと表示が重なる)
    displayFunctionKey(NO,0,1)
    if isLocalizeJapan() then {
        setFunctionKey(0,"終了",&h0d)
    } else {
        setFunctionKey(0,"End",&h0d)
    }
    displayFunctionKey(YES,0,0)
    int ky
    repeat
        ky=inkey()
    until ky<>0
end

//--------------------------------

func print_head()
    if fzenhan then {
        print "-code-:-+0-+1-+2-+3-+4-+5-+6-+7-+8-+9-+A-+B-+C-+D-+E-+F-"
    } else {
        print "-code-:-0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F-"
    }
endfunc

func print_skip()
    print "      :                                                "
endfunc

func str hex4$(h;int)
    return (right$("0000"+hex$(h),4))
endfunc

func str hex2$(h;int)
    return (right$("00"+hex$(h),2))
endfunc

func printChr(h;int,l;int)
    print chr$((h shl 16)or l);
endfunc

func int print_code(st;int,ed;int)
/* 全角文字表示 
int i,li,hi
int j
    for i=st to ed
        hi=i / 256
        li=i mod 256
        if li=0 then {
            print_head()
            int ky
            repeat
                ky=inkey()
            until ky<>0
            if ky=&h1b then return (YES)
            cls()
            if isLocalizeJapan() then {
                print "全角文字"
            } else {
                print "Double-Width character"
            }
            print_head()
        }
        if li<&h40 then continue:/* 下位8ビットが<$40の文字はない 
        
        /* アドレス表示 
        print " ";hex4$(i);" :";
        for j=0 to 16-1
            print " ";
            int c=(i+j) and &hff
            if c<&h40 or c=&h7f or c>=&hfd then { :/* 未定義文字 
                if fzenhan then {
                    print "**";
                } else {
                    print "*";
                }
            } else {
                c=(i+j)
                print chr$(c);    :/* 途中で桁上がりを起こさないことを前提にした処理 
            }
        next
        print
        i=i+16-1:/* 次のnext +1されるから
    next
    return (NO)
endfunc

func print_code0(fzenhan;int)
/* 半角文字表示 
int li
int j,c
    print_head()
    for li=&h20 to &he0-1
        /* 途中表示しないエリア 
        if li=&h80 then print_skip()
        if li>=&h80 and li<=&h9f then continue
        
        /* アドレス表示 
        print "  ";hex2$(li);"  :";
        /* 文字表示
        for j=0 to 16-1
            print " ";
            c=li+j
            if c=&h7f or c=&ha0 then c='*'
            print chr$(c);
            if fzenhan then print " ";:/* 全角=半角*2のフォントの時は後ろにスペースを入れる
        next
        print
        li=li+16-1:/* 次のnext +1されるから
    next
endfunc

Zipファイル :XBetc.zip

2013年3月1日金曜日

モーション関数テスト

モーション関数のテストプログラムです。 本体を傾けるとその情報を表示します。
//----------------------------------------------------------------------------------------------
// motion test
//----------------------------------------------------------------------------------------------

print "versionXBiOSMotion$=";versionXBiOSMotion$()

setFunctionKey(0,"end"   ,'!')
setFunctionKey(1,"pause" ,'p')
setFunctionKey(2,"start" ,'s')
setFunctionKey(3,"clear" ,'c')
setFunctionKey(4,"degree",'d')
setFunctionKey(5,"veloc" ,'v')
setFunctionKey(6,"rotate",'r')
displayFunctionKey(YES,0,6)
kBackgroundAlpha(0.9)

int mode=MOTION_DEGREE
if motionStart(10,mode) then {
    print localizedString("モーションは使えません","Can't use motion.")
    end
}
printMode(mode)

float x,y,z
int ky,cnt,i

while YES
    if not kbhit() then {
        i=0
        cnt=motionCount()
        if cnt>0 then locate(0,1):print "cnt=";cnt
        while cnt>0
            x=motionGetRotation(y,z)
            locate(0,2+i)
            if mode=MOTION_ROTATION then {
                if isLocalizeJapan() then {
                    print using "左右=+#.####,上下=+#.####,方位=+#.####";x,y,z
                } else {
                    print using "pitch=+#.####,roll=+#.####,yaw=+#.####";x,y,z
                }
            } else {
                if mode=MOTION_DEGREE then {
                    if isLocalizeJapan() then {
                        print using "角度:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    } else {
                        print using "degree:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    }
                } else {
                    if isLocalizeJapan() then {
                        print using "角速度:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    } else {
                        print using "velocity:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    }
                }
            }
            cnt=cnt-1
            i=i+1
            if kbhit() then break
        endwhile
    } else {
        ky=inkey()
        switch ky
            case 'p'
                motionPause(YES)
                print "Pause"
                break
            case 's'
                motionPause(NO)
                print "Start"
                break
            case 'c'
                cls()
                motionClear()
                break
            case 'd'
                mode=MOTION_DEGREE
                motionSelectData(mode)
                cls()
                motionClear()
                printMode(mode)
                break
            case 'v'
                mode=MOTION_VELOCITY
                motionSelectData(mode)
                cls()
                motionClear()
                printMode(mode)
                break
            case 'r'
                mode=MOTION_ROTATION
                motionSelectData(mode)
                cls()
                motionClear()
                printMode(mode)
                break
            default:
                // 念のため / just in case
                beep()
                break
        endswitch
        if ky='!' then break
    }
endwhile
motionEnd()
end

//----------------------------------------------------------------------------------------------

func printMode(mode;int)
    locate(0,2)
    if mode=MOTION_DEGREE   then print localizedString("角度     ","DEGREE  ")
    if mode=MOTION_VELOCITY then print localizedString("角速度   ","VEROCITY")
    if mode=MOTION_ROTATION then print localizedString("オイラー角","EULER   ")
endfunc

func str localizedString(js;str,es;str)
    if isLocalizeJapan() then return(js)
    return (es)
endfunc

//----------------------------------------------------------------------------------------------

Zipファイル :XBtests.zip

2013年2月28日木曜日

SHIFT-JIS文字ほぼ全一覧表示(UTF8版)

X68000がサポートしていたSHIFT-JIS文字ほぼ全てを一覧表示します。
算術で作り出したSHIFT-JISコードを表示時にUTF8に変換しています。
強制SHIFT-JISモードをオフに設定して実行してください。
// UTF8版
/* SHIFT-JIS 全文字コード表示プログラム 
// テキスト画面がスクロールできないのでページ切り替え
    font("Migu 1M")
    int fzenhan:// YES=
    width(64,,fzenhan)
    print "fzenhan=";fzenhan
    cls()
    
    if isLocalizeJapan() then {
        setFunctionKey(0,"次へ",&h0d)
        setFunctionKey(1,"中断",&h1b)
        print "半角文字"
    } else {
        setFunctionKey(0,"Next",&h0d)
        setFunctionKey(1,"Break",&h1b)
        print "Half-Width Character"
    }
    print_code0(fzenhan)
    //
    displayFunctionKey(YES,0,1)
    //
    while YES
        if print_code(&h8100,&h9fff) then break
        if print_code(&he000,&hefff) then break
        print_head()
        break
    endwhile
    //
    // ファンクションキー表示は個数を変えても自動的に前の表示は消えないので、
    // ユーザーが消す必要がある(そうしないと表示が重なる)
    displayFunctionKey(NO,0,1)
    if isLocalizeJapan() then {
        setFunctionKey(0,"終了",&h0d)
    } else {
        setFunctionKey(0,"End",&h0d)
    }
    displayFunctionKey(YES,0,0)
    int ky
    repeat
        ky=inkey()
    until ky<>0
end

//--------------------------------

func print_head()
    if fzenhan then {
        print "-code-:-+0-+1-+2-+3-+4-+5-+6-+7-+8-+9-+A-+B-+C-+D-+E-+F-"
    } else {
        print "-code-:-0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F-"
    }
endfunc

func print_skip()
    print "      :                                                "
endfunc

func str hex4$(h;int)
    return (right$("0000"+hex$(h),4))
endfunc

func str hex2$(h;int)
    return (right$("00"+hex$(h),2))
endfunc

func printChr(h;int,l;int)
    print chr$((h shl 16)or l);
endfunc

func int print_code(st;int,ed;int)
/* 全角文字表示 
int i,li,hi
int j
    for i=st to ed
        hi=i / 256
        li=i mod 256
        if li=0 then {
            print_head()
            int ky
            int ts=time()
            int dt=0,t
            repeat
                ky=inkey()
                t=time()
                if t-ts>dt then { :/* 秒が変った
                    dt=dt+1
                    locate(40,0):print dt
                    beep2(0)
                }
            until ky<>0
            if ky=&h1b then return (YES)
            cls()
            if isLocalizeJapan() then {
                print "全角文字"
            } else {
                print "Double-Width character"
            }
            print_head()
        }
        if li<&h40 then continue:/* 下位8ビットが<$40の文字はない 
        
        /* アドレス表示 
        print " ";hex4$(i);" :";
        for j=0 to 16-1
            print " ";
            int c=(i+j) and &hff
            if c<&h40 or c=&h7f or c>=&hfd then { /* 未定義文字 
                if fzenhan then {
                    print "**";
                } else {
                    print "*";
                }
            } else {
                c=sjisToUtf8(i+j)
                print chr$(c);    /* 途中で桁上がりを起こさないことを前提にした処理 
            }
        next
        print
        i=i+16-1:/* 次のnext +1されるから
    next
    return (NO)
endfunc

func print_code0(fzenhan;int)
/* 半角文字表示 
int li
int j,c
    print_head()
    for li=&h20 to &he0-1
        /* 途中表示しないエリア 
        if li=&h80 then print_skip()
        if li>=&h80 and li<=&h9f then continue
        
        /* アドレス表示 
        print "  ";hex2$(li);"  :";
        /* 文字表示
        for j=0 to 16-1
            print " ";
            c=li+j
            if c=&h7f or c=&ha0 then c='*' else c=sjisToUtf8(c)
            print chr$(c);
            if fzenhan then print " ";:/* 全角=半角*2のフォントの時は後ろにスペースを入れる
        next
        print
        li=li+16-1:/* 次のnext +1されるから
    next
endfunc

Zipファイル :XBetc.zip

2013年2月27日水曜日

ビンゴゲーム

いわゆるビンゴゲーム。コンピューターと対戦します。
多くのタッチエリアを設定しています。
画面表示の関係上、iPadの縦画面専用です。
//--------------------------------------------------------------------------------
/* BINGO
// for X-BASIC for iOS v2.0
//--------------------------------------------------------------------------------

if deviceType()<>DEVICE_IPAD and deviceType()<>DEVICE_IPAD_SIMULATOR then {
    print localizedString("このプログラムはiPad専用です","This program only for iPad.")
    end
}
dim int A(5,11),B(12,2)
dim int keyAreaNo(5,5)
int d,L,T,E,F
int WX,WY
int sx,sy,ex,ey
int OPEND=100:// 定数
/*
srand2()
width(64)
getWidth(WX,WY)
setUpScroll(NO):// テキスト画面の上スクロールを止める (V2.0)
apage(GPAGE0)
vpage(B_TPAGE or B_GPAGE0 or B_GPAGE1,YES)
//display_title()

d=0
dim str menues(1)
str title
int e
repeat
    cls()
    apage(GPAGE1):wipe()
    apage(GPAGE0):wipe()
    gcolor(-TWHITE,0,0,255)
    symbol(128,2,"BINGO GAME","IPAGothic",48)
    gcolor(-THWHITE,0,0,255)
    symbol(129,3,"BINGO GAME","IPAGothic",48)
    gcolor(-THRED,0,0,255)
    box(13,64,748,614)
    tcolor(-THWHITE,0,0,255)
    shuffle():// 数字の設定
    field_print():// 数字表示&タッチエリア設定
    print_number(NO)
    /*
    if isLocalizeJapan() then {
        menues={"先手","後手"}
        title="順番選択"
    } else {
        menues={"First move","Passive move"}
        title="Moving order"
    }
    repeat
        L=selectMenu2(title,menues):// -1,0,1
    until L>=0:// -1=BREAK/outside menu touch
    L=L+1:// 0,1->1,2

    sub_cls()
    /*
    for e=0 to 12
        B(e,0)=0
        B(e,1)=0
        B(e,2)=0
    next
    E=0:F=0:T=0
    repeat
        T=T+1
        tcolor(-THWHITE,0,0,255)
        locate(6,17)
        if isLocalizeJapan() then {
            print"第";T;"手"
        } else {
            print"The";T;" hand"
        }
        repeat
            switch L
                case 1:
                    locate(11,19)
                    print localizedString("あなた:","You : ");
                    d=input_num()
                    L=2
                    break
                case 2:
                    locate(38,19)
                    print localizedString("コンピューター:","Computer : ");
                    d=com_num()
                    //beep()
                    L=1
                    break
            endswitch
            int cx=pos()
            int cy=csrlin()
            int ffind=check_num(d)
            if not ffind then {
                // 見つからなかった
                // 人間側のみありえる
                L=1
                beep()
                // 選択しなおし
            }
        until ffind
        locate(cx,cy):print d
    until (F>=5) or (E>=5)
    resetALlKeys():// タッチエリアの解除
    sub_cls()
    print_number(YES)
    hantei(E,F)
    locate(11,24)
    if isLocalizeJapan() then {
        print "御苦労さまでした"
        menues={"はい","いいえ"}
        title="もう一度しますか?"
    } else {
        print "Cheers for hard work was."
        menues={"YES","NO"}
        title="Try again ?"
    }
    L=selectMenu2(title,menues):// -1=stop,0=YES,1=NO
until L=1 or L=-1
end

//--------------------------------------------------------------------------------
// functions
//--------------------------------------------------------------------------------

func hantei(E;int,F;int)
/* 勝ち負け判定
    tcolor(-THYELLOW,0,0,255)
    locate(10,23)
    if isLocalizeJapan() then {
        print E;" 対";F;"で ";
    }
    if F<E then {
           print localizedString("あなたの勝ち","You win");
    } else {
        if E<F then {
            print localizedString("コンピューターの勝ち","Computer win");
        } else {
            print localizedString("引き分け","Draw");
        }
    }
    if not isLocalizeJapan() then {
        print " in the";E;"-for-";F
    }
endfunc
/*
func int input_num()
/* 人間の数字選択
int num
//    kbclr()
    // キー入力待ち
    while not kbhit()
    endwhile
    // エリアをタッチすると、数字がキーコードとして返ってくる
    num=inkey()
    return(num)
endfunc
/*
func int check_num(d;int)
/* 番号チェック&マスオープン
int h,x,y,ac,bb,i,j
    for h=1 to 2:// 両方を調べる
        // 数字からマス座標を得る
        int ffind=NO
        for i=1 to 5
            for j=1 to 5
                ac=A(i,j+(h-1)*6)
                if ac=d then {
                    x=i:y=j
                    ffind=YES
                    break
                }
            next
            if ffind then break
        next
        if not ffind then {
            // 見つからない
            locate(0,5):print "見つからない"
            return (NO)
        }
        //
        apage(GPAGE1)
        switch h
            case 1:gcolor(-THMAGENTA,0,0,200):break
            case 2:gcolor(-THGREEN  ,0,0,200):break
        endswitch
        calc_grid_gxy(x,y,h-1):// ->sx,sy,ex,ey
        fill(sx,sy,ex,ey)
        apage(GPAGE0)
        //
        A(x,y+(h-1)*6)=ac+OPEND:/* 開いたの印
        bb=0
        if x=y   then bb=B(12,h):B(12,h)=bb+1
        if x=6-y then bb=B(11,h):B(11,h)=bb+1
        bb=B(x,h)  :B(x  ,h)=bb+1
        bb=B(y+5,h):B(y+5,h)=bb+1
        x=0
        for i=1 to 12
            x=x+B(i,h)\5
        next
        if (h=1) and (E<x) then {
            locate(11,15)
            if isLocalizeJapan() then {
                print "あなた:";x;"列"
            } else {
                print "You :";x;" lines"
            }
            E=x
            beep2(7)
        } else {
            if (h=2)*(F<x) then {
                locate(38,15)
                if isLocalizeJapan() then {
                    print "コンピューター:";x;"列"
                } else {
                    print "Computer :";x;" lines"
                }
                F=x
                beep2(8)
            }
        }
    next
    // 見つかって処理した
    return (YES)
endfunc
/*
func int com_num()
/* コンピューターの番号考え
int i,j,m,bb,c
    m=0
    for i=1 to 5
        for j=1 to 5
            bb=0
            if A(i,j+6)<OPEND then {
                if i=j   then bb=   1+B(12,2)
                if i=6-j then bb=bb+1+B(11,2)
                bb=bb+2+B(i,2)+B(j+5,2)
                if bb>m then c=A(i,j+6):m=bb
            }
        next
    next
//    locate(0,26):print "com=";c
    return(c)
endfunc
/*
func sub_cls()
/* 画面一部クリア
    int y
    for y=16 to WY
        locate(0,y):print space$(WX);
    next
endfunc
/*
func shuffle()
/* マス内数字シャッフル
int i,j,l,h
int c,x,y
    for l=0 to 1:/* l=0:あなた , 1=コンピューター
        /* まずはマス内に順番に数字を入れる
        /* A(i,j) : j=1〜5:あなた , 6〜11:コンピューター
        h=0
        for i=1 to 5
            for j=1 to 5
                h=h+1
                A(i,j+l*6)=h
            next
        next
        /* マスを入れ替える
        for i=1 to 5
            for j=1 to 5
                x=rand() mod 5+1
                y=rand() mod 5+1+l*6
                c=A(i,j+l*6)
                A(i,j+l*6)=A(x,y)
                A(x,y)=c
            next
        next
    next
endfunc
/*
func print_number(mode;int)
/* マス内番号表示
// mode : NO=人側のみ開く , YES=コンピューター側を開く
int i,j,c
int x,y
    tcolor(-THWHITE,0,0,255)
    for i=1 to 5
        x=(i-1)*5
        for j=1 to 5
            y=j*2+2
            if not mode then {
                // 人側(Human)のみ開く
                c=A(i,j)
                if c>OPEND then c=c-OPEND:/* すでに開いているマスの時
                locate(x+ 7,y):print using "##";c
                locate(x+36,y):print "??"
            } else {
                // コンピューター側(Computer)を開く
                c=A(i,j+6)
                if c>OPEND then c=c-OPEND:/* すでに開いているマスの時
                locate(x+36,y):print using "##";c
            }
        next
    next
endfunc
/*
func field_print()
/* フィールド描画
// 先にshuffle()で数字を確定しておくこと
int l,i,j
    for l=0 to 1:/* l=0:あなた , 1=コンピューター
        if l=0 then {
            tcolor(-THCYAN,0,0,255)
            locate(11,14)
            print localizedString("あなたのマス目","Your grid")
        } else {
            tcolor(-THYELLOW,0,0,255)
            locate(36,14)
            print localizedString("コンピューターのマス目","  Computer grid  ")
        }
        // ます線描画
        gcolor(-THMAGENTA,0,0,255)
        for i=1 to 5
            for j=1 to 5
                calc_grid_gxy(i,j,l):// ->sx,sy,ex,ey
                box(sx,sy,ex,ey)
                if l=0 then {
                    // タッチエリアの設定
                    // 人間側のみ
                    // キーコードに数字を入れておく
                    keyAreaNo(i,j)=setTouchArea(sx,sy,(ex-sx),(ey-sy),A(i,j),YES)
                    // save touch area No into keyAreaNo()
                }
            next
        next
    next
    tcolor(-THWHITE,0,0,255)
endfunc
/*
func resetALlKeys()
// 全タッチアリアの解除(重要)
    int i,j
    for i=1 to 5
          for j=1 to 5
            removeTouchArea(keyAreaNo(i,j))
        next
    next
endfunc
/*
func calc_grid_gxy(i;int,j;int,l;int)
// マス目座標からグラフィック表示座標を得る
int x,y
    x=textX2Gx((i-1)*5+7)+l*340
    y=textY2Gy(j*2+2)
    // 以下リターン値(グローバル変数)
    ex=textX2Gx((i-1+1)*5+7)+l*340-12
    ey=textY2Gy((j+1)*2+2)-12
    sx=x-12
    sy=y-12
endfunc
/*
func display_title()
/* タイトル描画
int i,x
str s,s1
    wipe()
    lineWidth(2)
    gcolor(-THRED,0,0,255)
    box(61,4,448,128)
    gcolor(-THMAGENTA,0,0,200)
    fill(63,6,446,126)
    s="BINGO"
    for i=0 to 4
        x=i*70+90
        s1=utf8Mid$(s,i+1,1)
        gcolor(-TWHITE,0,0,255)
        symbol(x-11,16,s1,"Times New Roman",64)
        gcolor(-THWHITE,0,0,255)
        symbol(x-9 ,18,s1,"Times New Roman",64)
    next
    /*
    gcolor(-TGREEN,0,0,255)        :fill(112,180,400,320)
    //
    str copyright="Presented by AIG-SOFT"
    str forMachine="for X-BASIC or iOS"
    gcolor(-TWHITE,0,0,255)
    symbol(170,201,copyright,"IPAGothic",16)
    symbol(180,231,forMachine,"IPAGothic",16)
    gcolor(-THWHITE,0,0,255)
    symbol(169,200,copyright,"IPAGothic",16)
    symbol(179,230,forMachine,"IPAGothic",16)
    //
    gcolor(-THRED,0,0,255)
    box(109,178,403,324)
    hitKey()
endfunc
/*
func srand2()
/* 乱数初期化
int t
    t=val(right$(time$,2))+val(mid$(time$,4,2))
    srand(t*16)
endfunc
/*
func hitKey()
    setFunctionKey(0,localizedString("ここを押してください","Hit This Button"),'!')
    displayFunctionKey(YES,0,0)
    while inkey()=0
    endwhile
    cls()
    displayFunctionKey(NO,0,0)
endfunc

func str localizedString(js;str,es;str)
    if isLocalizeJapan() then return(js)
    return (es)
endfunc


//--------------------------------------------------------------------------------

Zipファイル :XBbingo.zip

2013年2月26日火曜日

電子メイル関数テスト

電子メイル関数のサンプルプログラムです。 別途pngファイルを用意しておいてください(添付ファイルを作るため)。
//------------------------------------------------
/* eMailSend() test
//------------------------------------------------

dim str fileList(256):// ()内は扱える最大ファイル数
int cnt
// ここをpng->jpegと変更してテスト
cnt=files(fileList,"","png",YES,FILES_FILE)
if isLocalizeJapan() then {
 print "該当ファイル数=";cnt
} else {
 print "Corresponding file number=";cnt
}
int i
for i=0 to cnt-1
 print i;":";fileList(i)
next

// (1)添付なし
if isLocalizeJapan() then {
 print "(1)添付なし"
 emailSend("件名1","本文1")
} else {
 print "(1)no attachment"
 emailSend("subject1","body1")
}
//hitKey()
// (2)そのまま添付
if isLocalizeJapan() then {
 print "(2)そのまま添付"
 emailSend("件名2","本文2(添付付き)",fileList,3)
} else {
 print "(2)attach each file"
 emailSend("subject2","body2(with attachment)",fileList,3)
}
//hitKey()
// (3)zip圧縮添付
if isLocalizeJapan() then {
 print "(3)zip圧縮添付"
 emailSend("件名3","本文3(zip添付付き)",fileList,10,"testzip.zip")
} else {
 print "(3)attach with zip archive"
 emailSend("subject3","body3(zip archive)",fileList,10,"testzip.zip")
}

if isLocalizeJapan() then {
 print "全送信終了"
} else {
 print "All send finish."
}

//------------------------------------------------
end
//------------------------------------------------
func hitKey()
 str exit$
 if isLocalizeJapan() then {
  exit$="次へ"
 } else {
  exit$="To Next"
 }
 setFunctionKey(0,exit$,'!')
 displayFunctionKey(YES,0,0)
 while inkey()=0
 endwhile
 cls()
 displayFunctionKey(NO,0,0)
endfunc

Zipファイル :XBtests.zip

2013年2月25日月曜日

電子コンパス関数テスト

電子コンパス関数のテストプログラムです。 iPod touchには電子コンパスはないので利用できません。 (これが電話以外のiPhoneとの違い。)
//----------------------------------------------------------------------------------------------
// compass test
//----------------------------------------------------------------------------------------------

print "version Motion=";versionXBiOSMotion$()

font("Cochin",6):// ファンクションキーのフォントを設定
setFunctionKey(0,"end"   ,'!')
setFunctionKey(1,"pause" ,'p')
setFunctionKey(2,"start" ,'s')
setFunctionKey(3,"clear" ,'c')
displayFunctionKey(YES,0,3)
kBackgroundAlpha(0.9)
font("IPAGothic")

if compassStart(10) then {
 print localizedString("方位取得は使えません","Can't use compass.")
 end
}

float degree,magnetic
int ky,cnt,i

while YES
 if not kbhit() then {
  i=0
  cnt=compassCount()
  if cnt>0 then locate(0,1):print "cnt=";cnt
  while cnt>0
   degree=compassGetData(magnetic)
   locate(0,2+i)
   if isLocalizeJapan() then {
    print using "極北からの角度=###.####,磁北からの角度=###.####";degree,magnetic
   } else {
    print using "true=###.####,magnetic=###.####";degree,magnetic
   }
   cnt=cnt-1
   i=i+1
   if kbhit() then break
  endwhile
 } else {
  ky=inkey()
  switch ky
   case 'p'
    compassPause(YES)
    print "Pause"
    break
   case 's'
    compassPause(NO)
    print "Start"
    break
   case 'c'
    cls()
    compassClear()
    break
   default:
    // 念のため
    beep()
    break
  endswitch
  if ky='!' then break
 }
endwhile
compassEnd()
end

//----------------------------------------------------------------------------------------------

func str localizedString(js;str,es;str)
 if isLocalizeJapan() then return(js)
 return (es)
endfunc

//----------------------------------------------------------------------------------------------

Zipファイル :XBtests.zip