-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added input handler (command line at the moment)
- Added ability to quit the game (was not possible until now xP) - Added first ASCII UI and widgets: - Need bar - Activity bar - World view
- Loading branch information
Florian R. A. Angermeier
committed
Jun 30, 2011
1 parent
012e005
commit 896e46d
Showing
11 changed files
with
371 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/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 AsciiWidget import AsciiWidget | ||
|
||
class ActivityBar( AsciiWidget ): | ||
def __init__( self, pos, character ): | ||
self.cmdPrefix = '\033[' | ||
self.cmdSeperator = ';' | ||
self.cmdPostfixPosition = 'H' | ||
self.cmdPostfixColor = 'm' | ||
self.cmdTab = '\t' | ||
self.pos = pos | ||
self.character = character | ||
|
||
def printWidget( self ): | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0], self.cmdSeperator, self.pos[1], self.cmdPostfixPosition ) | ||
output = '%sActivity: %s (%s)' % ( cmdPosition, self.character.brain.activity, self.character.brain.activityTimer ) | ||
print '%s' % ( output ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/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 | ||
from twisted.internet import reactor | ||
|
||
from GameClock import GameClock | ||
from NeedBar import NeedBar | ||
from ActivityBar import ActivityBar | ||
from MapView import MapView | ||
|
||
class AsciiUI: | ||
# The ASCII user interface base class which provides the drawing loop. | ||
|
||
def __init__( self, server, world ): | ||
self.server = server | ||
self.gameClock = GameClock( ( 1, 1 ) , world) | ||
self.needBarSleep = NeedBar( ( 2, 1 ), 'Sleep ', world.characters[ 0 ], 'sleep' ) | ||
self.needBarFood = NeedBar( ( 3, 1 ), 'Food ', world.characters[ 0 ], 'food' ) | ||
self.needBarWater = NeedBar( ( 4, 1 ), 'Water ', world.characters[ 0 ], 'water' ) | ||
self.needBarUrination = NeedBar( ( 2, 30 ), 'Urination ', world.characters[ 0 ], 'urination' ) | ||
self.needBarHygiene = NeedBar( ( 3, 30 ), 'Hygiene ', world.characters[ 0 ], 'hygiene' ) | ||
self.needBarFun = NeedBar( ( 4, 30 ), 'Fun ', world.characters[ 0 ], 'fun' ) | ||
self.needBarSocial = NeedBar( ( 2, 60 ), 'Social ', world.characters[ 0 ], 'social' ) | ||
self.activityBar = ActivityBar( ( 5, 1 ), world.characters[ 0 ] ) | ||
self.mapView = MapView( (6, 0), world ) | ||
|
||
def run( self, treadPool ): | ||
os.system( 'clear' ) | ||
while( self.server.stop != True ): | ||
self.gameClock.printWidget() | ||
self.needBarSleep.printWidget() | ||
self.needBarFood.printWidget() | ||
self.needBarWater.printWidget() | ||
self.needBarUrination.printWidget() | ||
self.needBarHygiene.printWidget() | ||
self.needBarFun.printWidget() | ||
self.needBarSocial.printWidget() | ||
self.activityBar.printWidget() | ||
self.mapView.printWidget() | ||
sleep( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/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 AsciiWidget: | ||
# The abstract base class for all ascii widgets. | ||
|
||
def __init__( self, pos ): | ||
self.cmdPrefix = '\033[' | ||
self.cmdSeperator = ';' | ||
self.cmdPostfixPosition = 'H' | ||
self.cmdPostfixColor = 'm' | ||
self.cmdTab = '\t' | ||
self.pos = pos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 AsciiWidget import AsciiWidget | ||
|
||
class GameClock( AsciiWidget ): | ||
def __init__( self, pos, world ): | ||
self.cmdPrefix = '\033[' | ||
self.cmdSeperator = ';' | ||
self.cmdPostfixPosition = 'H' | ||
self.cmdPostfixColor = 'm' | ||
self.cmdTab = '\t' | ||
self.pos = pos | ||
self.world = world | ||
|
||
def printWidget( self ): | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0], self.cmdSeperator, self.pos[1], self.cmdPostfixPosition ) | ||
cmdColor = '%s1%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
output = '%s%sGame date: %i/%i/%i%sGame time: %i:%i:%i' % ( cmdPosition, cmdColor, self.world.gameMonth, self.world.gameDay, self.world.gameYear, | ||
self.cmdTab, self.world.gameHour, self.world.gameMinute, self.world.gameSecond ) | ||
cmdColor = '%s0%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
output += cmdColor | ||
print '%s' % ( output ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/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 AsciiWidget import AsciiWidget | ||
|
||
class MapView( AsciiWidget ): | ||
def __init__( self, pos, world ): | ||
self.cmdPrefix = '\033[' | ||
self.cmdSeperator = ';' | ||
self.cmdPostfixPosition = 'H' | ||
self.cmdPostfixColor = 'm' | ||
self.cmdTab = '\t' | ||
self.pos = pos | ||
self.world = world | ||
self.asciiTiles = { 0: '%s33%s42%s"%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
1: '%s30%s40%s:%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
2: '%s31%s43%s#%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
3: '%s30%s44%s~%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
4: '%s30%s44%s+%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ) } | ||
self.asciiObject = { 'Bed': '%s1%s37%s43%sH%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
'Cooker': '%s1%s30%s47%s8%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
'Refrigerator': '%s1%s30%s47%s*%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
'Toilet': '%s1%s30%s47%sO%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
'Shower': '%s1%s30%s47%s^%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ), | ||
'TvSet': '%s1%s30%s43%sY%s0%s' % ( self.cmdPrefix, self.cmdSeperator, self.cmdSeperator, self.cmdPostfixColor, self.cmdPrefix, self.cmdPostfixColor ) } | ||
|
||
def printWidget( self ): | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0], self.cmdSeperator, self.pos[1], self.cmdPostfixPosition ) | ||
print '%sMap view' % ( cmdPosition ) | ||
rowId = 0 | ||
colId = 0 | ||
for row in self.world.typeMap: | ||
rowId += 1 | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0] + rowId, self.cmdSeperator, self.pos[1], self.cmdPostfixPosition ) | ||
output = '%s' % ( cmdPosition ) | ||
for col in row: | ||
output += self.asciiTiles[ col ] | ||
print '%s' % ( output ) | ||
|
||
for object in self.world.objects: | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0] + object.pos[0], self.cmdSeperator, self.pos[1] + object.pos[1], self.cmdPostfixPosition ) | ||
output = '%s%s' % ( cmdPosition, self.asciiObject[ object.type ] ) | ||
print output | ||
|
||
for character in self.world.characters: | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0] + character.pos[0], self.cmdSeperator, self.pos[1] + character.pos[1], self.cmdPostfixPosition ) | ||
output = '%sC' % ( cmdPosition ) | ||
print output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/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 AsciiWidget import AsciiWidget | ||
|
||
class NeedBar( AsciiWidget ): | ||
def __init__( self, pos, label, character, need ): | ||
self.cmdPrefix = '\033[' | ||
self.cmdSeperator = ';' | ||
self.cmdPostfixPosition = 'H' | ||
self.cmdPostfixColor = 'm' | ||
self.cmdTab = '\t' | ||
self.pos = pos | ||
self.label = label | ||
self.character = character | ||
self.need = need | ||
|
||
def printWidget( self ): | ||
cmdPosition = '%s%i%s%i%s' % ( self.cmdPrefix, self.pos[0], self.cmdSeperator, self.pos[1], self.cmdPostfixPosition ) | ||
|
||
cmdColor = '%s40%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
output = '%s%s%s ' % ( cmdPosition, self.label, cmdColor ) | ||
cmdColor = '%s0%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
output += cmdColor | ||
print '%s' % ( output ) | ||
|
||
if( self.character.needs[ self.need ] >= 750 ): | ||
cmdColor = '%s42%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
elif( self.character.needs[ self.need ] >= 500 ): | ||
cmdColor = '%s43%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
else: | ||
cmdColor = '%s41%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
output = '%s%s%s' % ( cmdPosition, self.label, cmdColor ) | ||
for i in range( int( self.character.needs[ self.need ] / 100 ) ): | ||
output += ' ' | ||
cmdColor = '%s0%s' % ( self.cmdPrefix, self.cmdPostfixColor ) | ||
output += '%s' % ( cmdColor ) | ||
print '%s' % ( output ) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.