From 511b70d07113b5f2215c1350073906bf753c9db6 Mon Sep 17 00:00:00 2001 From: "Florian R. A. Angermeier" Date: Fri, 24 Jun 2011 00:35:19 +0200 Subject: [PATCH] - Remove the lv_ prefix from all classes/objects - Fixed a bug in the radius code (The radius code needs some care at all) --- ClientBasic.py | 36 +++++ Server.py | 39 ++++++ gameEngine/Character.py | 271 ++++++++++++++++++++++++++++++++++++ gameEngine/Object.py | 24 ++++ gameEngine/Protocol.py | 23 +++ gameEngine/ServerFactory.py | 22 +++ gameEngine/World.py | 145 +++++++++++++++++++ objects/Bed.py | 35 +++++ objects/Cooker.py | 30 ++++ objects/Refrigerator.py | 35 +++++ objects/Shower.py | 30 ++++ objects/TvSet.py | 30 ++++ 12 files changed, 720 insertions(+) create mode 100644 ClientBasic.py create mode 100644 Server.py create mode 100644 gameEngine/Character.py create mode 100644 gameEngine/Object.py create mode 100644 gameEngine/Protocol.py create mode 100644 gameEngine/ServerFactory.py create mode 100644 gameEngine/World.py create mode 100644 objects/Bed.py create mode 100644 objects/Cooker.py create mode 100644 objects/Refrigerator.py create mode 100644 objects/Shower.py create mode 100644 objects/TvSet.py diff --git a/ClientBasic.py b/ClientBasic.py new file mode 100644 index 0000000..a286341 --- /dev/null +++ b/ClientBasic.py @@ -0,0 +1,36 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +from twisted.internet import reactor, protocol + +from lv_protocol import lv_protocol + +class lv_clientFactory( protocol.ClientFactory ): + protocol = lv_protocol + +class lv_client: + def __init__( self ): + reactor.callInThread( self.runInterface ) + reactor.connectTCP( raw_input( '\033[1;37mlv_client_basic\033[0m host [127.0.0.1] > ' ), 65000, lv_clientFactory() ) + reactor.run() + + def runInterface( self ): + playerInput = '' + while( playerInput != 'quit' ): + playerInput = raw_input( '\033[1;37mlv_client_basic\033[0m command > ' ) + +if( __name__ == '__main__' ): + client = lv_client() diff --git a/Server.py b/Server.py new file mode 100644 index 0000000..5db374f --- /dev/null +++ b/Server.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +from twisted.internet import reactor + +import gameEngine +from gameEngine.ServerFactory import ServerFactory +from gameEngine.World import World + +class Server: + def __init__( self ): + # Initializing the simulation + self.world = World( 1 ) + def run( self ): + print '\033[32mInfo\033[0m Starting world thread...' + reactor.callInThread( self.world.run ) + + print '\033[32mInfo\033[0m Starting listening socket...' + reactor.listenTCP( 65000, ServerFactory() ) + + print '\033[32mInfo\033[0m Starting reactor...' + reactor.run() + +if( __name__ == '__main__' ): + Server = Server() + Server.run() diff --git a/gameEngine/Character.py b/gameEngine/Character.py new file mode 100644 index 0000000..28cc299 --- /dev/null +++ b/gameEngine/Character.py @@ -0,0 +1,271 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +from random import choice + +class Character: + def __init__( self, id, world, gender ): + self.id = id # Unique integer number to identify a character. + self.world = world # The world a character belongs to. + self.pos = [ 0, 0, 0 ] # A characters current position. + self.destination = [ 0, 0, 0 ] # A characters destination for movement. + + if( gender.lower() == 'random' ): # A characters gender. + self.gender = choice( ( 'male', 'female' ) ) # + else: # + self.gender = gender # + + self.activity = None # A characters activity. + self.activityTimer = 0 # How much game seconds are left for an activity. + self.activityInteractive = None # The character or object to interact with. + + self.activityRadiusOn = 0 # The radius for activities which the character is + # on a character or object. + self.activityRadiusNextTo = 1 # The radius for activities which the character is + # next to a character or object. + self.activityRadiusNear = 2 # The radius for activities which the character is + # near the character or object. + + self.needs = { 'sleep': 500, # The chracters needs. + 'food': 500, # + 'water': 500, # + 'hygiene': 500, # + 'fun': 1000, # + 'social': 1000 } # + + def teleportTo( self, x, y, z ): + print 'DEBUG: Character %i teleports to X: %i Y: %i Z: %i.' % ( self.id, x, y, z ) + self.pos = [ x, y, z ] + + def goTo( self, x, y, z ): + print 'DEBUG: Character %i goes to X: Y: %i %i Z: %i.' % ( self.id, x, y, z ) + self.destination = [ x, y, z ] + + def move( self ): + # X axis + if( self.pos[ 0 ] != self.destination[ 0 ] ): + print 'DEBUG: Character %i is on his/her way on the x axis.' + if( self.pos[ 0 ] < self.destination[ 0 ] ): + self.pos[ 0 ] += 1 + elif( self.pos[ 0 ] > self.destination[ 0 ] ): + self.pos[ 0 ] -= 1 + # Y axis + if( self.pos[ 1 ] != self.destination[ 1 ] ): + print 'DEBUG: Character %i is on his/her way on the y axis.' + if( self.pos[ 1 ] < self.destination [ 1 ] ): + self.pos[ 1 ] += 1 + elif( self.pos[ 1 ] > self.destination[ 1 ] ): + self.pos[ 1 ] -= 1 + # Z axis + if( self.pos[ 2 ] != self.destination[ 2 ] ): + print 'DEBUG: Character %i is on his/her way on the z axis.' + if( self.pos[ 2 ] < self.destination [ 2 ] ): + self.pos[ 2 ] += 1 + elif( self.pos[ 2 ] > self.destination[ 2 ] ): + self.pos[ 2 ] -= 1 + + def isInRange( self, characterOrObject, type ): + if( type == 'On' ): + if( characterOrObject.pos[ 0 ] >= self.pos[ 0 ] - self.activityRadiusOn and characterOrObject.pos[0] <= self.pos[ 0 ] + self.activityRadiusOn ): + if( characterOrObject.pos[ 1 ] >= self.pos[ 1 ] - self.activityRadiusOn and characterOrObject.pos[ 1 ] <= self.pos[ 1 ] + self.activityRadiusOn ): + if( characterOrObject.pos[ 2 ] >= self.pos[ 2 ] - self.activityRadiusOn and characterOrObject.pos[ 2 ] <= self.pos[ 2 ] + self.activityRadiusOn ): + return True + else: + return False + else: + return False + else: + return False + if( type == 'NextTo' ): + if( characterOrObject.pos[ 0 ] >= self.pos[ 0 ] - self.activityRadiusNextTo and characterOrObject.pos[0] <= self.pos[ 0 ] + self.activityRadiusNextTo ): + if( characterOrObject.pos[ 1 ] >= self.pos[ 1 ] - self.activityRadiusNextTo and characterOrObject.pos[ 1 ] <= self.pos[ 1 ] + self.activityRadiusNextTo ): + if( characterOrObject.pos[ 2 ] >= self.pos[ 2 ] - self.activityRadiusNextTo and characterOrObject.pos[ 2 ] <= self.pos[ 2 ] + self.activityRadiusNextTo ): + return True + else: + return False + else: + return False + else: + return False + if( type == 'Near' ): + if( characterOrObject.pos[ 0 ] >= self.pos[ 0 ] - self.activityRadiusNear and characterOrObject.pos[0] <= self.pos[ 0 ] + self.activityRadiusNear ): + if( characterOrObject.pos[ 1 ] >= self.pos[ 1 ] - self.activityRadiusNear and characterOrObject.pos[ 1 ] <= self.pos[ 1 ] + self.activityRadiusNear ): + if( characterOrObject.pos[ 2 ] >= self.pos[ 2 ] - self.activityRadiusNear and characterOrObject.pos[ 2 ] <= self.pos[ 2 ] + self.activityRadiusNear ): + return True + else: + return False + else: + return False + else: + return False + + def increaseNeed( self, needName, needValue ): + try: + if( self.needs[needName] < 1000 ): + self.needs[needName] += needValue + elif( self.needs[needName] != 1000 ): + self.needs[needName] = 1000 + except: + pass + + def decreaseNeeds( self ): + try: + if( self.activity != 'rest' and self.activity != 'sleep' ): + self.needs['sleep'] -= 0.011574074 + if( self.activity != 'cook' ): + self.needs['food'] -= 0.003858025 + if( self.activity != 'drink' ): + self.needs['water'] -= 0.011574074 + if( self.activity != 'shower' ): + self.needs['hygiene'] -= 0.005787037 + # if( self.activity != 'watchTV' ): + # self.needs['fun'] -= 1 + # if( self.activity != 'chat' ): + # self.needs['social'] -= 1 + except: + pass + + def processActivity( self ): + # Process the activity of a character. + + if( self.activityTimer > 0 ): # Character has active activity. + print 'Character is doing activity. Timer is not zero.' + objectFound = False + for object in self.world.objects: # Search for the object to interact with. + if( object.id == self.activityInteractive ): # Object found in the wolrd's object list. + objectFound = True + + if( self.activity == 'rest' ): + radiusType = 'On' + elif( self.activity == 'sleep' ): + radiusType = 'On' + elif( self.activity == 'eatSnack' ): + radiusType = 'NextTo' + elif( self.activity == 'cook' ): + radiusType = 'NextTo' + elif( self.activity == 'drink' ): + radiusType = 'NextTo' + elif( self.activity == 'shower' ): + radiusType = 'On' + else: + radiusType = 'Near' + + if( self.isInRange( object, radiusType ) ): # Checks if the object is in range of the character. + print 'Object found to interact with and is in range (%s). Object id is %i/%i.' % ( radiusType, self.activityInteractive, object.id ) + print 'Character interacts with the object of type %s.' % ( object.type ) + exec 'object.%s( self )' % ( self.activity ) # Calls the methode of an world object which # modify a character attribute. + self.activityTimer -= 1 + + else: + print 'Object found to interact with but is not in range (%s). Object id is %i/%i.' % ( radiusType, self.activityInteractive, object.id ) + self.goTo( object.pos[0], object.pos[1], object.pos[2] ) + self.move() + if( objectFound == False ): # Object not found in the world's object list. + print 'Object not found to interact. Object id is %s/%i.' % ( self.activityInteractive, object.id ) + self.activity = None + self.activityTimer = 0 + self.activityInteractive = None + else: # Character is free for a new activity. + print 'Character is thinking about the next activity. Timer is zero.' + # Getting the lowest need + lowestNeedName = '' + lowestNeedValue = 1000 + for needName in self.needs.keys(): + if( self.needs.get( needName ) < lowestNeedValue ): + lowestNeedName = needName + lowestNeedValue = self.needs.get( needName ) + + print '\033[32mInfo\033[0m Lowest need: %s (%i)' % ( lowestNeedName, lowestNeedValue ) + + # Searching for an character or object to raise the need + # if( lowestNeedName == 'fun' or lowestNeedName == 'social' ): + # for character in self.world.characters: + # self.needs[lowestNeedName] = 1000 + # # if( character. ): + if( lowestNeedName == 'sleep' ): + if( lowestNeedValue < 833.333333333 ): # The sleep need is not below the minimal limit. + for object in self.world.objects: # Search for the object to interact with. + if( object.type == 'Bed' ): # Object of type bed found in the wolrd's object list. + if( lowestNeedValue > 208.333333333 ): # The sleep need is not below the critcal limit. + self.activity = 'rest' + self.activityTimer = 900 # 15 game minutes + self.activityInteractive = object.id + else: # The sleep need is below the critcal limit. + self.activity = 'sleep' + self.activityTimer = 28800 # 8 game hours + self.activityInteractive = object.id + if( self.isInRange( object, 'On' ) == False ): + self.goTo( object.pos[0], object.pos[1], object.pos[2] ) + self.move() + else: # The lowest need is not below the minimal limit. + self.activity = 'beHappy' # Reset the activity to a standard beHappy activity. + self.activityTimer = 1 # Reset the timer to 1. + self.activityInteractive = None # Reset the interactive to None. + elif( lowestNeedName == 'food' ): + if( lowestNeedValue < 833.333333333 ): # The food need is not below the minimal limit. + for object in self.world.objects: # Search for the object to interact with. + if( object.type == 'Refrigerator' ): # Object of type refrigerator found in the wolrd's object list. + if( lowestNeedValue > 833.333333333 ): # The food need is not below the critcal limit. + self.activity = 'eatSnack' + self.activityTimer = 300 # 5 game minutes. + self.activityInteractive = object.id + if( self.isInRange( object, 'NextTo' ) == False ): + self.goTo( object.pos[0], object.pos[1], object.pos[2] ) + self.move() + elif( object.type == 'Cooker' ): # Object of type cooker found in the wolrd's object list. + if( lowestNeedValue > 0 ): # The food need is below the critcal limit. + self.activity = 'cook' + self.activityTimer = 900 # 15 game minutes. + self.activityInteractive = object.id + if( self.isInRange( object, 'NextTo' ) == False ): + self.goTo( object.pos[0], object.pos[1], object.pos[2] ) + self.move() + else: # The lowest need is not below the minimal limit. + self.activity = 'beHappy' # Reset the activity to a standard beHappy activity. + self.activityTimer = 1 # Reset the timer to 1. + self.activityInteractive = None # Reset the interactive to None. + elif( lowestNeedName == 'water' ): + if( lowestNeedValue < 833.333333333 ): # The water need is not below the minimal limit. + for object in self.world.objects: + if( object.type == 'Refrigerator' ): + self.activity = 'drink' + self.activityTimer = 60 # 1 game minute. + self.activityInteractive = object.id + if( self.isInRange( object, 'NextTo' ) == False ): + self.goTo( object.pos[0], object.pos[1], object.pos[2] ) + self.move() + else: # The lowest need is not below the minimal limit. + self.activity = 'beHappy' # Reset the activity to a standard beHappy activity. + self.activityTimer = 1 # Reset the timer to 1. + self.activityInteractive = None # Reset the interactive to None. + elif( lowestNeedName == 'hygiene' ): + if( lowestNeedValue < 833.333333333 ): # The hygiene need is not below the minimal limit. + for object in self.world.objects: + if( object.type == 'Shower' ): + self.activity = 'shower' + self.activityTimer = 1800 # 30 game minutes. + self.activityInteractive = object.id + if( self.isInRange( object, 'On' ) == False ): + self.goTo( object.pos[0], object.pos[1], object.pos[2] ) + self.move() + else: # The lowest need is not below the minimal limit. + self.activity = 'beHappy' # Reset the activity to a standard beHappy activity. + self.activityTimer = 1 # Reset the timer to 1. + self.activityInteractive = None # Reset the interactive to None. + else: + self.activity = 'beHappy' # Reset the activity to a standard beHappy activity. + self.activityTimer = 1 # Reset the timer to 1. + self.activityInteractive = None # Reset the interactive to None. diff --git a/gameEngine/Object.py b/gameEngine/Object.py new file mode 100644 index 0000000..f0b7625 --- /dev/null +++ b/gameEngine/Object.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +class Object: + # The base class for in-world objects in La Vida. + + def __init__( self, id ): + self.id = id + self.type = 'generic' + self.pos = [ 0, 0, 0 ] + self.isInUse = False diff --git a/gameEngine/Protocol.py b/gameEngine/Protocol.py new file mode 100644 index 0000000..6193bad --- /dev/null +++ b/gameEngine/Protocol.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +from twisted.protocols import basic + +class Protocol( basic.LineReceiver ): + def lineReceived( self, line ): + if( line == "stop" ): + self.sendLine("server_stoped") + reactor.stop() diff --git a/gameEngine/ServerFactory.py b/gameEngine/ServerFactory.py new file mode 100644 index 0000000..d713b25 --- /dev/null +++ b/gameEngine/ServerFactory.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +from twisted.internet import protocol + +from gameEngine.Protocol import Protocol + +class ServerFactory( protocol.ServerFactory ): + protocol = Protocol diff --git a/gameEngine/World.py b/gameEngine/World.py new file mode 100644 index 0000000..b0dcc89 --- /dev/null +++ b/gameEngine/World.py @@ -0,0 +1,145 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import os +from time import sleep, time +from ConfigParser import ConfigParser + +import gameEngine +from gameEngine.Character import Character + +import objects +from objects.Bed import Bed +from objects.Cooker import Cooker +from objects.Refrigerator import Refrigerator +from objects.Shower import Shower + +class World: + def __init__( self, amountOfCharacters ): + + + # Basic infrastructure + self.configParser = ConfigParser() + + # Reading the game engine cinfiguration + if( os.path.exists( '../config/gameEngine.cfg' ) == True ): + self.configParser.read( open( '../config/gameEngine.cfg' ) ) + self.gameEngineConfigExists = True + else: + self.gameEngineConfigExists = False + print '\033[31mError\033[0m No game engine configuration file found. Using default options.' + + # Game time + self.startTime = time() # The start time + self.gameYear = 1 # In game year; NOT real year + self.gameMonth = 1 # In game month; NOT real month + self.gameDay = 1 # In game day; NOT real day + self.gameHour = 0 # In game hour; NOT real hour + self.gameMinute = 0 # In game minute; NOT real minute + self.gameSecond = 0 # In game second; NOT real second + + if( self.gameEngineConfigExists == True ): + self.ticksPerSecond = self.configParser.get( 'time', 'ticksPerSecond' ) # Ticks per second + self.gameSecondsPerTick = self.configParser.get( 'time', 'gameSecondsPerTick' ) # The amount of game seconds passing each tick + else: + self.ticksPerSecond = 1 + self.gameSecondsPerTick = 1 + + # Physics data + self.physicsGravity = 9.8 # Factor of gravity + + # Terrain information + self.typeMap = [] # Type of the ground + self.heightMap = [] # Height of the ground + + # Entities in the world + self.characters = [] # List of characters in the world + self.objects = [] # List of objects in the world + + for i in range(amountOfCharacters): + self.characters.insert( 0, Character( i, self, 'random' ) ) + + self.objects.insert( 0, Bed( 0, -7, -7, 0 ) ) + self.objects.insert( 1, Cooker( 1, 1, 1, 0 ) ) + self.objects.insert( 2, Refrigerator( 2, 5, 5, 0 ) ) + self.objects.insert( 3, Shower( 3, 7, 3, 0 ) ) + + def processTime( self ): + # Process the game time. + self.gameSecond += self.gameSecondsPerTick + if( self.gameSecond >= 60 ): + self.gameMinute += 1 + self.gameSecond = 0 + + if( self.gameMinute >= 60 ): + self.gameHour += 1 + self.gameMinute = 0 + + if( self.gameHour >= 24 ): + self.gameDay += 1 + self.gameHour = 0 + + if( self.gameMonth == 1 or self.gameMonth == 3 or self.gameMonth == 5 or self.gameMonth == 7 or self.gameMonth == 8 or self.gameMonth == 10 or self.gameMonth >= 12 ): + if( self.gameDay == 32 ): + self.gameMonth += 1 + self.gameDay = 1 + elif( self.gameMonth == 2 ): + if( self.gameYear % 4 == 0 ): + if( self.gameDay == 30 ): + self.gameMonth += 1 + self.gameDay = 1 + else: + if( self.gameDay == 29 ): + self.gameMonth += 1 + self.gameDay = 1 + elif( self.gameMonth == 4 or self.gameMonth == 6 or self.gameMonth == 9 or self.gameMonth == 11 ): + if( self.gameDay == 31 ): + self.gameMonth += 1 + self.gameDay = 1 + + if( self.gameMonth >= 13 ): + self.gameYear += 1 + self.gameMonth = 1 + + def processGravity( self ): + # Processes gravity on characters and objects. + for character in self.characters: + if( character.pos[2] > 0): + character.pos[2] -= 1 + else: + character.pos[2] = 0 + for object in self.objects: + if( object.pos[2] > 0): + object.pos[2] -= 1 + else: + object.pos[2] = 0 + + def run( self ): + while( self.gameDay <= 7 ): + os.system('clear') + self.processTime() + # self.processGravity() + print '\033[32mInfo\033[0m World\tGame date: %i-%i-%i\tGame time: %i:%i:%i' % ( self.gameYear, self.gameMonth, self.gameDay, self.gameHour, self.gameMinute, self.gameSecond ) + for character in self.characters: + print '\033[32mInfo\033[0m Character %i, %s' % ( character.id, character.gender ) + print '\033[32mInfo\033[0m Pos: %i %i %i\tDestination: %i %i %i' % ( character.pos[0], character.pos[1], character.pos[2], character.destination[0], character.destination[1], character.destination[2] ) + print '\033[32mInfo\033[0m Sleep: %i\t\tFood: %i\tWater: %i' % ( character.needs['sleep'], character.needs['food'], character.needs['water'] ) + print '\033[32mInfo\033[0m Hygiene: %i\tFun: %i\tSocial: %i' % ( character.needs['hygiene'], character.needs['fun'], character.needs['social'] ) + print '\033[32mInfo\033[0m Activity: %s (%i game seconds left)' % ( character.activity, character.activityTimer ) + character.decreaseNeeds() + character.processActivity() + sleep( 1 / self.ticksPerSecond ) + diff --git a/objects/Bed.py b/objects/Bed.py new file mode 100644 index 0000000..73de612 --- /dev/null +++ b/objects/Bed.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import gameEngine +from gameEngine.Object import Object + +class Bed( Object ): + def __init__( self, id, x, y, z ): + self.id = id + self.type = 'Bed' + self.pos = [ x, y, z ] + self.isInUse = False + + def rest( self, user ): + # The user rests on the bed. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'sleep', 0.008680555 ) + + def sleep( self, user ): + # The user sleeps on the bed. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'sleep', 0.034722222 ) diff --git a/objects/Cooker.py b/objects/Cooker.py new file mode 100644 index 0000000..b151e06 --- /dev/null +++ b/objects/Cooker.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import gameEngine +from gameEngine.Object import Object + +class Cooker( Object ): + def __init__( self, id, x, y, z ): + self.id = id + self.type = 'Cooker' + self.pos = [ x, y, z ] + self.isInUse = False + + def cook( self, user ): + # The user cooks on the cooker and eats. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'food', 0.37037037 ) diff --git a/objects/Refrigerator.py b/objects/Refrigerator.py new file mode 100644 index 0000000..c61e522 --- /dev/null +++ b/objects/Refrigerator.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import gameEngine +from gameEngine.Object import Object + +class Refrigerator( object ): + def __init__( self, id, x, y, z ): + self.id = id + self.type = 'Refrigerator' + self.pos = [ x, y, z ] + self.isInUse = False + + def drink( self, user ): + # The user drinks somthing. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'water', 1.388888889 ) + + def eatSnack( self, user ): + # The user eats a snack. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'food', 0.555555556 ) diff --git a/objects/Shower.py b/objects/Shower.py new file mode 100644 index 0000000..cf7f20a --- /dev/null +++ b/objects/Shower.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import gameEngine +from gameEngine.Object import Object + +class Shower( Object ): + def __init__( self, id, x, y, z ): + self.id = id + self.type = 'Shower' + self.pos = [ x, y, z ] + self.isInUse = False + + def shower( self, user ): + # The user takes a shower. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'hygiene', 0.555555556 ) diff --git a/objects/TvSet.py b/objects/TvSet.py new file mode 100644 index 0000000..dbd26c5 --- /dev/null +++ b/objects/TvSet.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +#*** encoding:utf-8 *** + +# This file is part of La Vida +# Copyright (C) 2011 Florian R. A. Angermeier +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import gameEngine +from gameEngine.Object import Object + +class TvSet( Object ): + def __init__( self, id, x, y, z ): + self.id = id + self.type = 'TvSet' + self.pos = [ x, y, z ] + self.isInUse = False + + def watch( self, user ): + # The user watches TV. + print 'DEBUG: %s.%s is called.' % ( __name__, dir( self ) ) + user.increaseNeed( 'hygiene', 0.555555556 )