|
楼主 |
发表于 2005-4-15 10:22:22
|
显示全部楼层
我想用vim写,才刚刚开始:
[code:1]
" Gomoku Game in VIM
" v0.1 2005-03-13 Jerry Fleming<[email protected]>
" COMMENT
" This game adopts the idea and algorithm of gomoku.el, which may be found
" in standard Emacs distribution. No restriction is made on the squares one
" may move to disable _force win_ in the TRUE Gomoku, because I have no idea
" how one can force win at all. If you guys do, please let me know.
" some vars that you may change to fix your screen
let s:width = 128 " columns of text your screen can display
let s:height = 48 " rows of text your screen can display
let s:player = "X" " the piece-shape for a play
let s:robot = "0" " the piece-shape for the robot
let s:grid = "." " the mark of a square position
let s:gridwidth = 3 " the width of the grid, which should be less than 5;
" otherwise you can only see a very small set of grids
" PLAYING
" use h,l,j,k keys to move around as you would normally do in vimming, and press
" space bar where you see you are likely to win
"""
""" IMPORTANT: you should not edit below whithout aware what you are doing
"""
" since we deliberately makes the board four times of the screen, we should turn
" wrap off to see only a _windowed_ central part of the board
set wrap!
" we'd better set whichwrap so as to move freely with h,l,j,k
set ww=h,l,b,s
" the cmdheight might be changed, so we set it back
set ch=1
" initialize the board
let s:count= 0
while s:count < s:gridwidth - 1
let s:grid = s:grid . " "
let s:count = s:count + 1
endwhile
let @" = s:grid
let s:count = 0
while s:count < s:width / s:gridwidth
normal p
let s:count = s:count + 1
endwhile
let s:count=0
normal yy
while s:count < s:height - 1
normal p
let s:count = s:count + 1
endwhile
normal gg
let s:count=0
while s:count < s:height - 1
let s:i = s:gridwidth - 2
while s:i > 0
normal jd$
let s:i = s:i -1
endwhile
normal j
let s:count = s:count + 1
endwhile
normal gg0
" keymap to move s:gridwidth at a time and make your turn
let @x = s:player
noremap <Space> x"xPh
noremap l e
noremap h ge
" Gary Johnson <[email protected]> contributed the following maps
noremap j :let q=col(".")<CR>$:call search('\S','W')<CR>:exec "normal" q."\|"<CR>:echo ""<CR>
noremap k :let q=col(".")<CR>0:call search('\S','bW')<CR>:exec "normal" q."\|"<CR>:echo ""<CR>
" save game session
noremap s :w! .vimgomoku<CR>
" abort game
noremap q :q!<CR>
" save and exit
noremap x :wq! .vimgomoku<CR>
" read saved session
noremap r ggdG:r .vimgomoku<CR>
" new game
noremap n ggdG:source gomoku.vim<CR>
[/code:1] |
|