Hex Game

Game Intro

We will code a game which challenges students to convert from decimal (denary, base 10) to hexadecimal, base 16.

Python has a cool little built-in function that we can use. You have already seen a few built-in functions.

  1. print()
  2. random()
  3. int()
  4. input()

There is another one called hex()

Open your IDE and type in the following code:

num = 10

hNum = hex(num) #or just hNum = hex(10)

print(hNum)

Can you see how it works?

Do you remember using:

random.randint(1,10)

This function gives us an INTEGER between 1 and 10 inclusive.

hex(num)

gives us a hexadecimal number in the form of a STRING.

Annoyingly, it gives us 2 unwanted characters at the start of the STRING.

Do you know how to get rid of those characters?

Here is a help video if you want a tip.

Task 1 - the game scenario

The user enters their name.

The game player will face 10 challenges.

Each challenge will present the user with a decimal number between 0-101

The player has to enter the correct hexadecimal value.

If the player is correct, (s)he gets a point.

At the end of the game:

  • If the player gets 10 points, "WOW, name!!" is displayed.
  • If the player gets 8 points or more, "Amazing, name!" is displayed.
  • If the player gets 6 points or more, "Great, name!" is displayed.
  • If the player gets 4 points or more, "Nice job, name!" is displayed.
  • If the player gets less than 4 points, "Wanna try again, name?" is displayed.

where name is the name of the player.

Can you solve this problem using as many concepts covered in the course so far, including:

  • variables (global/local)
  • function definitions
  • function calls
  • selection (if...elif...else)
  • iteration
  • parameters

This is a non-AI challenge!

It might take a day, a week, a month or a year to solve it! Enjoy the experience!

Task 2 - adaptive maintenance

Can you add your own ideas to the game.

For example, if the player gets an answer wrong, (s)he loses a point!

If the player end with negative points, a consequence or additional challenge is presented...

Development

To help you plan your idea, design a main() function starting with comments eg:

def main():

#input name eg name = inputName() ... make name global

#set score to 0

#loop 10 times

#generate first challenge eg generateChallenge()

#prompt user to enter solution eg enterSolution()

Then you can start coding your solution using Python.