浏览python代码

时间:2016-04-02 23:09:10

标签: python branch action

我是python的新手,我正在制作一个简单的游戏来帮助自己学习它。我已经达到了一个目的,我希望在游戏中做出影响其后所有行动的决定。

print ("Left down the hallway? Or right?")

action4 = input()       
if action4 == ("left"):
    print ("You turn left and proceed down this hallway")
elif action4 == ("right"):
    print ("You turn right and proceed down this hallway")

#The game will branch off from this

我可以设置两个不同版本的代码分支。一个选择向右走,一个选择向左走。我希望每个方向完全给出不同的游戏。我该怎么做呢?提前谢谢!

1 个答案:

答案 0 :(得分:0)

考虑使用两个函数来完成这项工作。它看起来像这样:

var BABYLON;
var canvas = document.getElementById('gamecanvas');
var engine = new BABYLON.Engine(canvas, true);
var player_height = 2;
var player_speed = 1;
var player_inertia = 0.9;

function INIT_GAME(){
    BABYLON.SceneLoader.Load('Scenes/', 'zombie_map.babylon', engine, function(newScene){
        var scene = newScene; 
        var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), scene);
        var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene);
        scene.activeCamera = player;
        scene.activeCamera.attachControl(canvas, true);
        scene.enablePhysics();
        scene.setGravity(new BABYLON.Vector3(0, -10, 0));
        player.ellipsoid = new BABYLON.Vector3(1, player_height, 1);
        player.checkCollisions = true;
        player.applyGravity = true;
        player.keysUp = [87];
        player.keysDown = [83];
        player.keysLeft = [65];
        player.keysRight = [68];
        player.inertia = player_inertia;
        player.speed = player_speed;
        newScene.executeWhenReady(function(){
            engine.runRenderLoop(function(){
                newScene.render();
            });
        });
    });

canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock;
canvas.requestPointerLock();

window.addEventListener('resize', function(){
    engine.resize();
});