lkjfds
This commit is contained in:
24
GameState.py
24
GameState.py
@@ -1,16 +1,17 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from lamps.LampGroup import PLAYER_LAMPS
|
|
||||||
from lamps.Lamp import CREDIT
|
from lamps.Lamp import CREDIT
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
from time import sleep
|
from lamps.LampGroup import *
|
||||||
|
import asyncio
|
||||||
|
|
||||||
class GameState:
|
class GameState:
|
||||||
players = None
|
players = None
|
||||||
credits = config.BALLS_PER_GAME
|
credits = config.BALLS_PER_GAME
|
||||||
isPlaying = False
|
isPlaying = False
|
||||||
isStarted = False
|
isStarted = False
|
||||||
|
isIdle = True
|
||||||
|
|
||||||
def __init__(self, playerStateFactory, highscore, specialDisplay, currentPlayerID = 0):
|
def __init__(self, playerStateFactory, highscore, specialDisplay, currentPlayerID = 0):
|
||||||
CREDIT.activate()
|
CREDIT.activate()
|
||||||
@@ -22,6 +23,7 @@ class GameState:
|
|||||||
self.highscore = highscore
|
self.highscore = highscore
|
||||||
self.specialDisplay = specialDisplay
|
self.specialDisplay = specialDisplay
|
||||||
self.specialDisplay.printCredits(self.credits)
|
self.specialDisplay.printCredits(self.credits)
|
||||||
|
self.startIdleLoop()
|
||||||
|
|
||||||
def nextPlayer(self):
|
def nextPlayer(self):
|
||||||
self.currentPlayer = next(self.players)
|
self.currentPlayer = next(self.players)
|
||||||
@@ -42,14 +44,24 @@ class GameState:
|
|||||||
logging.info("Game ended")
|
logging.info("Game ended")
|
||||||
|
|
||||||
def startIdleLoop(self):
|
def startIdleLoop(self):
|
||||||
|
asyncio.run(self.idleLoop())
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stopIdleLoop(self):
|
def stopIdleLoop(self):
|
||||||
|
self.isIdle = False
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def idleLoop(self):
|
async def idleLoop(self):
|
||||||
|
all_cabinet_lamps = [BONUS_LAMPS, BONUS_MULTIPLIER_LAMPS, CHAMP_LAMPS,
|
||||||
pass
|
UPPER_PLAYFIELD_TIME_LAMPS, TUNNEL_NUMBER_LAMPS,
|
||||||
|
TUNNEL_LAMPS, TUNNEL_SCORE_LAMPS]
|
||||||
|
while True:
|
||||||
|
for lamps in all_cabinet_lamps:
|
||||||
|
for _ in lamps.lamps:
|
||||||
|
lamps.cycle()
|
||||||
|
if not self.isIdle:
|
||||||
|
return
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
def createPlayers(self, playerCount):
|
def createPlayers(self, playerCount):
|
||||||
players = []
|
players = []
|
||||||
@@ -77,6 +89,4 @@ class GameState:
|
|||||||
for player in self.players:
|
for player in self.players:
|
||||||
if player.hasHighscore:
|
if player.hasHighscore:
|
||||||
with open(config.HIGHSCORE_FILE, "w+") as file:
|
with open(config.HIGHSCORE_FILE, "w+") as file:
|
||||||
file.seek(0)
|
|
||||||
file.truncate()
|
|
||||||
file.write(player.score)
|
file.write(player.score)
|
||||||
@@ -85,6 +85,7 @@ class PlayerState:
|
|||||||
self.printSpecial()
|
self.printSpecial()
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
|
self.isActive = False
|
||||||
self.resetBall()
|
self.resetBall()
|
||||||
PLAYER_LAMPS.deactivate()
|
PLAYER_LAMPS.deactivate()
|
||||||
PLAYER_LAMPS.activate_one(self.id)
|
PLAYER_LAMPS.activate_one(self.id)
|
||||||
@@ -280,6 +281,7 @@ class PlayerState:
|
|||||||
def advanceBonusMultiplier(self):
|
def advanceBonusMultiplier(self):
|
||||||
if not self.isActive:
|
if not self.isActive:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.bonusMultiplier = next(self.bonusMultiplierIter)
|
self.bonusMultiplier = next(self.bonusMultiplierIter)
|
||||||
BONUS_MULTIPLIER_LAMPS.activateNext()
|
BONUS_MULTIPLIER_LAMPS.activateNext()
|
||||||
@@ -292,6 +294,7 @@ class PlayerState:
|
|||||||
|
|
||||||
if self.ballsLeft == 0 and self.bonusTime != 0:
|
if self.ballsLeft == 0 and self.bonusTime != 0:
|
||||||
self.replayBall = True
|
self.replayBall = True
|
||||||
|
SHOOT_AGAIN.activate()
|
||||||
if self.replayBallTimer != None:
|
if self.replayBallTimer != None:
|
||||||
self.replayBallTimer.cancel()
|
self.replayBallTimer.cancel()
|
||||||
self.replayBallTimer = Timer(interval=1, function=self.updateReplayBall)
|
self.replayBallTimer = Timer(interval=1, function=self.updateReplayBall)
|
||||||
@@ -314,6 +317,7 @@ class PlayerState:
|
|||||||
|
|
||||||
self.replayBall = False
|
self.replayBall = False
|
||||||
self.replayBallTimer = None
|
self.replayBallTimer = None
|
||||||
|
SHOOT_AGAIN.deactivate()
|
||||||
MainFlipper().deactivate()
|
MainFlipper().deactivate()
|
||||||
|
|
||||||
def addPoints(self, points):
|
def addPoints(self, points):
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import logging
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parseCommandLine()
|
args = parseCommandLine()
|
||||||
logging.basicConfig(filename='log.txt', level=config.LOG_LEVEL)
|
logging.basicConfig(filename=config.LOG_FILE, level=config.LOG_LEVEL)
|
||||||
game = createGame(args)
|
game = createGame(args)
|
||||||
asyncio.run(game.run())
|
asyncio.run(game.run())
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ RED_SPECIAL_TIMES = 1
|
|||||||
ORANGE_SPECIAL = SpecialEvent.points
|
ORANGE_SPECIAL = SpecialEvent.points
|
||||||
ORANGE_SPECIAL_BANK = ORANGE_SPECIAL_BANK_OPTIONS["BOTH"]
|
ORANGE_SPECIAL_BANK = ORANGE_SPECIAL_BANK_OPTIONS["BOTH"]
|
||||||
## Tech config
|
## Tech config
|
||||||
|
LOG_FILE="flippr-game.log"
|
||||||
LOG_LEVEL=logging.DEBUG
|
LOG_LEVEL=logging.DEBUG
|
||||||
WAIT_TIME_TO_RESET_SECONDS = 1
|
WAIT_TIME_TO_RESET_SECONDS = 1
|
||||||
MAX_NETWORK_RETRIES = 10
|
MAX_NETWORK_RETRIES = 10
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from lamps.Lamp import Lamp
|
from lamps.Lamp import Lamp
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
import time
|
||||||
|
|
||||||
class LampGroup:
|
class LampGroup:
|
||||||
def __init__(self, lamps):
|
def __init__(self, lamps):
|
||||||
@@ -44,6 +45,9 @@ class LampGroup:
|
|||||||
self.currentLamp = next(self.lamp_cycle)
|
self.currentLamp = next(self.lamp_cycle)
|
||||||
self.currentLamp.activate()
|
self.currentLamp.activate()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PLAYER_LAMPS = LampGroup([
|
PLAYER_LAMPS = LampGroup([
|
||||||
Lamp("Can Play 1"),
|
Lamp("Can Play 1"),
|
||||||
Lamp("Can Play 2"),
|
Lamp("Can Play 2"),
|
||||||
|
|||||||
Reference in New Issue
Block a user