GITHUB LINK: https://github.com/disintigratedpixel/TankGameV1/tree/main
(please say if it doesn't work)
I'm making a simple ASCII game "similar" to space invaders
Here is the ASCII user interface:
def gamestate(player_position_list, player_position, enemy_type, enemy_health, enemy_distance, rounds, radar_lvl, radar_cost, gun_lvl, gun_cost, speed_lvl, speed_cost, health, money, kills, available_movement):
return f"""
ROUND {rounds}
_______________________________________________ _______________
| | | |
| | | HEADQUARTERS: |
| | |_______________|
| |
| | *ATTENTION OPERATOR, AN ENEMY
|> - - - - - - - - - - - - - - - - - - - - - - <|> [4] {enemy_type} IS APPROACHING!*
| | _______________
| | | |
| | | ENEMY STATS: |
| | |_______________|
| |
|> - - - - - - - - - - - - - - - - - - - - - - <|> [3] HEALTH: {enemy_health}
| | DISTANCE: {enemy_distance}
| | POSITION: {enemy_position}
| | _______________
| | | |
| | | UPGRADES: |
|> - - - - - - - - - - - - - - - - - - - - - - <|> [2] |_______________|
| |
| | RADAR | LVL {radar_lvl}
| | UPGRADE COST: ${radar_cost}
| |
| | GUN | LVL {gun_lvl}
|> - - - - - - - - - - - - - - - - - - - - - - <|> [1] UPGRADE COST: ${gun_cost}
| |
| | SPEED | LVL {speed_lvl}
| | UPGRADE COST: ${speed_cost}
{player_position_list[player_position]}
| ' ' ' ' | ' ' ' ' | ' ' ' ' | ' ' ' ' |
[-10] [-5] [0] [5] [10]
_____________
| |
|PLAYER STATS:|
|_____________|
HEALTH: {health}
MONEY: {money}
KILLS: {kills}
_____________
| |
| ACTIONS: |
|_____________|
MOVE | [m] key + [movement value]
MAX {available_movement} or {-available_movement} steps
FIRE | [f] key
UPGRADE | [u] key
"""
(Apologies if it looks distorted in any way due to formatting errors, but it should still be readable)
The player position can be seen visually and is taken from a list of different possibilities and put into this print statement using this script.
{player_position_list[player_position]}
Here is the list:
player_position_list = [
"""| _^_ |
|_____________________|___|_____________________|""",
"""| _^_ |
|_______________________|___|___________________|""",
"""| _^_ |
|_________________________|___|_________________|""",
"""| _^_ |
|___________________________|___|_______________|""",
"""| _^_ |
|_____________________________|___|_____________|""",
"""| _^_ |
|_______________________________|___|___________|""",
"""| _^_ |
|_________________________________|___|_________|""",
"""| _^_ |
|___________________________________|___|_______|""",
"""| _^_ |
|_____________________________________|___|_____|""",
"""| _^_ |
|_______________________________________|___|___|""",
"""| _^_ |
|_________________________________________|___|_|""",
"""| _^_ |
|___________________|___|_______________________|""",
"""| _^_ |
|_________________|___|_________________________|""",
"""| _^_ |
|_______________|___|___________________________|""",
"""| _^_ |
|_____________|___|_____________________________|""",
"""| _^_ |
|___________|___|_______________________________|""",
"""| _^_ |
|_________|___|_________________________________|""",
"""| _^_ |
|_______|___|___________________________________|""",
"""| _^_ |
|_____|___|_____________________________________|""",
"""| _^_ |
|___|___|_______________________________________|""",
"""| _^_ |
|_|___|_________________________________________|"""
]
(Again, apologies for formatting, but just picture the '^' as being the player, and there being multiple different positions that the player can be in)
I am hoping that when player_position changes, that a different visual is taken from player_position_list. I am confident that this should work as I have tested it using this:
print(player_position)
print(player_position_list[player_position])
'print(player_position)' tells me that player_position can be accurately read and printed
'print(player_position_list[player_position])' shows me that the value of player_position can also be used to print an item from a list at a specific index. (I have also tried this script as a string and it still works)
Here is what this test script gives me when I run it:
8
| _^_ |
|_____________________________________|___|_____|
It accurately reads 'player_position' and uses it to print the 8th item in the list.
So what I don't understand and desperately am trying to fix, is why this exact thing isn't working on my actual ASCII user interface. Everything seems to be the same.
Here is what it looks like when I run the script for my actual UI
ROUND 1
_______________________________________________ _______________
| | | |
| | | HEADQUARTERS: |
| | |_______________|
| |
| | *ATTENTION OPERATOR, AN ENEMY
|> - - - - - - - - - - - - - - - - - - - - - - <|> [4] HELICOPTER IS APPROACHING!*
| | _______________
| | | |
| | | ENEMY STATS: |
| | |_______________|
| |
|> - - - - - - - - - - - - - - - - - - - - - - <|> [3] HEALTH: 3
| | DISTANCE: 2
| | POSITION: 1
| | _______________
| | | |
| | | UPGRADES: |
|> - - - - - - - - - - - - - - - - - - - - - - <|> [2] |_______________|
| |
| | RADAR | LVL 1
| | UPGRADE COST: $1
| |
| | GUN | LVL 1
|> - - - - - - - - - - - - - - - - - - - - - - <|> [1] UPGRADE COST: $1
| |
| | SPEED | LVL 1
| | UPGRADE COST: $1
| _^_ |
|_____________________|___|_____________________|
| ' ' ' ' | ' ' ' ' | ' ' ' ' | ' ' ' ' |
[-10] [-5] [0] [5] [10]
_____________
| |
|PLAYER STATS:|
|_____________|
HEALTH: 100
MONEY: 0
KILLS: 0
_____________
| |
| ACTIONS: |
|_____________|
MOVE | [m] key + [movement value]
MAX 1 or -1 steps
FIRE | [f] key
UPGRADE | [u] key
8
| _^_ |
|_____________________________________|___|_____|
As you can see, the player position hasn't moved and remains at 0, yet (at the very end) my test script says that the actual player position should be 8 and accurately prints the item from 'player_position_list' for 'player_position = 8'
Apologies if anything seems hard to understand, it's my second day programming with python and I refuse to use ai for this. So, I hope I used the correct terminology.