rpg game实现

本博客介绍了一个基于SQL的游戏,玩家可以在虚拟世界中通过执行SQL命令进行探险。文章详细解释了如何使用各种SQL过程来实现游戏的基本操作,如查看当前房间物品、前往不同地点、打开手电筒照明等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

set nocount on
drop proc look
create proc look
as
 
begin
  
declare @nowRoomID int,@nowRoomName nvarchar(50)
  
select @nowRoomID=RoomID from nowRoom
  
select @nowRoomName=roomName from Room where RoomID=@nowRoomID
  
print 'You are in the '+@nowRoomName
  
print 'You can see the following things:'
  
select GoodName
  
from Goods g
  
where inRoomID=@nowRoomID and not exists(select outerid
                                           
from GoodsInGood
                                           
where innerID=g.GoodID
                                           )
  
print 'You may go to the following rooms:'
  
select r2.RoomName
  
from Room r1
  
join RoomContact rc on r1.RoomID=rc.id1
  
join Room r2 on rc.id2=r2.RoomID 
  
where r1.RoomID=@nowRoomID
 
end
drop proc go2
create proc go2 (@RoomName nvarchar(50))
as
 
begin
  
declare @nowRoomID int,@isLighted bit,@isLightOn bit
  
select @nowRoomID=RoomID from nowRoom
  
select @isLightOn=status
  
from list
  
join Goods on list.GoodID=Goods.GoodID and Goods.GoodName like '%flashlight%'
  
set @isLightOn=isnull(@isLightOn,0)
  
select @islighted=r2.isLighted
  
from Room r1
  
join RoomContact rc on r1.RoomID=rc.id1
  
join Room r2 on rc.id2=r2.RoomID 
  
where r1.RoomID=@nowRoomID and r2.RoomName=@RoomName
  
print cast(@islighted as char(1))
  
print cast(@islighton as char(1))
  
if (@islighted | @isLightOn)=1
      
begin
        
update nowRoom
        
set RoomID=(select RoomID from Room where RoomName=@RoomName)
      
end   
  
else if (@islighted | @isLightOn)=0
      
print 'You can'+''''+'t go to the '+@RoomName+' because it'+''''+'s dark in the cellar and you'+''''+'re afraid of the dark.'
  
else
      
print 'You can'+''''+'t goto '+@RoomName+' from here'
end
go2 cellar
select * from list

drop proc turnon
create proc turnon (@light nvarchar(50))
as
 
declare @GoodID int,@lightID int
 
begin
  
select @GoodID=list.GoodID
  
from list
  
join Goods on list.GoodID=Goods.GoodID and Goods.GoodName=@light
  
if @GoodID is not null
    
begin
      
select  @lightID=list.GoodID
      
from list
      
join Goods_kind on List.GoodID=Goods_kind.GoodID
      
join kind on Goods_kind.kindID=kind.id
      
where list.GoodID=@GoodID and kind.name like '%lighted%'
      
if @lightID is not null
         
begin
           
update list
           
set status=1
           
where GoodID=@lightID
           
print 'flashlight turned on.'
         
end
      
else
        
print @light+' not a light.'
    
end
  
else
   
print 'You don'+''''+'t have the '+@light
 
end

create proc turnoff (@light nvarchar(50))
as
 
declare @GoodID int,@lightID int
 
begin
  
select @GoodID=list.GoodID
  
from list
  
join Goods on list.GoodID=Goods.GoodID and Goods.GoodName=@light
  
if @GoodID is not null
    
begin
      
select  @lightID=list.GoodID
      
from list
      
join Goods_kind on List.GoodID=Goods_kind.GoodID
      
join kind on Goods_kind.kindID=kind.id
      
where list.GoodID=@GoodID and kind.name like '%lighted%'
      
if @lightID is not null
         
begin
           
update list
           
set status=0
           
where GoodID=@lightID
           
print 'flashlight turned off.'
         
end
      
else
        
print @light+' not a light.'
    
end
  
else
   
print 'You don'+''''+'t have the '+@light
 
