High/Low

By IllogicTC on Mar 25, 2011

A silly little game, where you are shown a number and have to guess if "their" number is higher or lower than the one you are seeing.

To start, type /highlow. This will open the Setup dialog, where you can enter your number of rounds and the highest number. you can play up to 999 rounds with a high number of up to 9999.

Once you click start game, it will show you a number. For example, with a high number of 10, you are being shown 7. It is a fairly good chance that "their" number is lower, so select lower. If you think their number COULD be in the 8-10 range, select higher.

When you have played all your rounds, you will be shown a results screen that shows your setup, your correct/incorrect ratio, and a score determined on the amount of correct guesses, your number of rounds, and your selected high number.

And yes, I know there is probably some uber-way to make this thing tiny, or some regex for this or that. Oh well =(

dialog hl_setup {
  title "High-Low Setup"
  size -1 -1 77 52
  option dbu
  button "Start Game!", 1, 20 36 37 12, ok
  edit "Highest Number", 2, 3 5 70 12, limit 4 center
  edit "Game Length", 3, 3 21 70 12, limit 3 center
}

dialog hl_game {
  title "High-Low"
  size -1 -1 82 45
  option dbu
  text "", 1, 4 3 74 8, center
  edit "", 2, 26 15 30 10, read center
  button "Lower", 3, 2 29 25 12
  button "Higher", 4, 54 29 25 12
}

dialog hl_results {
  title "High-Low Results"
  size -1 -1 106 55
  option dbu
  text "", 1, 3 3 100 8, center
  text "", 2, 3 15 100 8, center
  text "", 3, 3 27 100 8, center
  button "Play Again!", 4, 3 39 37 12
  button "I'm Done", 5, 66 39 37 12
}

alias highlow {
  dialog -m hl_setup hl_setup
}

on *:dialog:hl_setup:sclick:1: {
  if ($did($dname,2) !isnum) || ($did($dname,3) !isnum) || ($did($dname,2) < 1) || ($did($dname,3) < 1) || ($chr(46) isin $did($dname,2)) || ($chr(46) isin $did($dname,3)) HALT
  set %hlow_high $did($dname,2)
  set %hlow_max $did($dname,3)
  set %hlow_cur 0
  dialog -m hl_game hl_game
}

on *:dialog:hl_game:*:*: {
  if ($devent == sclick) {
    if ($did == 3) || ($did == 4) {
      if ($did == 3) {
        if (%hlow_yournum > %hlow_theirnum) inc %hlow_correct
        else inc %hlow_incorrect
      }
      if ($did == 4) {
        if (%hlow_yournum < %hlow_theirnum) inc %hlow_correct
        else inc %hlow_incorrect
      }
      hl_update
      if (%hlow_cur > %hlow_max) {
        dialog -x hl_game
        dialog -m hl_results hl_results
      }
    }
  }
  elseif ($devent == init) hl_update
  elseif ($devent == close) unset %hlow_*
}

on *:dialog:hl_results:*:*: {
  if ($devent == init) {
    did -a $dname 1 Setup: %hlow_max rounds, %hlow_high high number.
    did -a $dname 2 Results: $iif(%hlow_correct,%hlow_correct,0) Correct / $iif(%hlow_incorrect,%hlow_incorrect,0) Incorrect. $chr(40) $+ $round($calc((%hlow_correct / %hlow_max) * 100),2) $+ $chr(37) $+ $chr(41)
    var %x $int($calc(((%hlow_correct * (%hlow_high ^ 1.2)) / (1 / %hlow_max)) / 3))
    if (%x > %hl_highscore) set %hl_highscore %x
    did -a $dname 3 Score: %x High Score: $iif(%hl_highscore > %x,%hl_highscore,%x)
  }
  if ($devent == sclick) {
    unset %hlow_*
    if ($did == 4) {
      dialog -x hl_results
      dialog -m hl_setup hl_setup
    }
    if ($did == 5) dialog -x hl_results
  }
}

alias hl_update {
  :picknumber
  var %x $rand(1,%hlow_high)
  var %y $rand(1,%hlow_high)
  if (%x == %y) goto picknumber
  set %hlow_yournum %x
  set %hlow_theirnum %y
  inc %hlow_cur
  did -ra hl_game 1 Round: %hlow_cur of %hlow_max
  did -ra hl_game 2 %hlow_yournum
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.