|
楼主 |
发表于 2009-4-28 17:56
|
显示全部楼层
procedure newshop(begin_num, page_num: integer);
type
TNewShop = record
case TCallType of
Element:
(Item, Amount, Seclectamount, Price, index1, index2: Smallint);
Address:
(Data: array[0..5] of Smallint);
end;
var
i, j, k, ifown, amount, shopnum, menu, price, ifend, page, totalprice, money, k_num: integer;
//page页码
own_num, word, temp: widestring;
list: array[0..4] of integer;
//shopitem: array[0..4] of widestring;
buylist: array of TNewShop;
begin
setlength(buylist, (page_num+1)*5);
setlength(menustring, 5);
setlength(Menuengstring, 5);
amount := 0;
page := 0;
ifend := 0;
ifown := 0;
menu := 0;
k := 0;
totalprice:=0;
for j:=0 to page_num do
begin
for i:=0 to 4 do
begin
if Rshop[begin_num+j].Amount[i] > 0 then
begin
buylist[k].Item := Rshop[begin_num+j].Item[i];
buylist[k].Amount := Rshop[begin_num+j].Amount[i];
buylist[k].Price := Rshop[begin_num+j].Price[i];
buylist[k].Seclectamount := 0;
buylist[k].index1 := j;
buylist[k].index2 := i;
totalprice := totalprice + buylist[k].Seclectamount * buylist[k].Price;
k := k+1;
end;
end;
end; //end 2 for
k_num:=k;
//buylist[k].Amount := 0;
//任选一个商店, 因未写他去其他客栈的指令 //取消此设计,由begin_num, page_num控制,在50e中是e1,e2
//shopnum := random(5);
//p:=0;
instruct_1($B9E, $6F, 0);
word := ' 物品';
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2, 155, 105, colcolor(49), colcolor(47));
word := ' 价格';
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2 + 135, 155, 45, colcolor(49), colcolor(47));
word := ' 存货';
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2 + 200, 155, 45, colcolor(49), colcolor(47));
word := ' 持有';
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2 + 265, 155, 45, colcolor(49), colcolor(47));
word := ' 交易';
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2 + 330, 155, 45, colcolor(49), colcolor(47));
newshop_showmenu2(363, CENTER_Y+115, 145, -1);
while ifend = 0 do
begin
if (menu < 0) or (menu > 4) then menu:=0;
newshop_showmenu2(363, CENTER_Y+115, 145, -1);
//SDL_UpdateRect(screen, CENTER_X-10, CENTER_Y+109, 166, 44);
str(page div 5 + 1, temp);
word := ' '+temp + '/';
str((k+4) div 5, temp);
word := word + temp;
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2 + 400, 155, 40, colcolor(49), colcolor(47));
for j := 0 to MAX_ITEM_AMOUNT - 1 do
begin
if RItemList[j].Number = MONEY_ID then
money := RItemList[j].Amount;
end; //end for
str(money, temp);
word := ' 身上银两:' + format('%5d', [money]);
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2, CENTER_Y+115, 160, colcolor(49), colcolor(47));
str(totalprice, temp);
word := ' 消费估算:' + format('%5d', [totalprice]);
DrawTextWithRect_new(@word[1], CENTER_X - 375 div 2, CENTER_Y+160, 160, colcolor(49), colcolor(47));
for i:=page to k-1 do
begin
if buylist[i].Amount > 0 then
begin
for j := 0 to MAX_ITEM_AMOUNT - 1 do
begin
if RItemList[j].Number = buylist[i].Item then
begin
own_num := format('%6d', [RItemList[j].Amount]);
ifown := 1;
break;
end; //end if
end; //end for
if ifown = 1 then
begin
menustring[amount] := Big5toUnicode(@Ritem[buylist[i].Item].Name);
menuengstring[amount] := format('%10d', [buylist[i].Price])+
format('%7d', [buylist[i].Amount])+
own_num+
format('%6d', [buylist[i].Seclectamount]);
end
else
begin
menustring[amount] := Big5toUnicode(@Ritem[buylist[i].Item].Name);
menuengstring[amount] := format('%10d', [buylist[i].Price])+
format('%7d', [buylist[i].Amount])+
format('%6d', [0])+
format('%6d', [buylist[i].Seclectamount]);
end;
ifown := 0;
list[amount] := i;
amount := amount + 1;
if amount >= 5 then
break;
end; //end if
end; //end for
menu := newshop_menu(CENTER_X - 375 div 2, 200, 375, amount - 1, menu);
if (menu >= 0) and (menu < 5) then
begin
//menu := list[menu];
price := buylist[list[menu]].Price;
if (instruct_31(price, 1, 0) = 1) and (totalprice + buylist[list[menu]].Price < money) then
begin
buylist[list[menu]].Seclectamount := buylist[list[menu]].Seclectamount+1;
if buylist[list[menu]].Seclectamount > buylist[list[menu]].amount then
buylist[list[menu]].Seclectamount := buylist[list[menu]].amount
else
totalprice := totalprice + buylist[list[menu]].Price;
end; //end if price
end //end if menu
else
begin
if menu < 100 then
begin
case menu of
6:
begin
for j:=0 to k-1 do
begin
buylist[j].Seclectamount :=0;
end;
totalprice := 0;
end;
7:
begin
for j:=0 to k-1 do //交易,计算金额
begin
if buylist[j].Seclectamount > 0 then
begin
instruct_32(Rshop[buylist[j].index1].Item[buylist[j].index2], buylist[j].Seclectamount);
instruct_32(MONEY_ID, -(buylist[j].Price*buylist[j].Seclectamount));
Rshop[buylist[j].index1].Amount[buylist[j].index2] := Rshop[buylist[j].index1].Amount[buylist[j].index2] - buylist[j].Seclectamount;
buylist[j].Amount := buylist[j].Amount-buylist[j].Seclectamount;
buylist[j].Seclectamount :=0; //重置交易数额
end; //end if seclectamount
end; //end for
for j:=0 to k-1 do //处理存货为0商品,方便翻页控制
begin
if buylist[j].Amount = 0 then
begin
for i:=j to k-2 do
begin
buylist[i].Item := buylist[i+1].Item;
buylist[i].Amount := buylist[i+1].Amount;
buylist[i].Price := buylist[i+1].Price;
buylist[i].Seclectamount := buylist[i+1].Seclectamount;
buylist[i].index1 := buylist[i+1].index1;
buylist[i].index2 := buylist[i+1].index2;
end; //end for
k := k-1; //减少商品种类计数
end; //end if
end; //end for
totalprice := 0;
page:=0;
end;
8:
begin
ifend := 1;
end;
9:
begin
if page <= k-6 then
begin
page := page+5;
end;
end;
10:
begin
if page >= 5 then
begin
page := page-5;
end;
end;
end; // end case
end // end if
else
begin
menu := menu - 100;
if (buylist[list[menu]].Seclectamount > 0) then
begin
buylist[list[menu]].Seclectamount := buylist[list[menu]].Seclectamount-1;
totalprice := totalprice - buylist[list[menu]].Price;
end; //end if price
end;
end; //end else
amount:=0;
end; //end while ifend
end;
function newshop_menu(x, y, w, max, menu: integer): integer;
var
menup, index: integer;
begin
index := -1;
//menu := 0;
//SDL_EnableKeyRepeat(0,10);
//DrawMMap;
newshop_showmenu(x, y, w, max, menu);
//SDL_UpdateRect(screen, x-10, y-11, w + 21, 132);
while (SDL_WaitEvent(@event) >= 0) do
begin
case event.type_ of
SDL_QUITEV:
if messagedlg('Are you sure to quit?', mtConfirmation, [mbOk, mbCancel], 0) = idOK then
Quit;
SDL_KEYUP:
begin
if (event.key.keysym.sym = sdlk_right) then
begin
if index >= 0 then
begin
index := index+1;
if index > 2 then
index := 2;
newshop_showmenu2(363, CENTER_Y+115, 145, index);
end
else
begin
result := 9;
break;
end;
end;
if (event.key.keysym.sym = sdlk_left) then
begin
if index >= 0 then
begin
index := index-1;
if index < 0 then
index := 0;
newshop_showmenu2(363, CENTER_Y+115, 145, index);
end
else
begin
result := 10;
break;
end;
end;
if (event.key.keysym.sym = sdlk_down) then
begin
menu := menu + 1;
if menu > max then
begin
menu := 6;
index := 0;
newshop_showmenu2(363, CENTER_Y+115, 145, index);
end;
newshop_showmenu(x, y, w, max, menu);
end;
if (event.key.keysym.sym = sdlk_up) then
begin
if index >= 0 then
begin
index := -1;
menu := max;
newshop_showmenu2(363, CENTER_Y+115, 145, index);
newshop_showmenu(x, y, w, max, menu);
end
else
begin
menu := menu - 1;
if menu < 0 then
menu := 0;
newshop_showmenu(x, y, w, max, menu);
end;
end;
if ((event.key.keysym.sym = sdlk_escape)) and (where <= 2) then
begin
if index < 0 then
begin
result := menu+100;
break;
end;
end;
if (event.key.keysym.sym = sdlk_return) or (event.key.keysym.sym = sdlk_space) then
begin
if index >= 0 then
begin
result := 6+index;
break;
end
else
begin
result := menu;
SDL_UpdateRect(screen, x-10, y-11, w + 21, 132);
break;
end;
end;
end;
SDL_MOUSEBUTTONUP:
begin
if (event.button.button = sdl_button_right) and (where <= 2) then
begin
if (event.button.x >= CENTER_X - 375 div 2 + 400) and (event.button.x < CENTER_X - 375 div 2 + 440) and (event.button.y >= 155) and (event.button.y < 155 + 23) then
begin
result := 10;
break;
end
else
begin
if index < 0 then
begin
result := menu+100;
break;
end;
end;
end;
if (event.button.button = sdl_button_left) then
begin
if (event.button.x >= CENTER_X - 375 div 2 + 400) and (event.button.x < CENTER_X - 375 div 2 + 440) and (event.button.y >= 155) and (event.button.y < 155 + 23) then
begin
result := 9;
break;
end
else
begin
if index < 0 then
begin
result := menu;
SDL_UpdateRect(screen, x-10, y-11, w + 21, 132);
break;
end
else
begin
result := 6+index;
break;
end; //end else
end; //end else
end;
end;
SDL_MOUSEMOTION:
begin
if (event.button.x >= x) and (event.button.x < x + w) and (event.button.y > y) and (event.button.y < y + max * 22 + 29) then
begin
menup := menu;
index := -1;
newshop_showmenu2(363, CENTER_Y+115, 145, index);
menu := (event.button.y - y - 2) div 22;
if menu > max then
menu := max;
if menu < 0 then
menu := 0;
if menup <> menu then
newshop_showmenu(x, y, w, max, menu);
end
else
begin
if (event.button.x >= 363) and (event.button.x < 363+145) and (event.button.y > CENTER_Y+115) and (event.button.y < CENTER_Y+115 + 29) then
begin
menup := index;
menu := -1;
newshop_showmenu(x, y, w, max, menu);
index := (event.button.x - 363 - 2) div 50;
if index > 2 then
index := 2;
if index < 0 then
index := 0;
if menup <> index then
newshop_showmenu2(363, CENTER_Y+115, 145, index);
end
else
begin
menu := -1;
index := -1;
newshop_showmenu(x, y, w, max, menu);
newshop_showmenu2(363, CENTER_Y+115, 145, index);
end; //end else
end; //end else
end;
end;
end;
//清空键盘键和鼠标键值, 避免影响其余部分
event.key.keysym.sym := 0;
event.button.button := 0;
end;
procedure newshop_showmenu(x, y, w, max, menu: integer);
var
i, j, p: integer;
begin
DrawRectangle_new(x, y, w, 4);
if length(Menuengstring) > 0 then
p := 1
else
p := 0;
for i := 0 to max do
if i = menu then
begin
drawshadowtext(@menustring[i][1], x - 17, y + 2 + 22 * i, colcolor($66), colcolor($64));
if p = 1 then
drawengshadowtext(@menuengstring[i][1], x + 73, y + 2 + 22 * i, colcolor($66), colcolor($64));
end
else
begin
drawshadowtext(@menustring[i][1], x - 17, y + 2 + 22 * i, colcolor($7), colcolor($5));
if p = 1 then
drawengshadowtext(@menuengstring[i][1], x + 73, y + 2 + 22 * i, colcolor($7), colcolor($5));
end;
SDL_UpdateRect(screen, x-10, y-11, w + 21, 132);
end;
procedure newshop_showmenu2(x, y, w, index: integer);
var
i, j, p: integer;
word: array[0..2] of widestring;
begin
word[0]:=' 重置';
word[1]:=' 确定';
word[2]:=' 离开';
DrawRectangle_new(x, y, w, 0);
for i := 0 to 2 do
if i = index then
begin
drawshadowtext(@word[i][1], x - 17 + i * 50, y + 2, colcolor($66), colcolor($64));
end
else
begin
drawshadowtext(@word[i][1], x - 17 + i * 50, y + 2, colcolor($7), colcolor($5));
end;
SDL_UpdateRect(screen, x-10, y-11, w + 21, 44);
end;
[[i] 本帖最后由 winson7891 于 2009-5-1 23:04 编辑 [/i]] |
评分
-
查看全部评分
|