end

drop proc release
create proc release (@GoodName nvarchar(50))
as
declare @GoodID int,@nowRoomID int
begin
 
select @nowRoomID=RoomID from nowRoom
 
select @GoodID=list.GoodID
 
from list
 
join Goods on list.GoodID=Goods.GoodID
 
where GoodName=@GoodName
 
if @GoodID is not null
   
begin
    
begin tran
     
update Goods
     
set inRoomID=@nowRoomID
     
where GoodID=@GoodID
     
delete list
     
where GoodID=@GoodID
     
print 'You now release the '+@GoodName
    
commit tran
   
end
 
else
  
print 'You don'+''''+'t have the '+@GoodName
end
 
 
 
release apple
 
create proc list1
as
begin
  
print 'You have:'
  
select GoodName as 'inventory'
  
from list
  
join Goods on list.GoodID=Goods.GoodID
end

drop proc eat
create proc eat (@food nvarchar(50))
as
 
declare @GoodID int,@foodID int
 
begin
  
select @GoodID=list.GoodID
  
from list
  
join Goods on list.GoodID=Goods.GoodID and Goods.GoodName=@food
  
if @GoodID is not null
    
begin
      
select  @foodID=list.GoodID
      
from list
      
join Goods_kind on List.GoodID=Goods_kind.GoodID
      
join kind on Goods_kind.kindID=kind.id
      
where list.GoodID=@GoodID and kind.name like '%eat%'
      
if @foodID is not null
         
begin
          
begin tran
           
delete list
           
where GoodID=@foodID
           
update Goods
           
set inRoomId=null
           
where GoodID=@foodID
           
print 'Taste good.'
         
commit tran
        
end
      
else
        
print @food+' can'+''''+'t be edible'
    
end
  
else
   
print 'You don'+''''+'t have the '+@food
 
end
drop proc take
create proc take (@GoodName nvarchar(50))
as
declare @GoodID int,@canTakeID int
begin
 
select @GoodID=GoodID
 
from Goods
 
where inRoomID=(select RoomID from nowRoom)
       
and GoodName=@GoodName
 
if @GoodID is null
   
print 'There is no '+@GoodName+' here'
 
else
 
begin
  
select  @canTakeID=GoodID
  
from Goods_kind
       
join kind on Goods_kind.kindID=kind.id
  
where GoodID=@GoodID
        
and kind.name like '%take%'
  
if @canTakeID is not null
   
begin
    
begin tran
     
insert into list(GoodID) values(@canTakeID)
     
update Goods
     
set inRoomID=null
     
where GoodID=@GoodID
     
delete GoodsinGood
     
where innerID=@GoodID
     
print 'You now have the '+@GoodName
    
commit tran
   
end
  
else
    
print 'You can'+''''+'t pick up a '+@GoodName
end
end
release 
[table]
release 
[table]
look
list1
select * from Goods
select * from goodsingood
take 
'washing maching'
 
create function IDExistedInRoom(@name nvarchar(50))
returns int
as
begin
 
declare @id int
 
select @id=GoodID
 
from Goods
 
where inRoomID=(select RoomID from nowRoom)
       
and GoodName=@name
 
return @id
end
declare @i int
select @i=dbo.IDExistedInRoom('apple')
go2 kitchen
drop proc lookin
create proc lookin (@GoodName nvarchar(50))
as
begin
  
declare @GoodID int
  
select @GoodID=dbo.IDExistedInRoom(@GoodName)
  
if @GoodID is null
    
print 'There is no '+@GoodName+' here'
  
else
  
begin
   
print 'You can see the following things:'
   
select g2.GoodName
   
from Goods g1
   
join GoodsinGood gig on g1.GoodID=gig.outerID
   
join Goods g2 on gig.innerid=g2.GoodID
   
where g1.GoodID=@GoodID
  
end
end

lookin ee
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值