Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 96 97 [98] 99 100 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883291 times)

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1455 on: February 12, 2012, 01:59:20 pm »

Two problems...
1. WindowAdaptor is an abstract class.  You can't instantiate abstract classes.  Extend it instead.
2. KeyListener is an interface.  You can't instantiate interfaces.  Implement it instead.

Have Labyrinth extend WindowAdaptor and implements KeyListener.  Then override the WindowAdaptor methods you want and implements the KeyListener methods in some fashion.  Actually...you might want to make a separate class for the window this will exist in and just pass it the labyrinth.  Let the labyrinth worry about itself and the window worry about letting you see it.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1456 on: February 12, 2012, 06:24:30 pm »

Hard to believe this thread is almost up to a 100 pages.   :o

Here is a screenshot of something I've been working on.

Spoiler (click to show/hide)

Its a dungeon keeper style game done with libtcod and python.  I've got a lot of the infrastructure done, but I still need to work a lot on adding actual game mechanics, UI bits, content and AI.

The little green g's are goblins and the p's are prisoners that do all your grunt work like digging and building things.  :)
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1457 on: February 12, 2012, 10:34:32 pm »

Two problems...
1. WindowAdaptor is an abstract class.  You can't instantiate abstract classes.  Extend it instead.
2. KeyListener is an interface.  You can't instantiate interfaces.  Implement it instead.

Have Labyrinth extend WindowAdaptor and implements KeyListener.  NO! Absolutely no need to do this! Then override the WindowAdaptor methods you want and implements the KeyListener methods in some fashion.  Actually...you might want to make a separate class for the window this will exist in and just pass it the labyrinth.  Let the labyrinth worry about itself and the window worry about letting you see it. This is a very good idea.

Your WindowAdapter is fine, but you'll want your inner class to extend KeyAdapter instead of implement KeyListener.
« Last Edit: February 12, 2012, 10:36:08 pm by SolarShado »
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1458 on: February 12, 2012, 10:36:23 pm »

Hard to believe this thread is almost up to a 100 pages.   :o

Here is a screenshot of something I've been working on.

Spoiler (click to show/hide)

Its a dungeon keeper style game done with libtcod and python.  I've got a lot of the infrastructure done, but I still need to work a lot on adding actual game mechanics, UI bits, content and AI.

The little green g's are goblins and the p's are prisoners that do all your grunt work like digging and building things.  :)

Looks like Dwarf Fortress kinda......
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1459 on: February 12, 2012, 11:37:28 pm »

Looks like Dwarf Fortress kinda......

Yeah, I used the same-ish digging colours.   :P
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Vector

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1460 on: February 14, 2012, 06:40:50 pm »

Hey... new stupid question.

I want to take a dictionary and return the key that maps to the minimal value.  Any of y'all know how to do that with built-in functions?
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1461 on: February 14, 2012, 06:45:23 pm »

This in python?
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Vector

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1462 on: February 14, 2012, 06:47:00 pm »

This in python?

Indeed.

I'm just wondering if there's some way to get the set of all keys mapping to a particular value, or something like that.
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1463 on: February 14, 2012, 06:49:58 pm »

Hmm, apparently not. Or at least not built into python. Finding the key from a value is a rather strange way of doing things, like carrying around a lot of padlocks for random keys you have scattered about. I'm left to wonder why you need to...


Anyway, the first solution I found was a nice little function somebody made that should do what you need.
Code: [Select]
def find_key(dic, val):
    return [k for k, v in dic.iteritems() if v == val][0]

EDIT: Ok, fixed something. That will teach me to copy pasta the work of people who can't even make a working function.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1464 on: February 14, 2012, 06:55:47 pm »

I don't think there is an easy one liner, but I think this should do it:

Code: [Select]
dict = {'a': 1, 'b': 2, 'c': 1, 'd': 5}

keys = []
for key, value in dict.iteritems():
   if value == 1:   #change one to whatever you want it to be.
      keys.append(key)

Or if you wanted the minimum value, this:

Code: [Select]
dict = {'a': 1, 'b': 2, 'c': 1, 'd': 5}

keys = []
for key, value in dict.iteritems():
   if value == min(dict.items()[1]):
      keys.append(key)


In ruby, its much easier.  :D

Code: [Select]
list = dict.to_a.find_all{|a| a[1] == min(dict.values)}
« Last Edit: February 14, 2012, 07:02:42 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Vector

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1465 on: February 14, 2012, 06:59:37 pm »

Yeah, that was basically plan B.  I guess I'll get to that, then...
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1466 on: February 14, 2012, 07:01:17 pm »

But no seriously, why are you looking for keys when you have a hand full of open locks?

Vector

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1467 on: February 14, 2012, 07:02:16 pm »

Because I need the key pertaining to the minimal value, not the minimal value itself.
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1468 on: February 14, 2012, 08:33:06 pm »

So, I opened up my IDE today in CompSci to try to figure out what was going so horribly wrong with inheritence in Gridworld. I glanced at the file and hit compile, just for kicks. And then... Nothing popped up.

Yes, that's right. Nothing. No errors. A clean compile. Literally overnight, the problem went away. It's still happening on my personal laptop, but not my school computer. Nothing was changed on the school computers that I know of. There is no reason for it to have suddenly started working. I'll post the code later when I'm less distracted by other things.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1469 on: February 14, 2012, 08:35:26 pm »

Like I said, sounds more like a glitch than lack of feature. You have to remember that the JVM is doing backflips to keep track of what exists when you don't have to forward declare everything, I guess something went wrong somewhere.
Pages: 1 ... 96 97 [98] 99 100 ... 796