コード例 #1
0
ファイル: startGame.py プロジェクト: MZASTR/cdsite
def startGame(gid):
    rvalue = {"errmsg":"", "pclist":[]}

    # find request.user.id created game id
    if gid <1:
        rvalue["errmsg"]="Game does not exist!"
        return rvalue

    # set game statue
    try:
        game = GameInfo.objects.get(pk=gid)
        
        if game.statue ==1:
            game.statue = 2
            allpc=PC.objects.filter(gameStatue=gid)
            pc_num = len(allpc)

            if pc_num<2:
                rvalue["errmsg"] = "not enough players!"
                return rvalue
            if pc_num>6:
                rvalue["errmsg"] = "too many players! please remove %d player(s)."%(len(pclist)-6)
                return rvalue

            # set players statue
            rvalue["pclist"] = ""
            tmpC = 0
            
            for pc in allpc:
                if tmpC ==0:
                    firstCaster = pc.player_id
                pc.sanity = 3

                #pc sequence

                #提醒:PClist部分作为投骰顺序数组保存,勿删除!
                #游戏信息使用get GIRNDByUid()获取
                
                tstr = str(pc.player_id)
                tmpC = tmpC + 1
                rvalue["pclist"] = rvalue["pclist"] + tstr
                if tmpC < pc_num:   #6:
                    rvalue["pclist"] = rvalue["pclist"] + ","

            createNewRound(firstCaster,gid)
            game.pclist = rvalue["pclist"]
            game.save(update_fields=['statue','pclist'])
    except Exception,data:
        debugLog("startGame():"+str(Exception)+":"+str(data))
        rvalue["errmsg"] = "cannot start the game!"
コード例 #2
0
ファイル: eye_choose.py プロジェクト: MZASTR/cdsite
    else:
        t_rnd.victimDice = diceIndex[dice]
        t_rnd.save(update_fields=['victimDice'])
        
        #if game over
        gameover = ifGameOver(gid)
        if gameover>=0:
	    rvalue["gameover"]=1
	    rvalue["winner"]=gameover
	    game = GameInfo.objects.get(pk=gid)
	    game.statue = 0
	    game.winner = gameover
	    game.save(update_fields=['statue','winner'])
	    
	    # TODO:
	    # 清除各pc游戏标志
	else:
	    rvalue["gameover"]=0

	    nextCaster = findNextCaster(gid)
	    newrid = createNewRound(nextCaster,gid)
	    rvalue["crntRid"] = newrid
	    rvalue["pTurn"] = nextCaster
	    rvalue["rtime"] = datetime.datetime.now().strftime('%Y-%B-%d %H:%M:%S')
	    rvalue["rFlag"] = 1
	    rvalue["rollFlag"] = 1

    r["info"] = rvalue
    r["target"] = target
    
    return r
コード例 #3
0
ファイル: roll.py プロジェクト: MZASTR/cdsite
def roll(request, target, gid, cRound, turnFlg):
    debugLog("roll() begin aaa")
    uid = request.user.id
    
    attFlag = turnFlg["RollTurnInfo"]["grStatue"]
    
    r = {"errmsg":""}
    targetStatue = ifMad(target)
    
    if targetStatue["errmsg"]=="":
        mad = targetStatue["mad"]
    else:
        r["errmsg"] = targetStatue["errmsg"]
        return r
    if mad and attFlag==0:
	r["errmsg"] = "target mad" #u"目标已疯,不能进行此操作。"
        return r
    else:
        # 生成骰数
	num = random.randint(0,11)
	#num = 9
	
        # 根据骰数决定对应操作
        diceIndex =["Cthulhu","Yellow","Tentacle","Tentacle","Yellow","Yellow","Yellow","Yellow","Elder","Eye","Tentacle","Tentacle"]

        debugLog("roll()  randint: diceNum="+str(num)+" dice="+str(diceIndex[num]) )
        debugLog("roll() *** attFlag="+str(attFlag))

        #设置攻击及受害者
        if attFlag==0:
            caster = uid
            victim = target
        elif attFlag == 1:
            lastRnd = getLastRound(gid)
            caster = lastRnd.victim
            victim = lastRnd.caster
        else:
            r["errmsg"] = "unknow"
            return r
        
        r["target"] = victim
        
        if not turnFlg["PCTURN"]:
            ot = True
        else:
            ot = False
            
        # 进行相应操作:扣除被伤害者相应神智/...等
        va = {"dice":diceIndex[num],
              "gid":gid,
              "caster":caster,
              "victim":victim,
              "flag":attFlag,
              "overtime":ot
              }
        rvalue = switch(va)
        
        if len(rvalue)==0:
            return r
        rvalue["rid"] = cRound

	rnd_list = Round.objects.filter(gameID=gid).order_by('-id')[:1]
	t_rnd = rnd_list[0]
        
        rvalue["rollFlag"] = attFlag

        #更新
        if attFlag==0:
	    if diceIndex[num]!="Eye":
	        rvalue["pTurn"] = target
	    else:
	        rvalue["pTurn"] = caster
            t_rnd.casterDice = num
            t_rnd.fbTimeBegin = datetime.datetime.now()
            t_rnd.victim = target
            t_rnd.save(update_fields=['casterDice','victim','fbTimeBegin'])
        elif attFlag == 1:
            t_rnd.victimDice = num
            t_rnd.save(update_fields=['victimDice'])

            # 若本轮结束则更新本轮;
            if diceIndex[num]!="Eye":
	        # 游戏结束:sanity<1的人有5个;查找是否有获胜者;返回数据格式:
	        gameover = ifGameOver(gid)
	        if gameover>=0:
		    rvalue["gameover"]=1
		    rvalue["winner"]=gameover
		    game = GameInfo.objects.get(pk=gid)
		    game.statue = 0
		    game.winner = gameover
		    game.save(update_fields=['statue','winner'])
		else:
		    rvalue["gameover"]=0
		    
		    #查找下一个玩家,开启下一回合(轮)
		    nextCaster = findNextCaster(gid)
		    newrid = createNewRound(nextCaster,gid)
		    
		    rvalue["crntRid"] = newrid
		    rvalue["pTurn"] = nextCaster
		    rvalue["rtime"] = datetime.datetime.now()
		    rvalue["rFlag"] = 1
            else:
	        rvalue["pTurn"] = uid
	        rvalue["rollFlag"] = attFlag+3
        else:
            pass
	    
        r["info"] = rvalue

    return r
コード例 #4
0
ファイル: checkPCTurn.py プロジェクト: MZASTR/cdsite
        es = str(Exception) + ":" + str(data)
        debugLog("check PCTurn () line 38:" + es)
        return r

    # 无论是否超时,只要当前是该玩家投骰则返回True
    if r["RollTurnInfo"]["crntPC"] == uid:
        r["PCTURN"] = True
        r["RollToken"] = True
        return r
    elif r["RollTurnInfo"]["overtime"] == True:

        # 非uid投骰,且当前超时:
        #  检查下一个投骰者是否uid
        nextpc = isNextCaster(uid, gid)

        #    若是则设置当前轮状态,生成新轮,并返回新生成的轮信息
        ##if uid == nextpc:
        if nextpc["found"]:
            r["RollToken"] = True
            # set crnt turn statue;
            rnd = getLastRound(gid)
            rnd.roundStatue = 1
            rnd.save(update_fields=["roundStatue"])
            # generate new turn;
            createNewRound(nextpc["rcntPC"], gid)
            r["rndID"] = rnd.id
            return r
    else:
        return r
    return r