A downloadable game

Enter "WASD" to move around the board. 

My entry for the #TweetTweetJam using python. The game was done in 551 characters.

Here's the code:

from random import randint as v
def P(m,s):
  print("Score: ",s)
  for r in m:
    for c in r:
      print(c,end=" ")
def R(map,G):
X,E,G='X','-','O';x,y,pX,pY=0,0,0,0;s=0;b=[[E]*4 for _ in range(4)];b[y][x]=X;R(b,G);P(b,s);
  while c.lower() not in {'w','a','s','d'}:c=input("WASD? ")
  if(y+1>0 and y<4 and x+1>0 and x<4):
    if c=='w':y-=1
    if c=='s':y+=1
    if c=='a':x-=1
    if c=='d':x+=1
    if b[y][x]==G:s+=1;R(b,G)

The non-shortened code with proper variable and function names:

from random import randint as random
def printBoard(m,s):
  print("Score: ", s)
  for row in m:
    for col in row:
      print(col,end=" ")
def reset(m, goal):
  board[random(0,3)][random(0,3)] = GOAL
PLAYER, EMPTY, GOAL = 'X', '-', 'O'
x, y, pX, pY = 0, 0, 0, 0
score = 0
board = [[EMPTY]*4 for _ in range(4)]
board[y][x] = PLAYER
reset(board, GOAL)
printBoard(board, score)
  choice = ''
  while choice.lower() not in {'w', 'a', 's', 'd'}:
    choice = input("WASD? ")
  if(y + 1 > 0 and y < 4 and x + 1 > 0 and x < 4):
    if choice == 'w': y -= 1
    if choice == 's': y += 1
    if choice == 'a': x -= 1
    if choice == 'd': x += 1
    if board[y][x] == GOAL:
      score += 1
      reset(board, GOAL)
    board[y][x] = PLAYER
    board[pY][pX] = EMPTY
    pY, pX = y, x
  printBoard(board, score)


tweettweetjam.py 567 bytes

Install instructions

  1. Have Python3.8 installed and (if on Windows) System Environment Variables set up.
  2. Navigate to the file location in Command Prompt/ Terminal.
  3. Run the game with: python3 tweettweetjam.py

Sometimes, the game places the O on the character, so just restart when that happens.

Leave a comment

Log in with itch.io to leave a comment.